Skip to content

Commit

Permalink
Merge pull request #59 from onetime-with-members/feature/#48/withdraw…
Browse files Browse the repository at this point in the history
…-service

[feat] : 유저는 서비스를 탈퇴할 수 있다
  • Loading branch information
bbbang105 authored Oct 1, 2024
2 parents 0628e3c + c5a3c1b commit 7d96142
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/side/onetime/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ public ResponseEntity<ApiResponse<SuccessStatus>> updateUserProfile(
userService.updateUserProfile(authorizationHeader, updateUserProfileRequest);
return ApiResponse.onSuccess(SuccessStatus._UPDATE_USER_PROFILE);
}

// 유저 서비스 탈퇴 API
@PostMapping("/action-withdraw")
public ResponseEntity<ApiResponse<SuccessStatus>> withdrawService(
@RequestHeader("Authorization") String authorizationHeader) {

userService.withdrawService(authorizationHeader);
return ApiResponse.onSuccess(SuccessStatus._WITHDRAW_SERVICE);
}
}
3 changes: 3 additions & 0 deletions src/main/java/side/onetime/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class User extends BaseEntity {
@OneToMany(mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Selection> selections;

@OneToMany(mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<EventParticipation> eventParticipations;

@Builder
public User(String name, String email, String nickname, String provider, String providerId) {
this.name = name;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/side/onetime/dto/EventDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/side/onetime/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7d96142

Please sign in to comment.