-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#75] refactor: auth domain layer kotlin으로 migration
- Loading branch information
1 parent
2844d78
commit ae490bb
Showing
11 changed files
with
82 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/main/java/com/mallang/auth/domain/MemberRepository.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/main/java/com/mallang/auth/domain/oauth/AuthCodeRequestUrlProvider.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/java/com/mallang/auth/domain/oauth/AuthCodeRequestUrlProviderComposite.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
src/main/java/com/mallang/auth/domain/oauth/OauthMemberClient.java
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
src/main/java/com/mallang/auth/domain/oauth/OauthMemberClientComposite.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/mallang/auth/domain/MemberRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mallang.auth.domain | ||
|
||
import com.mallang.auth.exception.NotFoundMemberException | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.repository.findByIdOrNull | ||
import java.util.* | ||
|
||
interface MemberRepository : JpaRepository<Member, Long> { | ||
|
||
override fun getById(id: Long) = findByIdOrNull(id) | ||
?: throw NotFoundMemberException() | ||
|
||
fun findByOauthId(oauthId: OauthId): Optional<Member> | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/mallang/auth/domain/oauth/AuthCodeRequestUrlProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mallang.auth.domain.oauth | ||
|
||
import com.mallang.auth.domain.OauthServerType | ||
|
||
interface AuthCodeRequestUrlProvider { | ||
fun supportServer(): OauthServerType | ||
fun provide(): String | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/mallang/auth/domain/oauth/AuthCodeRequestUrlProviderComposite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.mallang.auth.domain.oauth | ||
|
||
import com.mallang.auth.domain.OauthServerType | ||
import com.mallang.auth.exception.UnsupportedOauthTypeException | ||
import org.springframework.stereotype.Component | ||
import java.util.function.Function | ||
import java.util.stream.Collectors | ||
|
||
@Component | ||
class AuthCodeRequestUrlProviderComposite(providers: Set<AuthCodeRequestUrlProvider>) { | ||
|
||
private val mapping: Map<OauthServerType, AuthCodeRequestUrlProvider> = providers.stream() | ||
.collect(Collectors.toMap({ it.supportServer() }, Function.identity())) | ||
|
||
fun provide(oauthServerType: OauthServerType): String { | ||
return getProvider(oauthServerType).provide() | ||
} | ||
|
||
private fun getProvider(oauthServerType: OauthServerType): AuthCodeRequestUrlProvider { | ||
return mapping[oauthServerType] ?: throw UnsupportedOauthTypeException() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/mallang/auth/domain/oauth/OauthMemberClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mallang.auth.domain.oauth | ||
|
||
import com.mallang.auth.domain.Member | ||
import com.mallang.auth.domain.OauthServerType | ||
|
||
interface OauthMemberClient { | ||
fun supportServer(): OauthServerType | ||
fun fetch(code: String?): Member | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/mallang/auth/domain/oauth/OauthMemberClientComposite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mallang.auth.domain.oauth | ||
|
||
import com.mallang.auth.domain.Member | ||
import com.mallang.auth.domain.OauthServerType | ||
import com.mallang.auth.exception.UnsupportedOauthTypeException | ||
import org.springframework.context.annotation.Profile | ||
import org.springframework.stereotype.Component | ||
import java.util.function.Function | ||
import java.util.stream.Collectors | ||
|
||
@Profile("!test") | ||
@Component | ||
class OauthMemberClientComposite(clients: Set<OauthMemberClient>) { | ||
|
||
private val mapping: Map<OauthServerType, OauthMemberClient> = clients.stream() | ||
.collect(Collectors.toMap({ it.supportServer() }, Function.identity())) | ||
|
||
fun fetch(oauthServerType: OauthServerType, authCode: String): Member { | ||
return getClient(oauthServerType).fetch(authCode) | ||
} | ||
|
||
private fun getClient(oauthServerType: OauthServerType): OauthMemberClient { | ||
return mapping[oauthServerType] ?: throw UnsupportedOauthTypeException() | ||
} | ||
} |