Skip to content

Commit 11960bc

Browse files
committed
[BOOK-52] refactor: apis - Exception 추가 (#11)
1 parent 610cfb0 commit 11960bc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

apis/src/main/kotlin/org/yapp/apis/auth/exception/AuthErrorCode.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ enum class AuthErrorCode(
2222
INVALID_ID_TOKEN_FORMAT(HttpStatus.BAD_REQUEST, "AUTH_008", "Invalid ID token format."),
2323
SUBJECT_NOT_FOUND(HttpStatus.BAD_REQUEST, "AUTH_009", "Subject not found in ID token."),
2424
FAILED_TO_PARSE_ID_TOKEN(HttpStatus.BAD_REQUEST, "AUTH_010", "Failed to parse ID token."),
25-
FAILED_TO_GET_USER_INFO(HttpStatus.BAD_REQUEST, "AUTH_011", "Failed to get user info from provider.");
25+
FAILED_TO_GET_USER_INFO(HttpStatus.BAD_REQUEST, "AUTH_011", "Failed to get user info from provider."),
26+
USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "AUTH_012", "User not found.");
2627

2728
override fun getHttpStatus(): HttpStatus = httpStatus
2829
override fun getCode(): String = code

apis/src/main/kotlin/org/yapp/apis/auth/service/AuthServiceImpl.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.yapp.apis.auth.service
22

33
import org.springframework.stereotype.Service
4+
import org.yapp.apis.auth.dto.TokenPair
45
import org.yapp.apis.auth.dto.UserProfileResponse
56
import org.yapp.apis.auth.exception.AuthErrorCode
67
import org.yapp.apis.auth.exception.AuthException
@@ -32,7 +33,9 @@ class AuthServiceImpl(
3233
)
3334

3435
if (existingUser != null) {
35-
return generateTokenPair(existingUser.id!!)
36+
return generateTokenPair(
37+
existingUser.id ?: throw IllegalStateException("Existing user id should not be null")
38+
)
3639
}
3740

3841
userRepository.findByEmail(userInfo.email)?.let {
@@ -70,11 +73,10 @@ class AuthServiceImpl(
7073
tokenRepository.deleteRefreshToken(userId)
7174
}
7275

73-
override fun getUserById(userId: Long): User? = null
76+
override fun getUserById(userId: Long): User? = userRepository.findById(userId)
7477

7578
override fun getUserProfile(userId: Long): UserProfileResponse {
7679
val user = userRepository.findById(userId)
77-
7880
return UserProfileResponse(
7981
id = user.id!!,
8082
email = user.email,
@@ -98,7 +100,10 @@ class AuthServiceImpl(
98100

99101
private fun getAuthStrategy(credentials: AuthCredentials): AuthStrategy {
100102
return authStrategies.find { it.getProviderType() == credentials.getProviderType() }
101-
?: throw AuthException(AuthErrorCode.UNSUPPORTED_PROVIDER_TYPE, "Unsupported provider type: ${credentials.getProviderType()}")
103+
?: throw AuthException(
104+
AuthErrorCode.UNSUPPORTED_PROVIDER_TYPE,
105+
"Unsupported provider type: ${credentials.getProviderType()}"
106+
)
102107
}
103108

104109
private fun generateTokenPair(userId: Long): TokenPair {

0 commit comments

Comments
 (0)