Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static ProposalDirection fromWhoProposed(Role whoProposed) {
return switch (whoProposed) {
case BRAND -> BRAND_TO_CREATOR;
case CREATOR -> CREATOR_TO_BRAND;
case ADMIN, GUEST -> throw new IllegalArgumentException(
case ADMIN, GUEST, WITHDRAWN -> throw new IllegalArgumentException(
"Proposal direction is only for BRAND or CREATOR, got: " + whoProposed);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.RealMatch.user.application.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.RealMatch.global.exception.CustomException;
import com.example.RealMatch.global.presentation.code.GeneralErrorCode;
import com.example.RealMatch.user.domain.entity.User;
import com.example.RealMatch.user.domain.repository.UserRepository;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Transactional
public class UserWithdrawService {

private final UserRepository userRepository;

public void withdraw(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(GeneralErrorCode.INVALID_DATA));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

사용자를 찾지 못했을 때 GeneralErrorCode.INVALID_DATA를 사용하셨는데, 이는 다소 일반적인 오류 코드입니다. userRepository.findById는 이미 탈퇴한 사용자를 조회하지 않기 때문에, ID가 잘못되었거나 이미 탈퇴한 경우 모두 사용자를 찾지 못하게 됩니다. 이 경우, "요청한 리소스를 찾을 수 없음"을 의미하는 GeneralErrorCode.NOT_FOUND를 사용하는 것이 의미상 더 명확합니다.

Suggested change
.orElseThrow(() -> new CustomException(GeneralErrorCode.INVALID_DATA));
.orElseThrow(() -> new CustomException(GeneralErrorCode.NOT_FOUND));


user.withdraw(userId);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ public void updateInfo(String nickname, String address, String detailAddress) {
this.detailAddress = detailAddress;
}

public void softDelete(Long deletedBy) {
public void withdraw(Long deletedBy) {
this.isDeleted = true;
this.deletedAt = LocalDateTime.now();
this.deletedBy = deletedBy;
this.role = Role.WITHDRAWN;
}

public void completeSignup(String nickname, LocalDate birth, Gender gender, Role role) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum Role {
ADMIN,
GUEST,
BRAND,
CREATOR;
CREATOR,
WITHDRAWN;

// !!! customDetails에서 role을 string에서 Role로 바꾸면 이거 없앨거임
public static Role from(String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.RealMatch.user.presentation.controller;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -14,6 +15,7 @@
import com.example.RealMatch.match.presentation.dto.request.MatchRequestDto;
import com.example.RealMatch.user.application.service.UserFeatureService;
import com.example.RealMatch.user.application.service.UserService;
import com.example.RealMatch.user.application.service.UserWithdrawService;
import com.example.RealMatch.user.presentation.dto.request.MyEditInfoRequestDto;
import com.example.RealMatch.user.presentation.dto.response.MyEditInfoResponseDto;
import com.example.RealMatch.user.presentation.dto.response.MyFeatureResponseDto;
Expand All @@ -36,6 +38,7 @@ public class UserController implements UserSwagger {

private final UserService userService;
private final UserFeatureService userFeatureService;
private final UserWithdrawService userWithdrawService;

@Override
@GetMapping("/me")
Expand Down Expand Up @@ -117,4 +120,13 @@ public CustomResponse<NicknameAvailableResponseDto> checkNicknameAvailable(
boolean available = userService.isNicknameAvailable(nickname);
return CustomResponse.ok(new NicknameAvailableResponseDto(available));
}

@Override
@DeleteMapping("/me")
public CustomResponse<Void> withdraw(
@AuthenticationPrincipal CustomUserDetails userDetails
) {
userWithdrawService.withdraw(userDetails.getUserId());
return CustomResponse.ok(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,9 @@ CustomResponse<NicknameAvailableResponseDto> checkNicknameAvailable(
)
@RequestParam String nickname
);

@Operation(summary = "회원 탈퇴", description = "회원 탈퇴(Soft Delete) 처리 후 role을 WITHDRAWN으로 변경합니다.")
CustomResponse<Void> withdraw(
@AuthenticationPrincipal CustomUserDetails userDetails
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Swagger UI에서 userDetails 파라미터가 입력 필드로 표시되지 않도록 @Parameter(hidden = true) 어노테이션을 추가하는 것이 좋습니다. CustomUserDetails는 클라이언트가 직접 전달하는 값이 아니라 Spring Security가 인증 컨텍스트에서 해석하여 주입해주기 때문입니다. 다른 API 메소드들과의 일관성을 위해서도 이 어노테이션을 추가하는 것을 권장합니다.

Suggested change
@AuthenticationPrincipal CustomUserDetails userDetails
@Parameter(hidden = true) @AuthenticationPrincipal CustomUserDetails userDetails

);
}
Loading