diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Category.java b/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Category.java index 57d45ad..765ef7d 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Category.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Category.java @@ -8,6 +8,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @AllArgsConstructor @@ -18,10 +21,18 @@ public class Category { private long id; private String name; private String colorCode; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId") private User user; + @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true) + private List doList = new ArrayList<>(); + + @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true) + private List planList = new ArrayList<>(); + + public Category(CategoryCreateDTO categoryCreateDTO, User user){ this.name = categoryCreateDTO.getName(); this.colorCode = categoryCreateDTO.getColorCode(); diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Plan.java b/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Plan.java index 3a5fe6c..556fb82 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Plan.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/domain/Plan.java @@ -18,17 +18,24 @@ public class Plan { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; + private String title; + private LocalTime startTime; + private LocalTime endTime; + private boolean status; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "categoryId") private Category category; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userDateId") private UserDate userDate; - @OneToMany(mappedBy = "plan", cascade = CascadeType.ALL) + + @OneToMany(mappedBy = "plan", cascade = CascadeType.ALL, orphanRemoval = true) private List cycle; public Plan(PlanCreateDTO planCreateDTO, UserDate userDate){ diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/domain/UserDate.java b/src/main/java/com/trendithon/timetris/domain/mainpage/domain/UserDate.java index dac6a43..37a441d 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/domain/UserDate.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/domain/UserDate.java @@ -8,6 +8,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @@ -17,13 +20,24 @@ public class UserDate { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userId") private User user; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "dateId") private Date date; + @OneToMany(mappedBy = "userDate", cascade = CascadeType.ALL, orphanRemoval = true) + private List doList = new ArrayList<>(); + + @OneToMany(mappedBy = "userDate", cascade = CascadeType.ALL, orphanRemoval = true) + private List planList = new ArrayList<>(); + + @OneToMany(mappedBy = "userDate", cascade = CascadeType.ALL, orphanRemoval = true) + private List seeList = new ArrayList<>(); + public UserDate(UserDateCreateDTO userDateCreateDTO){ this.user = userDateCreateDTO.getUser(); this.date = userDateCreateDTO.getDate(); diff --git a/src/main/java/com/trendithon/timetris/domain/member/controller/MyPageController.java b/src/main/java/com/trendithon/timetris/domain/member/controller/MyPageController.java index a4a41fb..6a7ba64 100644 --- a/src/main/java/com/trendithon/timetris/domain/member/controller/MyPageController.java +++ b/src/main/java/com/trendithon/timetris/domain/member/controller/MyPageController.java @@ -41,4 +41,12 @@ public ApiResponse updateName(@RequestBody UpdateNa return ApiResponse.success(SuccessStatus.OK, myPageDTO); } + + @PostMapping + @Operation(summary = "회원 탈퇴 API") + public ApiResponse userOutService(HttpServletRequest request) { + Long userId = tokenProvider.getUserId(request); + myPageService.deleteUser(userId); + return ApiResponse.success(SuccessStatus.DELETE_USER_SUCCESS); + } } diff --git a/src/main/java/com/trendithon/timetris/domain/member/domain/User.java b/src/main/java/com/trendithon/timetris/domain/member/domain/User.java index b28caf6..2039938 100644 --- a/src/main/java/com/trendithon/timetris/domain/member/domain/User.java +++ b/src/main/java/com/trendithon/timetris/domain/member/domain/User.java @@ -1,9 +1,14 @@ package com.trendithon.timetris.domain.member.domain; +import com.trendithon.timetris.domain.mainpage.domain.Category; +import com.trendithon.timetris.domain.mainpage.domain.UserDate; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.*; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @Builder @@ -31,6 +36,12 @@ public class User { private String refreshToken; + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) + private List categories = new ArrayList<>(); + + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) + private List userDateList = new ArrayList<>(); + public void changeNickname(String nickname) { this.nickname = nickname; } diff --git a/src/main/java/com/trendithon/timetris/domain/member/service/MyPageService.java b/src/main/java/com/trendithon/timetris/domain/member/service/MyPageService.java index ccebc21..5121ec9 100644 --- a/src/main/java/com/trendithon/timetris/domain/member/service/MyPageService.java +++ b/src/main/java/com/trendithon/timetris/domain/member/service/MyPageService.java @@ -4,8 +4,6 @@ import com.trendithon.timetris.domain.member.dto.MyPageResponse; import com.trendithon.timetris.domain.member.dto.UpdateNameRequest; import com.trendithon.timetris.domain.member.repository.UserRepository; -import com.trendithon.timetris.global.exception.CustomException; -import com.trendithon.timetris.global.exception.enums.ErrorStatus; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -41,5 +39,10 @@ public MyPageResponse.getMyPageDTO updateName(Long userId, UpdateNameRequest nam .build(); } + @Transactional + public void deleteUser(Long userId) { + userRepository.deleteById(userId); + + } } diff --git a/src/main/java/com/trendithon/timetris/global/auth/oauth/handler/OAuth2SuccessHandler.java b/src/main/java/com/trendithon/timetris/global/auth/oauth/handler/OAuth2SuccessHandler.java index 5e586f3..0b6be4f 100644 --- a/src/main/java/com/trendithon/timetris/global/auth/oauth/handler/OAuth2SuccessHandler.java +++ b/src/main/java/com/trendithon/timetris/global/auth/oauth/handler/OAuth2SuccessHandler.java @@ -12,7 +12,6 @@ import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.util.UriComponentsBuilder; import java.io.IOException; diff --git a/src/main/java/com/trendithon/timetris/global/exception/enums/SuccessStatus.java b/src/main/java/com/trendithon/timetris/global/exception/enums/SuccessStatus.java index 82771b2..9b43b97 100644 --- a/src/main/java/com/trendithon/timetris/global/exception/enums/SuccessStatus.java +++ b/src/main/java/com/trendithon/timetris/global/exception/enums/SuccessStatus.java @@ -12,7 +12,8 @@ public enum SuccessStatus { /** * 200 OK */ - OK(HttpStatus.OK, "COMMON200", "성공입니다."); + OK(HttpStatus.OK, "COMMON200", "성공입니다."), + DELETE_USER_SUCCESS(HttpStatus.OK, "USER200", "유저 탈퇴 성공입니다."); private final HttpStatus httpStatus; private final String code;