Skip to content

Commit

Permalink
feat: DELETE Method - 유저 정보 삭제 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Apr 21, 2023
1 parent 6c18b07 commit 9eecf45
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public ResponseEntity<?> updateUser(@PathVariable Long userId, @RequestBody User
return generateUpdateResponseEntity(updateResult, userId);
}

@DeleteMapping("/delete/{userId}")
public ResponseEntity<?> updateUser(@PathVariable Long userId) {
boolean deleteResult = userService.deleteUser(userId);

return generateDeleteResponseEntity(deleteResult, userId);
}




Expand All @@ -52,4 +59,10 @@ private ResponseEntity<?> generateUpdateResponseEntity(boolean updateResult, Lon
new ResponseEntity<>(userId + "번 유저에 대한 정보가 존재하지 않습니다.", HttpStatus.NO_CONTENT);
}

private ResponseEntity<?> generateDeleteResponseEntity(boolean deleteResult, Long userId) {
return (deleteResult) ?
new ResponseEntity<>(userId + "번 유저에 대한 정보가 성공적으로 삭제 되었습니다.", HttpStatus.OK):
new ResponseEntity<>(userId + "번 유저에 대한 정보가 존재하지 않습니다.", HttpStatus.NO_CONTENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface UserRepository {
Optional<User> find(Long userId);

void update(Long userId, User user);

void delete(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public Optional<User> find(Long userId) {
@Override
public void update(Long userId, User user) {
userData.replace(userId, user);
System.out.println("userData.get(userId) = " + userData.get(userId).getName());
}

@Override
public void delete(Long userId) {
userData.remove(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface UserService{
Optional<User> findUserById(Long userId);

boolean updateUser(Long userId, UserRequestDto userDto);

boolean deleteUser(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,19 @@ public boolean updateUser(Long userId, UserRequestDto updateDto) {

return updateResult;
}

@Override
public boolean deleteUser(Long userId) {
boolean deleteResult = true;

Optional<User> user = userRepository.find(userId);

if(user.isEmpty()) {
deleteResult = false;
return deleteResult;
}

userRepository.delete(userId);
return deleteResult;
}
}

0 comments on commit 9eecf45

Please sign in to comment.