Skip to content

Commit

Permalink
feat: 유저 조회시, 회원가입 Provider Type 제공
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Dec 3, 2024
1 parent 9f2cabd commit 44bddd3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hero.alignlab.domain.auth.application

import arrow.fx.coroutines.parZip
import com.hero.alignlab.common.encrypt.EncryptData
import com.hero.alignlab.common.encrypt.Encryptor
import com.hero.alignlab.common.extension.coExecute
Expand All @@ -12,9 +13,12 @@ import com.hero.alignlab.domain.auth.model.request.SignUpRequest
import com.hero.alignlab.domain.auth.model.response.SignInResponse
import com.hero.alignlab.domain.auth.model.response.SignUpResponse
import com.hero.alignlab.domain.user.application.CredentialUserInfoService
import com.hero.alignlab.domain.user.application.OAuthUserInfoService
import com.hero.alignlab.domain.user.application.UserInfoService
import com.hero.alignlab.domain.user.domain.CredentialUserInfo
import com.hero.alignlab.domain.user.domain.UserInfo
import com.hero.alignlab.domain.user.domain.vo.OAuthProvider
import com.hero.alignlab.domain.user.model.response.AuthProvider
import com.hero.alignlab.domain.user.model.response.UserInfoResponse
import com.hero.alignlab.exception.ErrorCode
import com.hero.alignlab.exception.InvalidRequestException
Expand All @@ -27,6 +31,7 @@ import java.time.LocalDateTime
class AuthFacade(
private val userInfoService: UserInfoService,
private val credentialUserInfoService: CredentialUserInfoService,
private val oAuthUserInfoService: OAuthUserInfoService,
private val jwtTokenService: JwtTokenService,
private val encryptor: Encryptor,
private val txTemplates: TransactionTemplates,
Expand Down Expand Up @@ -94,8 +99,22 @@ class AuthFacade(
}

suspend fun getUserInfo(user: AuthUser): UserInfoResponse {
val userInfo = userInfoService.getUserByIdOrThrow(user.uid)
return parZip(
{ userInfoService.getUserByIdOrThrow(user.uid) },
{ credentialUserInfoService.findAllByUid(user.uid) },
{ oAuthUserInfoService.findAllByUid(user.uid) },
) { userInfo, credentialUsers, oAuthUsers ->
val providers = buildList {
if (credentialUsers.isNotEmpty()) {
add(AuthProvider.BASIC)
}

repeat(
oAuthUsers.filter { it.provider == OAuthProvider.KAKAO }.size
) { add(AuthProvider.KAKAO) }
}

return UserInfoResponse.from(userInfo)
UserInfoResponse.of(userInfo, providers)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ class CredentialUserInfoService(
fun saveSync(credentialUserInfo: CredentialUserInfo): CredentialUserInfo {
return credentialUserInfoRepository.save(credentialUserInfo)
}

suspend fun findAllByUid(uid: Long): List<CredentialUserInfo> {
return withContext(Dispatchers.IO) {
credentialUserInfoRepository.findAllByUid(uid)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hero.alignlab.domain.user.application

import com.hero.alignlab.domain.user.domain.vo.OAuthProvider
import com.hero.alignlab.domain.user.domain.OAuthUserInfo
import com.hero.alignlab.domain.user.domain.vo.OAuthProvider
import com.hero.alignlab.domain.user.infrastructure.OAuthUserInfoRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -33,4 +33,10 @@ class OAuthUserInfoService(
oAuthUserInfoRepository.findByProviderAndOauthId(provider, oauthId)
}
}

suspend fun findAllByUid(uid: Long): List<OAuthUserInfo> {
return withContext(Dispatchers.IO) {
oAuthUserInfoRepository.findAllByUid(uid)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UserInfoService(
getUserByIdOrThrowSync(id)
}

return UserInfoResponse.from(userInfo)
return UserInfoResponse.of(userInfo)
}

suspend fun findByCredentialOrThrow(username: String, password: String): UserInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ interface CredentialUserInfoRepository : JpaRepository<CredentialUserInfo, Long>
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun deleteAllByUid(uid: Long)

fun findAllByUid(uid: Long): List<CredentialUserInfo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ interface OAuthUserInfoRepository : JpaRepository<OAuthUserInfo, Long> {
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun deleteAllByUid(uid: Long)

fun findAllByUid(uid: Long): List<OAuthUserInfo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ import com.hero.alignlab.domain.user.domain.UserInfo
data class UserInfoResponse(
val uid: Long,
val nickname: String,
val providers: List<AuthProvider> = emptyList(),
val level: Int,
) {
companion object {
fun from(user: UserInfo): UserInfoResponse {
fun of(user: UserInfo, providers: List<AuthProvider>): UserInfoResponse {
return UserInfoResponse(
uid = user.id,
nickname = user.nickname,
providers = providers,
level = user.level,
)
}

fun of(user: UserInfo): UserInfoResponse {
return UserInfoResponse(
uid = user.id,
nickname = user.nickname,
Expand All @@ -17,3 +27,9 @@ data class UserInfoResponse(
}
}
}

enum class AuthProvider {
BASIC,
KAKAO,
;
}

0 comments on commit 44bddd3

Please sign in to comment.