Skip to content

Commit

Permalink
🔀 :: (#243) logout API (#147)
Browse files Browse the repository at this point in the history
* ⚡️ :: logout API

* ♻️ :: method명 수정

* ♻️ :: method로 분리
  • Loading branch information
jyk1029 authored Sep 30, 2023
1 parent 4260b80 commit 3d99575
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ interface UserApi {
suspend fun getAllStudentByName(name: String): List<User>
suspend fun getAllUserByRole(role: String?): List<User>
suspend fun getExcludeUserIdList(userIdList: List<UUID>?): List<UUID>
suspend fun setEmptyDeviceToken(userId: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ class UserApiImpl(
}

override suspend fun updateProfileFileName(userId: UUID, profileFileName: String?) {
val user = userRepositorySpi.findByIdAndStateWithCreated(userId)
?: throw UserNotFoundException(UserNotFoundException.USER_ID_NOT_FOUND)
val user = getUserById(userId)
val updatedUser = user.updateProfileFileName(profileFileName)
userRepositorySpi.applyChanges(updatedUser)
}
Expand Down Expand Up @@ -188,8 +187,7 @@ class UserApiImpl(

refreshTokenSpi.delete(refreshTokenEntity)

val user = userRepositorySpi.findByIdAndStateWithCreated(refreshTokenEntity.userId)
?: throw UserNotFoundException(UserNotFoundException.USER_ID_NOT_FOUND)
val user = getUserById(refreshTokenEntity.userId)
refreshTokenSpi.delete(refreshTokenEntity)

val params = buildAccessTokenParams(user)
Expand Down Expand Up @@ -219,6 +217,11 @@ class UserApiImpl(
}
}

override suspend fun setEmptyDeviceToken(userId: UUID) {
val user = getUserById(userId)
user.setDeviceToken("")
}

private suspend fun saveNewRefreshToken(user: User, params: MutableMap<String, Any>): RefreshToken {
val newRefreshToken = jwtTokenGeneratorSpi.generateJwtToken(user.id.toString(), TokenType.REFRESH_TOKEN, params)

Expand All @@ -231,8 +234,7 @@ class UserApiImpl(
}

override suspend fun getUserPointInformation(userId: UUID): PointDomainResponse {
val user = userRepositorySpi.findByIdAndStateWithCreated(userId)
?: throw UserNotFoundException(UserNotFoundException.USER_ID_NOT_FOUND)
val user = getUserById(userId)

val userPoint = pointSpi.getUserPoint(userId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ class UserHandler(
return ServerResponse.ok().bodyValueAndAwait(response)
}

suspend fun logoutHandler(serverRequest: ServerRequest): ServerResponse {
val userId = requestHeaderAspect.getUserId(serverRequest)
userApi.setEmptyDeviceToken(userId)

return ServerResponse.noContent().buildAndAwait()
}

private fun User.toGetUserNameResponseDto() =
GetUserNameResponse(
id = this.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class UserRouter {
GET("/search", userHandler::getAllStudentByNameHandler)
GET("/role", userHandler::getUserByRoleHandler)
POST("/exclude", userHandler::getExcludeUserListHandler)
PUT("", userHandler::logoutHandler)
}
}
}

0 comments on commit 3d99575

Please sign in to comment.