diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/UserApi.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/UserApi.kt index ae29f94..1774476 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/UserApi.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/UserApi.kt @@ -24,4 +24,5 @@ interface UserApi { suspend fun getAllStudentByName(name: String): List suspend fun getAllUserByRole(role: String?): List suspend fun getExcludeUserIdList(userIdList: List?): List + suspend fun setEmptyDeviceToken(userId: UUID) } diff --git a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt index b88d5bf..10ae2d5 100644 --- a/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt +++ b/user-domain/src/main/kotlin/com/xquare/v1userservice/user/api/impl/UserApiImpl.kt @@ -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) } @@ -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) @@ -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): RefreshToken { val newRefreshToken = jwtTokenGeneratorSpi.generateJwtToken(user.id.toString(), TokenType.REFRESH_TOKEN, params) @@ -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) diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt index 5a862d4..680953a 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserHandler.kt @@ -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, diff --git a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt index 4f4eb09..062e092 100644 --- a/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt +++ b/user-infrastructure/src/main/kotlin/com/xquare/v1userservice/user/router/UserRouter.kt @@ -29,6 +29,7 @@ class UserRouter { GET("/search", userHandler::getAllStudentByNameHandler) GET("/role", userHandler::getUserByRoleHandler) POST("/exclude", userHandler::getExcludeUserListHandler) + PUT("", userHandler::logoutHandler) } } }