diff --git a/src/main/java/side/onetime/controller/UserController.java b/src/main/java/side/onetime/controller/UserController.java index 37c2d98..7af1ffe 100644 --- a/src/main/java/side/onetime/controller/UserController.java +++ b/src/main/java/side/onetime/controller/UserController.java @@ -41,4 +41,13 @@ public ResponseEntity> updateUserProfile( userService.updateUserProfile(authorizationHeader, updateUserProfileRequest); return ApiResponse.onSuccess(SuccessStatus._UPDATE_USER_PROFILE); } + + // 유저 서비스 탈퇴 API + @PostMapping("/action-withdraw") + public ResponseEntity> withdrawService( + @RequestHeader("Authorization") String authorizationHeader) { + + userService.withdrawService(authorizationHeader); + return ApiResponse.onSuccess(SuccessStatus._WITHDRAW_SERVICE); + } } \ No newline at end of file diff --git a/src/main/java/side/onetime/domain/User.java b/src/main/java/side/onetime/domain/User.java index 20f7091..6504cb1 100644 --- a/src/main/java/side/onetime/domain/User.java +++ b/src/main/java/side/onetime/domain/User.java @@ -37,6 +37,9 @@ public class User extends BaseEntity { @OneToMany(mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List selections; + @OneToMany(mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List eventParticipations; + @Builder public User(String name, String email, String nickname, String provider, String providerId) { this.name = name; diff --git a/src/main/java/side/onetime/dto/EventDto.java b/src/main/java/side/onetime/dto/EventDto.java index 721a1ad..c827a3f 100644 --- a/src/main/java/side/onetime/dto/EventDto.java +++ b/src/main/java/side/onetime/dto/EventDto.java @@ -9,7 +9,6 @@ import lombok.NoArgsConstructor; import side.onetime.domain.*; import side.onetime.global.common.constant.Category; -import side.onetime.util.DateUtil; import java.time.LocalTime; import java.util.ArrayList; @@ -169,7 +168,7 @@ public static GetUserParticipatedEventsResponse of(Event event, EventParticipati return GetUserParticipatedEventsResponse.builder() .eventId(event.getEventId()) .title(event.getTitle()) - .createdDate(DateUtil.formatDateToYearMonthDay(event.getCreatedDate())) + .createdDate(String.valueOf(event.getCreatedDate())) .participantCount(participantCount) .eventStatus(String.valueOf(eventParticipation.getEventStatus())) .build(); diff --git a/src/main/java/side/onetime/global/common/constant/SuccessStatus.java b/src/main/java/side/onetime/global/common/constant/SuccessStatus.java index bf60b1e..8d03d01 100644 --- a/src/main/java/side/onetime/global/common/constant/SuccessStatus.java +++ b/src/main/java/side/onetime/global/common/constant/SuccessStatus.java @@ -42,6 +42,7 @@ public enum SuccessStatus implements BaseCode { _ONBOARD_USER(HttpStatus.CREATED, "201", "유저 온보딩에 성공했습니다."), _GET_USER_PROFILE(HttpStatus.OK, "200", "유저 정보 조회에 성공했습니다."), _UPDATE_USER_PROFILE(HttpStatus.OK, "200", "유저 정보 수정에 성공했습니다."), + _WITHDRAW_SERVICE(HttpStatus.OK, "200", "유저 서비스 탈퇴에 성공했습니다."), ; private final HttpStatus httpStatus; diff --git a/src/main/java/side/onetime/service/UserService.java b/src/main/java/side/onetime/service/UserService.java index c13a207..3586cbd 100644 --- a/src/main/java/side/onetime/service/UserService.java +++ b/src/main/java/side/onetime/service/UserService.java @@ -87,4 +87,11 @@ public void updateUserProfile(String authorizationHeader, UserDto.UpdateUserProf user.updateNickName(nickname); userRepository.save(user); } + + // 유저 서비스 탈퇴 메서드 + @Transactional + public void withdrawService(String authorizationHeader) { + User user = jwtUtil.getUserFromHeader(authorizationHeader); + userRepository.delete(user); + } }