[#34] 회원 / 인증 도메인 재정의 #43

Merged
pricelees merged 73 commits from refactor/#34 into main 2025-09-13 10:13:45 +00:00
2 changed files with 56 additions and 1 deletions
Showing only changes of commit 39da28d3f1 - Show all commits

View File

@ -0,0 +1,52 @@
package roomescape.member.business
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import roomescape.common.dto.CurrentUserContext
import roomescape.common.dto.PrincipalType
import roomescape.common.dto.UserLoginCredentials
import roomescape.member.exception.UserErrorCode
import roomescape.member.exception.UserException
import roomescape.member.infrastructure.persistence.UserEntity
import roomescape.member.infrastructure.persistence.UserRepository
private val log: KLogger = KotlinLogging.logger {}
@Service
class UserService(
private val userRepository: UserRepository,
) {
@Transactional(readOnly = true)
fun findContextById(id: Long): CurrentUserContext {
log.info { "[UserService.findContextById] 현재 로그인된 회원 조회 시작: id=${id}" }
val user: UserEntity = findOrThrow(id)
return CurrentUserContext(user.id, user.name, PrincipalType.USER)
.also {
log.info { "[UserService.findContextById] 현재 로그인된 회원 조회 완료: id=${id}" }
}
}
@Transactional(readOnly = true)
fun findCredentialsByAccount(email: String): UserLoginCredentials {
log.info { "[UserService.findCredentialsByAccount] 회원 조회 시작: email=${email}" }
return userRepository.findByEmail(email)
?.let {
log.info { "[UserService.findCredentialsByAccount] 회원 조회 완료: id=${it.id}" }
UserLoginCredentials(it.id, it.password)
}
?: run {
log.info { "[UserService.findCredentialsByAccount] 회원 조회 실패" }
throw UserException(UserErrorCode.USER_NOT_FOUND)
}
}
private fun findOrThrow(id: Long): UserEntity {
return userRepository.findByIdOrNull(id)
?: throw UserException(UserErrorCode.USER_NOT_FOUND)
}
}

View File

@ -2,6 +2,9 @@ package roomescape.member.infrastructure.persistence
import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.JpaRepository
interface UserRepository : JpaRepository<UserEntity, Long> interface UserRepository : JpaRepository<UserEntity, Long> {
fun findByEmail(email: String): UserEntity?
}
interface UserStatusHistoryRepository : JpaRepository<UserStatusHistoryEntity, Long> interface UserStatusHistoryRepository : JpaRepository<UserStatusHistoryEntity, Long>