Skip to content

Commit

Permalink
[Refactor] 회원 탈퇴 코드 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed Jun 20, 2024
1 parent 379c852 commit c88f5e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public ResponseEntity<ResponseMemberDTO> updateUserPw(@AuthenticationPrincipal C
@Operation(summary = "회원 탈퇴", description = "비밀번호 이용")
@ApiResponse(responseCode = "200", description = "회원 탈퇴 성공", content = @Content(schema = @Schema(implementation = ResponseDTO.class)))
@ApiResponse(responseCode = "404", description = "회원 비밀번호 불일치", content = @Content(schema = @Schema(implementation = ErrorDTO.class)))
public ResponseEntity<ResponseDTO> deleteMember(@AuthenticationPrincipal CustomUserDetails user, @RequestParam String userPw) {
memberService.deleteMember(user.getUsername(), userPw);
public ResponseEntity<ResponseDTO> deleteMember(@AuthenticationPrincipal CustomUserDetails user) {
memberService.deleteMember(user.getUsername());
return ResponseEntity.ok(ResponseDTO.builder()
.msg("회원 탈퇴 성공")
.build());
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/com/jiyunio/todolist/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,12 @@ public ResponseMemberDTO updateUserPw(String userId, @Valid ChangeUserPwDTO chan
}
}

public void deleteMember(String userId, String userPw) {
public void deleteMember(String userId) {
Member member = memberRepository.findByUserId(userId).orElseThrow(
() -> new CustomException(HttpStatus.NOT_FOUND, ErrorCode.NOT_EXIST_MEMBER)
);
if (passwordEncoder.matches(userPw, member.getUserPw())) { // 회원 탈퇴 성공
todoService.deleteTodos(userId);
categoryService.deleteCategories(userId);
memberRepository.deleteById(member.getId());
} else {
// 비밀번호 불일치
throw new CustomException(HttpStatus.NOT_FOUND, ErrorCode.WRONG_USERID_PASSWORD);
}
todoService.deleteTodos(userId);
categoryService.deleteCategories(userId);
memberRepository.deleteById(member.getId());
}
}

0 comments on commit c88f5e3

Please sign in to comment.