generated from pricelees/issue-pr-template
[#44] 매장 기능 도입 #45
@ -13,6 +13,7 @@ import roomescape.common.dto.AdminLoginCredentials
|
|||||||
import roomescape.common.dto.CurrentUserContext
|
import roomescape.common.dto.CurrentUserContext
|
||||||
import roomescape.common.dto.OperatorInfo
|
import roomescape.common.dto.OperatorInfo
|
||||||
import roomescape.common.dto.PrincipalType
|
import roomescape.common.dto.PrincipalType
|
||||||
|
import roomescape.common.dto.toCredentials
|
||||||
|
|
||||||
private val log: KLogger = KotlinLogging.logger {}
|
private val log: KLogger = KotlinLogging.logger {}
|
||||||
|
|
||||||
@ -33,15 +34,15 @@ class AdminService(
|
|||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
fun findCredentialsByAccount(account: String): AdminLoginCredentials {
|
fun findCredentialsByAccount(account: String): AdminLoginCredentials {
|
||||||
log.info { "[AdminService.findInfoByAccount] 관리자 조회 시작: account=${account}" }
|
log.info { "[AdminService.findCredentialsByAccount] 관리자 조회 시작: account=${account}" }
|
||||||
|
|
||||||
return adminRepository.findByAccount(account)
|
return adminRepository.findByAccount(account)
|
||||||
?.let {
|
?.let {
|
||||||
log.info { "[AdminService.findByAccount] 관리자 조회 완료: account=${account}, id=${it.id}" }
|
log.info { "[AdminService.findCredentialsByAccount] 관리자 조회 완료: account=${account}, id=${it.id}" }
|
||||||
AdminLoginCredentials(it.id, it.password, it.permissionLevel)
|
it.toCredentials()
|
||||||
}
|
}
|
||||||
?: run {
|
?: run {
|
||||||
log.info { "[AdminService.findInfoByAccount] 관리자 조회 실패: account=${account}" }
|
log.info { "[AdminService.findCredentialsByAccount] 관리자 조회 실패: account=${account}" }
|
||||||
throw AdminException(AdminErrorCode.ADMIN_NOT_FOUND)
|
throw AdminException(AdminErrorCode.ADMIN_NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,24 +1,64 @@
|
|||||||
package roomescape.common.dto
|
package roomescape.common.dto
|
||||||
|
|
||||||
|
import roomescape.admin.infrastructure.persistence.AdminEntity
|
||||||
import roomescape.admin.infrastructure.persistence.AdminPermissionLevel
|
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"
|
const val MDC_PRINCIPAL_ID_KEY: String = "principal_id"
|
||||||
|
|
||||||
abstract class LoginCredentials {
|
abstract class LoginCredentials {
|
||||||
abstract val id: Long
|
abstract val id: Long
|
||||||
abstract val password: String
|
abstract val password: String
|
||||||
|
abstract val name: String
|
||||||
|
|
||||||
|
abstract fun toResponse(accessToken: String): LoginSuccessResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
data class AdminLoginCredentials(
|
data class AdminLoginCredentials(
|
||||||
override val id: Long,
|
override val id: Long,
|
||||||
override val password: String,
|
override val password: String,
|
||||||
val permissionLevel: AdminPermissionLevel
|
override val name: String,
|
||||||
) : LoginCredentials()
|
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(
|
data class UserLoginCredentials(
|
||||||
override val id: Long,
|
override val id: Long,
|
||||||
override val password: String,
|
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(
|
data class CurrentUserContext(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
|
|||||||
@ -47,7 +47,7 @@ class UserService(
|
|||||||
return userRepository.findByEmail(email)
|
return userRepository.findByEmail(email)
|
||||||
?.let {
|
?.let {
|
||||||
log.info { "[UserService.findCredentialsByAccount] 회원 조회 완료: id=${it.id}" }
|
log.info { "[UserService.findCredentialsByAccount] 회원 조회 완료: id=${it.id}" }
|
||||||
UserLoginCredentials(it.id, it.password)
|
it.toCredentials()
|
||||||
}
|
}
|
||||||
?: run {
|
?: run {
|
||||||
log.info { "[UserService.findCredentialsByAccount] 회원 조회 실패" }
|
log.info { "[UserService.findCredentialsByAccount] 회원 조회 실패" }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user