Skip to content

Commit

Permalink
🐛[fix]: 회원탈퇴 userID 기반으로 삭제하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyesooo committed Nov 8, 2023
1 parent 872cf26 commit 05aef30
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ public ApiRes<UserResource> searchUserByUid(@PathVariable("id") Long id) {
/*
* 회원 탈퇴
* */
@PostMapping("/withdrawal")
@PostMapping("/withdrawal/{userId}")
@Operation(summary = "회원 탈퇴",
description = "회원 정보 삭제 및 탈퇴 사유를 저장한다.",
responses = {@ApiResponse(responseCode = "200", description = "탈퇴 성공")}
)
public ApiRes<?> signup(@RequestBody UserWithdrawalResource withdrawalResource) {
@Parameter(name = "userId", description = "userId", in = ParameterIn.PATH)
public ApiRes<?> signup(@PathVariable("userId") Long userId, @RequestBody UserWithdrawalResource withdrawalResource) {
withdrawalResource.setUserId(userId);
userService.withdrawalAccount(commonConverter.convertToGeneric(withdrawalResource, WithdrawalDto.class));
return ApiRes.createSuccessWithNoContent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Getter
@Setter
public class WithdrawalDto {
private String uid;
private Long userId;
private String reason;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pingpong.quoteBakery.sys.resource;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -9,8 +10,9 @@
@Getter
@Setter
public class UserWithdrawalResource {
@Schema(description = "탈퇴유저uid")
private String uid;
@Hidden
@Schema(description = "사용자ID")
private Long userId;

@Schema(description = "탈퇴사유")
private String reason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ public boolean validateUid(String uid){

@Transactional
public void withdrawalAccount(WithdrawalDto dto){
User user = userRepository.findById(dto.getUserId()).orElseThrow(() -> new BusinessInvalidValueException("해당 ID에 대한 사용자 정보가 없습니다."));

String tokenUid = tokenService.getCurrentTokenInfo().getUid();
String requestUid = dto.getUid();
String requestUid = user.getUid();

if(!requestUid.equals(tokenUid)) throw new BusinessInvalidValueException("본인만 회원 탈퇴할 수 있습니다.");

User user = userRepository.findByUid(requestUid).orElseThrow(() -> new BusinessInvalidValueException("해당 ID에 대한 정보가 없습니다."));
userPreferenceRepository.deleteAllByUserId(user.getId());
likeRepository.deleteAllByUserId(user.getId());
userRepository.delete(user);
Expand Down

0 comments on commit 05aef30

Please sign in to comment.