val userHashMap = HashMap<UUID, String>()
fun signIn(request: UserSignInRequest): UserSignInResponse {
val user = userRepository.findByAccountId(request.accountId)
?: throw UnAuthorizedException
if (request.password != user.password) {
throw UnAuthorizedException
}
val randomUUID = UUID.randomUUID()
userHashMap[randomUUID] = request.accountId
return UserSignInResponse(randomUUID = randomUUID)
}
fun addTodo(request: AddTodoRequest, httpServletRequest: HttpServletRequest) {
val userUUID = httpServletRequest.getHeader("Authorization")
val userAccountId = userHashMap[UUID.fromString(userUUID)]
?: throw UnAuthorizedException
val user = userRepository.findByAccountId(userAccountId)
?: throw UserNotFoundException
todoRepository.save(
TodoEntity(
title = request.title,
content = request.content,
isCompleted = false,
user = user,
)
)
}
로그인을 한 뒤 발급받은 UUID로 Authorization Header에 넘기면 성공하는걸 확인할 수 있습니다.