From 3efb08fb5b6083fa82ff339f575aa59f798201c3 Mon Sep 17 00:00:00 2001 From: ibaesuyeon Date: Sat, 27 Apr 2024 19:30:53 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EC=8A=B9=EC=9D=B8=EC=97=AC=EB=B6=80?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/UserService/controller/UserController.java | 8 ++++++++ .../java/com/example/UserService/service/UserService.java | 2 ++ .../com/example/UserService/service/UserServiceImpl.java | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/example/UserService/controller/UserController.java b/src/main/java/com/example/UserService/controller/UserController.java index 264729b..18f17db 100644 --- a/src/main/java/com/example/UserService/controller/UserController.java +++ b/src/main/java/com/example/UserService/controller/UserController.java @@ -123,4 +123,12 @@ public ResponseEntity> getAllUsers() { List users = userService.getAllUsers(); return ResponseEntity.ok(users); } + + //승인 여부 변경 + @PutMapping("/approve") + public ResponseEntity approveUser(@RequestParam("userId") @Valid Long userId, + @RequestParam("approved") boolean approved) { + boolean isApproved = userService.updateApproved(userId, approved); + return ResponseEntity.ok().body(isApproved); + } } diff --git a/src/main/java/com/example/UserService/service/UserService.java b/src/main/java/com/example/UserService/service/UserService.java index df304f4..fef14ed 100644 --- a/src/main/java/com/example/UserService/service/UserService.java +++ b/src/main/java/com/example/UserService/service/UserService.java @@ -35,4 +35,6 @@ public interface UserService{ ResponseEntity unregister(Long userId); List getAllUsers(); + + boolean updateApproved(Long userId, boolean approved); } diff --git a/src/main/java/com/example/UserService/service/UserServiceImpl.java b/src/main/java/com/example/UserService/service/UserServiceImpl.java index fb53a8a..6df78d4 100644 --- a/src/main/java/com/example/UserService/service/UserServiceImpl.java +++ b/src/main/java/com/example/UserService/service/UserServiceImpl.java @@ -209,4 +209,12 @@ public List getAllUsers() { } return userResponses; } + + @Override + public boolean updateApproved(Long userId, boolean approved) { + UserEntity user = userRepository.findById(userId).orElseThrow(); + user.setApproved(approved); + userRepository.save(user); + return user.isApproved(); + } }