From 18c71232b1218ade940b9e896a81bb8f0a3ccb70 Mon Sep 17 00:00:00 2001 From: jiinkyung Date: Wed, 21 Feb 2024 10:35:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9BFix:=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timetris/domain/mainpage/domain/Category.java | 11 +++++++++++ .../timetris/domain/mainpage/domain/Plan.java | 9 ++++++++- .../timetris/domain/mainpage/domain/UserDate.java | 14 ++++++++++++++ .../timetris/domain/member/domain/User.java | 11 +++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) 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/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; } From 760cc3f35780391f06c274dc1e60e066a34d2af6 Mon Sep 17 00:00:00 2001 From: jiinkyung Date: Wed, 21 Feb 2024 10:36:59 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8Feat:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MyPageController.java | 8 ++++++++ .../timetris/domain/member/service/MyPageService.java | 7 +++++-- .../global/auth/oauth/handler/OAuth2SuccessHandler.java | 1 - .../timetris/global/exception/enums/SuccessStatus.java | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) 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/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;