Skip to content

Commit 4e767e3

Browse files
committed
feat: restore user
1 parent e240efc commit 4e767e3

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/main/kotlin/com/open3r/openmusic/domain/admin/user/controller/AdminUserController.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ class AdminUserController(
2727
@DeleteMapping("/{userId}")
2828
@PreAuthorize("hasRole('ADMIN')")
2929
fun deleteUser(@PathVariable userId: Long) = BaseResponse(adminUserService.deleteUser(userId), 204).toEntity()
30+
31+
@Operation(summary = "유저 복구")
32+
@PatchMapping("/{userId}/restore")
33+
@PreAuthorize("hasRole('ADMIN')")
34+
fun restoreUser(@PathVariable userId: Long) = BaseResponse(adminUserService.restoreUser(userId), 200).toEntity()
3035
}

src/main/kotlin/com/open3r/openmusic/domain/admin/user/service/AdminUserService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ interface AdminUserService {
66
fun getUsers(): List<UserResponse>
77
fun getDeletedUsers(): List<UserResponse>
88
fun deleteUser(userId: Long)
9+
fun restoreUser(userId: Long)
910
}

src/main/kotlin/com/open3r/openmusic/domain/admin/user/service/impl/AdminUserServiceImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ class AdminUserServiceImpl(
3434

3535
userRepository.save(user)
3636
}
37+
38+
@Transactional
39+
override fun restoreUser(userId: Long) {
40+
val user = userRepository.findByIdOrNull(userId) ?: throw CustomException(ErrorCode.USER_NOT_FOUND)
41+
42+
if (user.status == UserStatus.ACTIVE) throw CustomException(ErrorCode.USER_ALREADY_ACTIVE)
43+
44+
user.status = UserStatus.ACTIVE
45+
46+
userRepository.save(user)
47+
}
3748
}

src/main/kotlin/com/open3r/openmusic/global/error/ErrorCode.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum class ErrorCode(
6363
USER_QUEUE_NOT_FOUND(HttpStatus.NOT_FOUND, "User queue not found"),
6464
USER_QUEUE_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, "User queue already exists"),
6565
USER_ALREADY_DELETED(HttpStatus.BAD_REQUEST, "User already deleted"),
66+
USER_ALREADY_ACTIVE(HttpStatus.BAD_REQUEST, "User already active"),
6667

6768
// Else
6869
MAX_UPLOAD_SIZE_EXCEEDED(HttpStatus.BAD_REQUEST, "Max upload size exceeded"),

0 commit comments

Comments
 (0)