Skip to content

Commit

Permalink
imp: reactor handler sync fun을 suspend로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 16, 2024
1 parent 2bcf859 commit 56ed698
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class AuthFacade(
private val TOKEN_EXPIRED_DATE = LocalDateTime.of(2024, 12, 29, 0, 0, 0)
}

fun resolveAuthUser(token: AuthUserToken): AuthUser {
suspend fun resolveAuthUser(token: AuthUserToken): AuthUser {
val payload = jwtTokenService.verifyToken(token)

if (payload.type != "accessToken") {
throw InvalidTokenException(ErrorCode.INVALID_ACCESS_TOKEN)
}

val user = userInfoService.getUserByIdOrThrowSync(payload.id)
val user = userInfoService.getUserByIdOrThrow(payload.id)

return AuthUserImpl.from(user)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ class AuthFacade(
}

suspend fun signIn(request: SignInRequest): SignInResponse {
val userInfo = userInfoService.findByCredential(request.username, request.password)
val userInfo = userInfoService.findByCredentialOrThrow(request.username, request.password)

val accessToken = jwtTokenService.createToken(userInfo.id, TOKEN_EXPIRED_DATE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,21 @@ class UserInfoService(
return UserInfoResponse.from(userInfo)
}

suspend fun findByCredential(username: String, password: String): UserInfo {
suspend fun findByCredentialOrThrow(username: String, password: String): UserInfo {
return withContext(Dispatchers.IO) {
findByCredentialSync(username, password)
userInfoRepository.findByCredential(
username = username,
password = EncryptData.enc(password, encryptor)
)
} ?: throw NotFoundException(ErrorCode.NOT_FOUND_USER_ERROR)
}

private fun findByCredentialSync(username: String, password: String): UserInfo? {
return userInfoRepository.findByCredential(
username = username,
password = EncryptData.enc(password, encryptor)
)
}

suspend fun findAllByIds(ids: List<Long>): List<UserInfo> {
return withContext(Dispatchers.IO) {
findAllByIdsSync(ids)
userInfoRepository.findAllById(ids)
}
}

fun findAllByIdsSync(ids: List<Long>): List<UserInfo> {
return userInfoRepository.findAllById(ids)
}

suspend fun findByOAuthOrThrow(provider: OAuthProvider, oauthId: String): UserInfo {
return withContext(Dispatchers.IO) {
userInfoRepository.findByOAuth(provider, oauthId)
Expand Down

0 comments on commit 56ed698

Please sign in to comment.