Skip to content

Commit

Permalink
[#75] refactor: auth domain layer kotlin으로 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shin-mallang committed Nov 17, 2023
1 parent 2844d78 commit ae490bb
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 104 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def excludeCoverage = [
'**/command/**',
'**/request/**',
'**/data/**',
'**/dao/support/*Support*',
'**/domain/*Repository*',
'**/dao/support/*Support**',
'**/domain/*Repository**',
'**/auth/infrastructure/oauth/*/**',
'**/auth/presentation/OauthController*',
] + Qdomains
Expand Down Expand Up @@ -153,8 +153,8 @@ jacocoTestCoverageVerification {
'*.command.*',
'*.request.*',
'*.data.*',
'*.dao.support.*Support',
'*.domain.*Repository',
'*.dao.support.*Support*',
'*.domain.*Repository*',
'*.auth.infrastructure.oauth.*.*',
'*.OauthController',
] + QdomainsInVerification
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/mallang/auth/domain/MemberRepository.java

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/com/mallang/auth/domain/oauth/OauthMemberClient.java

This file was deleted.

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/kotlin/com/mallang/auth/domain/MemberRepository.kt
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>
}
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
}
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()
}
}
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
}
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()
}
}

0 comments on commit ae490bb

Please sign in to comment.