Skip to content

Commit

Permalink
feat: restore user
Browse files Browse the repository at this point in the history
  • Loading branch information
jbj338033 committed Aug 1, 2024
1 parent e240efc commit 4e767e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ class AdminUserController(
@DeleteMapping("/{userId}")
@PreAuthorize("hasRole('ADMIN')")
fun deleteUser(@PathVariable userId: Long) = BaseResponse(adminUserService.deleteUser(userId), 204).toEntity()

@Operation(summary = "유저 복구")
@PatchMapping("/{userId}/restore")
@PreAuthorize("hasRole('ADMIN')")
fun restoreUser(@PathVariable userId: Long) = BaseResponse(adminUserService.restoreUser(userId), 200).toEntity()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ interface AdminUserService {
fun getUsers(): List<UserResponse>
fun getDeletedUsers(): List<UserResponse>
fun deleteUser(userId: Long)
fun restoreUser(userId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ class AdminUserServiceImpl(

userRepository.save(user)
}

@Transactional
override fun restoreUser(userId: Long) {
val user = userRepository.findByIdOrNull(userId) ?: throw CustomException(ErrorCode.USER_NOT_FOUND)

if (user.status == UserStatus.ACTIVE) throw CustomException(ErrorCode.USER_ALREADY_ACTIVE)

user.status = UserStatus.ACTIVE

userRepository.save(user)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum class ErrorCode(
USER_QUEUE_NOT_FOUND(HttpStatus.NOT_FOUND, "User queue not found"),
USER_QUEUE_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, "User queue already exists"),
USER_ALREADY_DELETED(HttpStatus.BAD_REQUEST, "User already deleted"),
USER_ALREADY_ACTIVE(HttpStatus.BAD_REQUEST, "User already active"),

// Else
MAX_UPLOAD_SIZE_EXCEEDED(HttpStatus.BAD_REQUEST, "Max upload size exceeded"),
Expand Down

0 comments on commit 4e767e3

Please sign in to comment.