generated from pricelees/issue-pr-template
refactor: 로그인시 사용하는 LoginCredential 회원 / 관리자 분리 및 헬퍼 메서드 추가
This commit is contained in:
parent
9361ea606b
commit
63251d67ea
@ -13,6 +13,7 @@ import roomescape.common.dto.AdminLoginCredentials
|
||||
import roomescape.common.dto.CurrentUserContext
|
||||
import roomescape.common.dto.OperatorInfo
|
||||
import roomescape.common.dto.PrincipalType
|
||||
import roomescape.common.dto.toCredentials
|
||||
|
||||
private val log: KLogger = KotlinLogging.logger {}
|
||||
|
||||
@ -33,15 +34,15 @@ class AdminService(
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
fun findCredentialsByAccount(account: String): AdminLoginCredentials {
|
||||
log.info { "[AdminService.findInfoByAccount] 관리자 조회 시작: account=${account}" }
|
||||
log.info { "[AdminService.findCredentialsByAccount] 관리자 조회 시작: account=${account}" }
|
||||
|
||||
return adminRepository.findByAccount(account)
|
||||
?.let {
|
||||
log.info { "[AdminService.findByAccount] 관리자 조회 완료: account=${account}, id=${it.id}" }
|
||||
AdminLoginCredentials(it.id, it.password, it.permissionLevel)
|
||||
log.info { "[AdminService.findCredentialsByAccount] 관리자 조회 완료: account=${account}, id=${it.id}" }
|
||||
it.toCredentials()
|
||||
}
|
||||
?: run {
|
||||
log.info { "[AdminService.findInfoByAccount] 관리자 조회 실패: account=${account}" }
|
||||
log.info { "[AdminService.findCredentialsByAccount] 관리자 조회 실패: account=${account}" }
|
||||
throw AdminException(AdminErrorCode.ADMIN_NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,64 @@
|
||||
package roomescape.common.dto
|
||||
|
||||
import roomescape.admin.infrastructure.persistence.AdminEntity
|
||||
import roomescape.admin.infrastructure.persistence.AdminPermissionLevel
|
||||
import roomescape.admin.infrastructure.persistence.AdminType
|
||||
import roomescape.auth.web.AdminLoginSuccessResponse
|
||||
import roomescape.auth.web.LoginSuccessResponse
|
||||
import roomescape.auth.web.UserLoginSuccessResponse
|
||||
import roomescape.user.infrastructure.persistence.UserEntity
|
||||
|
||||
const val MDC_PRINCIPAL_ID_KEY: String = "principal_id"
|
||||
|
||||
abstract class LoginCredentials {
|
||||
abstract val id: Long
|
||||
abstract val password: String
|
||||
abstract val name: String
|
||||
|
||||
abstract fun toResponse(accessToken: String): LoginSuccessResponse
|
||||
}
|
||||
|
||||
data class AdminLoginCredentials(
|
||||
override val id: Long,
|
||||
override val password: String,
|
||||
val permissionLevel: AdminPermissionLevel
|
||||
) : LoginCredentials()
|
||||
override val name: String,
|
||||
val type: AdminType,
|
||||
val storeId: Long?,
|
||||
val permissionLevel: AdminPermissionLevel,
|
||||
) : LoginCredentials() {
|
||||
override fun toResponse(accessToken: String) = AdminLoginSuccessResponse(
|
||||
accessToken = accessToken,
|
||||
name = name,
|
||||
type = type,
|
||||
storeId = storeId
|
||||
)
|
||||
}
|
||||
|
||||
fun AdminEntity.toCredentials() = AdminLoginCredentials(
|
||||
id = this.id,
|
||||
password = this.password,
|
||||
name = this.name,
|
||||
type = this.type,
|
||||
storeId = this.storeId,
|
||||
permissionLevel = this.permissionLevel
|
||||
)
|
||||
|
||||
data class UserLoginCredentials(
|
||||
override val id: Long,
|
||||
override val password: String,
|
||||
) : LoginCredentials()
|
||||
override val name: String,
|
||||
) : LoginCredentials() {
|
||||
override fun toResponse(accessToken: String) = UserLoginSuccessResponse(
|
||||
accessToken = accessToken,
|
||||
name = name
|
||||
)
|
||||
}
|
||||
|
||||
fun UserEntity.toCredentials() = UserLoginCredentials(
|
||||
id = this.id,
|
||||
password = this.password,
|
||||
name = this.name,
|
||||
)
|
||||
|
||||
data class CurrentUserContext(
|
||||
val id: Long,
|
||||
|
||||
@ -47,7 +47,7 @@ class UserService(
|
||||
return userRepository.findByEmail(email)
|
||||
?.let {
|
||||
log.info { "[UserService.findCredentialsByAccount] 회원 조회 완료: id=${it.id}" }
|
||||
UserLoginCredentials(it.id, it.password)
|
||||
it.toCredentials()
|
||||
}
|
||||
?: run {
|
||||
log.info { "[UserService.findCredentialsByAccount] 회원 조회 실패" }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user