From 45bcebf6c8c377763b4a6c512430fca260b264a6 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 25 Aug 2024 22:24:44 +0900 Subject: [PATCH 01/18] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=20=EC=97=94=ED=8B=B0=ED=8B=B0=20delete=20cascade=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/entity/MissionPost.java | 5 +++++ .../domain/farmclub/entity/MissionPostComment.java | 4 ++++ .../domain/farmclub/entity/MissionPostLike.java | 5 +++++ .../domain/farmclub/entity/UserFarmClub.java | 5 +++++ .../domain/myveggiegarden/entity/Diary.java | 7 ++++++- .../domain/myveggiegarden/entity/DiaryComment.java | 1 + .../domain/myveggiegarden/entity/DiaryLike.java | 2 +- .../domain/myveggiegarden/entity/MyVeggie.java | 8 ++++++-- .../domain/myveggiegarden/entity/Routine.java | 6 +++--- .../farmusspring/domain/user/entity/User.java | 10 +++++++++- 10 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java index 07061178..36bbe7aa 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java @@ -4,6 +4,8 @@ import jakarta.persistence.*; import lombok.*; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.ArrayList; import java.util.List; @@ -29,14 +31,17 @@ public class MissionPost extends BaseEntity { @Column(nullable = false) private String image; + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL) @Builder.Default private List missionPostLikes = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL) @Builder.Default private List missionPostComments = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java index e40fce3c..684d0438 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java @@ -8,6 +8,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -24,10 +26,12 @@ public class MissionPostComment extends BaseEntity { @Column(nullable = false) private String comment; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "mission_post_id") private MissionPost missionPost; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java index 1b7eb034..db7ec478 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java @@ -8,6 +8,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -21,10 +23,13 @@ public class MissionPostLike extends BaseEntity { @Column(name = "mission_post_like_id") private Long id; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "mission_post_id") private MissionPost missionPost; + + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java index 95fc733f..29df1477 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java @@ -5,6 +5,8 @@ import jakarta.persistence.*; import lombok.*; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.ArrayList; import java.util.List; @@ -33,6 +35,7 @@ public class UserFarmClub extends BaseEntity { @Column(nullable = false) private boolean isComplete; + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "userFarmClub", cascade = CascadeType.REMOVE) @Builder.Default private List missionPosts = new ArrayList<>(); @@ -41,6 +44,8 @@ public class UserFarmClub extends BaseEntity { @JoinColumn(name = "farm_club_id") private FarmClub farmClub; + + @OnDelete(action = OnDeleteAction.CASCADE) @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java index d0b87381..17f7af20 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java @@ -6,7 +6,8 @@ import jakarta.persistence.*; import lombok.*; import lombok.experimental.SuperBuilder; - +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.ArrayList; @@ -37,14 +38,18 @@ public class Diary extends BaseEntity { @Column(name = "state") private String state; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaryComments = new ArrayList<>(); + + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaryLikes = new ArrayList<>(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java index 07a3db55..5673b417 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java @@ -34,6 +34,7 @@ public class DiaryComment extends BaseEntity { @JoinColumn(name = "diary_id") private Diary diary; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java index 029a988f..da9ced24 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java @@ -26,7 +26,7 @@ public class DiaryLike extends BaseEntity { @JoinColumn(name = "diary_id") private Diary diary; - + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java index d37ed14b..9ee19246 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java @@ -6,7 +6,8 @@ import jakarta.persistence.*; import lombok.*; import lombok.experimental.SuperBuilder; - +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.ArrayList; @@ -41,19 +42,22 @@ public class MyVeggie extends BaseEntity { @Column(name = "veggie_image") private String veggieImage; - + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List routines = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaries = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java index 9dc03173..e656ad3f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java @@ -8,7 +8,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; - +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.Date; @@ -39,7 +40,7 @@ public class Routine extends BaseEntity { @Column(name = "complete") private boolean complete; - + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; @@ -56,6 +57,5 @@ public static Routine createRoutine(Date date, String content, int period, MyVeg myVeggie.addRoutine(newRoutine); return newRoutine; - } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java index 702978d5..d342869e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java @@ -9,6 +9,8 @@ import jakarta.persistence.*; import lombok.*; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.time.LocalDateTime; @@ -49,31 +51,37 @@ public class User extends BaseEntity { @Column(nullable = false) private Boolean notificationStatus; - + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List userFirebaseTokens = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List userMotivations = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) @Builder.Default private List myVeggies = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) @Builder.Default private List diaryComments = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) @Builder.Default private List diaryLikes = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List missionPostComments = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @Builder.Default private List missionPostLikes = new ArrayList<>(); From 2468db1925c146240ed81a7edc925e766ca16e84 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 25 Aug 2024 22:36:34 +0900 Subject: [PATCH 02/18] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/repository/UserRepository.java | 3 ++ .../domain/user/service/UserService.java | 34 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java index 259eb563..b8b2cb8b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java @@ -15,6 +15,9 @@ public interface UserRepository extends JpaRepository { Optional findByUserNumber(String usernumber); + + @Query("SELECT a FROM user AS a WHERE a.id = :userId") + Optional findUser(@Param("userId") Long userId); @Query("SELECT a FROM user AS a WHERE a.id = :userId") User findUserData(@Param("userId") Long userId); User findUserById(Long userId); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 389b7ffb..bd59cc2b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -35,11 +35,8 @@ public class UserService { @Transactional public BaseResponseDto selectUserProfile(Long userId) { - Optional userData = selectUser(userId); - long dDay = calFromToday(userData.get().getCreatedDate()); - return BaseResponseDto.of(SuccessCode.SUCCESS, UserProfileResponse.of( userData.get().getNickname(), @@ -48,6 +45,33 @@ public BaseResponseDto selectUserProfile(Long userId) { )); } + @Transactional + public BaseResponseDto deleteUser(Long userId) { + Optional user = userRepository.findUser(userId); + // 유저 검증 + + // 유저 도메인 정보 삭제 + // 1.1 유저 id를 통한 성장일기 좋아요 삭제 + // 1.2 유저 id를 통한 성장일기 댓글 삭제 + // 1.3 유저 id를 통한 인증글 좋아요 삭제 + // 1.4 유저 id를 통한 인증글 댓글 삭제 + + + // 채소 도메인 정보 삭제 + // 유저 id를 통한 내 채소 삭제 + + + + // 팜클럽 도메인 정보 삭제 + // 내 채소 id를 통한 유저 팜클럽 삭제 + + + + return null; + } + + + @Transactional public BaseResponseDto deleteProfleImage(Long userId) { updateProfileImage(userId); @@ -129,7 +153,6 @@ public Optional selectUser(Long userId){ return user; } private long calFromToday(LocalDateTime date){ - LocalDateTime currentDateTime = LocalDateTime.now(); long daysDifference = ChronoUnit.DAYS.between(date.toLocalDate(), currentDateTime.toLocalDate()); return daysDifference; @@ -140,4 +163,7 @@ private void updateProfileImage(Long userId){ } + + + } From 9272887d6557c6ee5eb5ee1ecab1efc41112040e Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 25 Aug 2024 22:36:39 +0900 Subject: [PATCH 03/18] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/user/controller/UserController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java index f48910a5..b0d6856c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java @@ -32,6 +32,11 @@ public BaseResponseDto selectUserProfile(@AuthenticationPri return userService.selectUserProfile(user.getUserId()); } + @DeleteMapping() + public BaseResponseDto deleteUser(@AuthenticationPrincipal CustomUser user) { + return userService.selectUserProfile(user.getUserId()); + } + @PatchMapping(value = "/profile-image") public BaseResponseDto deleteProfleImage(@AuthenticationPrincipal CustomUser user) { From 537c0a7333db17057b804f408cde7525813f1451 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 25 Aug 2024 22:41:52 +0900 Subject: [PATCH 04/18] =?UTF-8?q?[feat]=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=EB=B3=84=20cascade=20=EC=82=AD=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/entity/MissionPostComment.java | 1 - .../domain/farmclub/entity/MissionPostLike.java | 2 +- .../farmusspring/domain/farmclub/entity/UserFarmClub.java | 1 - .../domain/myveggiegarden/entity/DiaryComment.java | 1 - .../domain/myveggiegarden/entity/DiaryLike.java | 1 - .../domain/myveggiegarden/entity/MyVeggie.java | 3 +-- .../farmusspring/domain/user/entity/User.java | 8 +++----- 7 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java index 684d0438..585cf26e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostComment.java @@ -31,7 +31,6 @@ public class MissionPostComment extends BaseEntity { @JoinColumn(name = "mission_post_id") private MissionPost missionPost; - @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java index db7ec478..d2f427f7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostLike.java @@ -29,7 +29,7 @@ public class MissionPostLike extends BaseEntity { private MissionPost missionPost; - @OnDelete(action = OnDeleteAction.CASCADE) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java index 29df1477..093e84b7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java @@ -45,7 +45,6 @@ public class UserFarmClub extends BaseEntity { private FarmClub farmClub; - @OnDelete(action = OnDeleteAction.CASCADE) @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java index 5673b417..07a3db55 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryComment.java @@ -34,7 +34,6 @@ public class DiaryComment extends BaseEntity { @JoinColumn(name = "diary_id") private Diary diary; - @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java index da9ced24..24f7856b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/DiaryLike.java @@ -26,7 +26,6 @@ public class DiaryLike extends BaseEntity { @JoinColumn(name = "diary_id") private Diary diary; - @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java index 9ee19246..bcde0f4d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java @@ -42,7 +42,6 @@ public class MyVeggie extends BaseEntity { @Column(name = "veggie_image") private String veggieImage; - @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; @@ -57,7 +56,7 @@ public class MyVeggie extends BaseEntity { @Builder.Default private List diaries = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java index d342869e..f2917af3 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java @@ -61,27 +61,25 @@ public class User extends BaseEntity { @Builder.Default private List userMotivations = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) @Builder.Default private List myVeggies = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) @Builder.Default private List diaryComments = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) @Builder.Default private List diaryLikes = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List missionPostComments = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) @Builder.Default private List missionPostLikes = new ArrayList<>(); From 657cc2ccdf207a7e86f11184861113109ffa7d5e Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 25 Aug 2024 22:53:26 +0900 Subject: [PATCH 05/18] =?UTF-8?q?[feat]=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=EB=B3=84=20cascade=20=EC=82=AD=EC=A0=9C=20=EB=B0=98=EB=8C=80?= =?UTF-8?q?=20=EA=B4=80=EA=B3=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/entity/MissionPost.java | 4 ++-- .../farmusspring/domain/farmclub/entity/UserFarmClub.java | 2 +- .../farmusspring/domain/myveggiegarden/entity/Diary.java | 4 ++-- .../farmusspring/domain/myveggiegarden/entity/MyVeggie.java | 4 ++-- .../modernfarmer/farmusspring/domain/user/entity/User.java | 3 +-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java index 36bbe7aa..218ad79c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java @@ -31,16 +31,16 @@ public class MissionPost extends BaseEntity { @Column(nullable = false) private String image; - @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL) @Builder.Default private List missionPostLikes = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL) @Builder.Default private List missionPostComments = new ArrayList<>(); + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_farm_club_id") diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java index 093e84b7..c365f077 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java @@ -35,7 +35,7 @@ public class UserFarmClub extends BaseEntity { @Column(nullable = false) private boolean isComplete; - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "userFarmClub", cascade = CascadeType.REMOVE) @Builder.Default private List missionPosts = new ArrayList<>(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java index 17f7af20..1bb35a42 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Diary.java @@ -43,13 +43,13 @@ public class Diary extends BaseEntity { @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaryComments = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaryLikes = new ArrayList<>(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java index bcde0f4d..8a46b45a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java @@ -46,12 +46,12 @@ public class MyVeggie extends BaseEntity { @JoinColumn(name = "user_id") private User user; - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List routines = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaries = new ArrayList<>(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java index f2917af3..8d791cc1 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java @@ -51,12 +51,11 @@ public class User extends BaseEntity { @Column(nullable = false) private Boolean notificationStatus; - @OnDelete(action = OnDeleteAction.CASCADE) @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List userFirebaseTokens = new ArrayList<>(); - @OnDelete(action = OnDeleteAction.CASCADE) + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List userMotivations = new ArrayList<>(); From f8ef44457cfb7897d0e4530d3ea695f04a971349 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 00:27:33 +0900 Subject: [PATCH 06/18] =?UTF-8?q?[feat]=20User=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=97=90=EB=9F=AC=20=ED=98=95=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/exception/custom/UserBaseException.java | 15 +++++++++++++++ .../exception/custom/UserNotFoundException.java | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserBaseException.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserBaseException.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserBaseException.java new file mode 100644 index 00000000..2f3d0de7 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserBaseException.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.user.exception.custom; + +import com.modernfarmer.farmusspring.domain.user.exception.UserErrorCode; +import lombok.Getter; + +@Getter +public class UserBaseException extends RuntimeException{ + + private final UserErrorCode errorCode; + public UserBaseException(String message, UserErrorCode errorCode) { + super(message); + this.errorCode = errorCode; + } + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java new file mode 100644 index 00000000..febb7a04 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java @@ -0,0 +1,12 @@ +package com.modernfarmer.farmusspring.domain.user.exception.custom; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.MyVeggieGardenBaseException; + +public class UserNotFoundException extends MyVeggieGardenBaseException { + + public UserNotFoundException(String message, MyVeggieGardenErrorCode errorCode) { + super(message, errorCode); + } + +} From a78de1db2b06dd3ae0331059b38f6441f0594be7 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 00:42:39 +0900 Subject: [PATCH 07/18] =?UTF-8?q?[feat]=20User=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=97=90=EB=9F=AC=20=ED=98=95=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/exception/AuthExceptionHandler.java | 1 - .../domain/auth/util/social/SocialLogin.java | 5 ++--- .../user/exception/UserExceptionHandler.java | 16 ++++++++-------- .../user/exception/UserNotFoundException.java | 8 -------- .../exception/custom/UserNotFoundException.java | 5 +++-- .../user/service/FirebaseTokenService.java | 9 +++------ .../domain/user/service/OnBoardingService.java | 7 +++---- 7 files changed, 19 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserNotFoundException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/exception/AuthExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/exception/AuthExceptionHandler.java index 26ed5de5..b9287321 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/exception/AuthExceptionHandler.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/exception/AuthExceptionHandler.java @@ -1,7 +1,6 @@ package com.modernfarmer.farmusspring.domain.auth.exception; import com.modernfarmer.farmusspring.domain.test.exception.TestException; -import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java index acebbd18..80c99f49 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/auth/util/social/SocialLogin.java @@ -4,7 +4,7 @@ import com.modernfarmer.farmusspring.domain.auth.repository.RedisManager; import com.modernfarmer.farmusspring.domain.auth.util.social.dto.SocialUserResponseDto; import com.modernfarmer.farmusspring.domain.user.entity.User; -import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.exception.custom.UserNotFoundException; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import com.modernfarmer.farmusspring.global.common.security.JwtTokenProvider; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -13,7 +13,6 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -44,7 +43,7 @@ public LoginResponseDto login(SocialUserResponseDto socialUserData){ return null; }); - Optional userLoginData = Optional.ofNullable(userRepository.findByUserNumber(String.valueOf(socialUserData.getId())).orElseThrow(() -> new UserNotFoundException("해당 유저의 정보가 존재하지 않습니다."))); + Optional userLoginData = Optional.ofNullable(userRepository.findByUserNumber(String.valueOf(socialUserData.getId())).orElseThrow(() -> new UserNotFoundException("해당 유저의 정보가 존재하지 않습니다.", UserErrorCode.NOT_FOUND_USER))); String refreshToken = jwtTokenProvider.createRefreshToken(userLoginData.get().getId()); String accessToken = jwtTokenProvider.createAccessToken( diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserExceptionHandler.java index abfbf0b3..77018ed6 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserExceptionHandler.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserExceptionHandler.java @@ -11,12 +11,12 @@ @RestControllerAdvice(basePackages = "com.modernfarmer.farmusspring.domain.test") public class UserExceptionHandler { - @ExceptionHandler(UserNotFoundException.class) - public BaseResponseDto handleUserNotFoundException(TestException e, HttpServletRequest request) { - log.error("UserException : {} {} errMessage={}\n", - request.getMethod(), - request.getRequestURI(), - e.getMessage()); - return BaseResponseDto.of(UserErrorCode.NOT_FOUND_USER, e); - } +// @ExceptionHandler(UserNotFoundException.class) +// public BaseResponseDto handleUserNotFoundException(TestException e, HttpServletRequest request) { +// log.error("UserException : {} {} errMessage={}\n", +// request.getMethod(), +// request.getRequestURI(), +// e.getMessage()); +// return BaseResponseDto.of(UserErrorCode.NOT_FOUND_USER, e); +// } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserNotFoundException.java deleted file mode 100644 index 7065c5eb..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/UserNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.modernfarmer.farmusspring.domain.user.exception; - -public class UserNotFoundException extends RuntimeException { - - public UserNotFoundException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java index febb7a04..c8f78d6d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/exception/custom/UserNotFoundException.java @@ -2,10 +2,11 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.custom.MyVeggieGardenBaseException; +import com.modernfarmer.farmusspring.domain.user.exception.UserErrorCode; -public class UserNotFoundException extends MyVeggieGardenBaseException { +public class UserNotFoundException extends UserBaseException { - public UserNotFoundException(String message, MyVeggieGardenErrorCode errorCode) { + public UserNotFoundException(String message, UserErrorCode errorCode) { super(message, errorCode); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/FirebaseTokenService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/FirebaseTokenService.java index 30bf4c48..3228f592 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/FirebaseTokenService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/FirebaseTokenService.java @@ -1,11 +1,10 @@ package com.modernfarmer.farmusspring.domain.user.service; -import com.modernfarmer.farmusspring.domain.user.dto.request.SetLevelRequest; -import com.modernfarmer.farmusspring.domain.user.dto.request.SetMotivationRequest; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.domain.user.entity.UserFirebaseToken; -import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.exception.UserErrorCode; +import com.modernfarmer.farmusspring.domain.user.exception.custom.UserNotFoundException; import com.modernfarmer.farmusspring.domain.user.repository.FirebaseTokenRepository; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import lombok.AllArgsConstructor; @@ -13,8 +12,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; - @Slf4j @AllArgsConstructor @@ -40,7 +37,7 @@ public void addFirebaseToken(Long userId, String firebaseToken){ public void validateUser(User user){ if(user == null) - throw new UserNotFoundException("해당 유저는 존재하지 않습니다."); + throw new UserNotFoundException("해당 유저는 존재하지 않습니다.", UserErrorCode.NOT_FOUND_USER); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/OnBoardingService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/OnBoardingService.java index 4547839c..7fa74570 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/OnBoardingService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/OnBoardingService.java @@ -7,7 +7,8 @@ import com.modernfarmer.farmusspring.domain.user.dto.response.SetLevelResponse; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.domain.user.entity.UserMotivation; -import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.exception.UserErrorCode; +import com.modernfarmer.farmusspring.domain.user.exception.custom.UserNotFoundException; import com.modernfarmer.farmusspring.domain.user.repository.UserMotivationRepository; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import com.modernfarmer.farmusspring.domain.user.util.EncouragementMessages; @@ -17,11 +18,9 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.Optional; @Slf4j @AllArgsConstructor @@ -107,7 +106,7 @@ private String measureLevel(int time,String skill) { return "알 수 없음"; } public User findUser(Long userId) { - return userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("해당 유저가 없습니다.")); + return userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("해당 유저가 없습니다.", UserErrorCode.NOT_FOUND_USER)); } } From fc57d300ed819afb7af46707f518222b29261f71 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 00:42:51 +0900 Subject: [PATCH 08/18] =?UTF-8?q?[feat]=20User=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 2 +- .../domain/user/helper/UserHelper.java | 9 ++++-- .../user/repository/UserRepository.java | 4 +++ .../domain/user/service/UserService.java | 28 +++++++++++++------ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java index b0d6856c..c998861a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java @@ -34,7 +34,7 @@ public BaseResponseDto selectUserProfile(@AuthenticationPri @DeleteMapping() public BaseResponseDto deleteUser(@AuthenticationPrincipal CustomUser user) { - return userService.selectUserProfile(user.getUserId()); + return userService.deleteUser(user.getUserId()); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java index 9529e5f2..41c4bcad 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java @@ -1,7 +1,8 @@ package com.modernfarmer.farmusspring.domain.user.helper; import com.modernfarmer.farmusspring.domain.user.entity.User; -import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.exception.UserErrorCode; +import com.modernfarmer.farmusspring.domain.user.exception.custom.UserNotFoundException; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,9 +15,13 @@ public class UserHelper { private final UserRepository userRepository; + public void deleteUser(Long userId){ + userRepository.deleteUser(userId); + } + public User getUserEntity(Long userId) { return userRepository.findById(userId) - .orElseThrow(() -> new UserNotFoundException("해당 유저가 존재하지 않습니다.")); + .orElseThrow(() -> new UserNotFoundException("해당 유저가 존재하지 않습니다.", UserErrorCode.NOT_FOUND_USER)); } public String getUserLevel(Long userId) { diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java index b8b2cb8b..84372020 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java @@ -40,5 +40,9 @@ public interface UserRepository extends JpaRepository { @Query("update user as u set u.nickname = :nickName where u.id = :userId") void updateNickname(@Param("userId") Long userId, @Param("nickName") String nickName); + @Modifying + @Query("delete from user as u where u.id = :userId") + void deleteUser(@Param("userId") Long userId); + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index bd59cc2b..f62f07c3 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -1,20 +1,17 @@ package com.modernfarmer.farmusspring.domain.user.service; -import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; -import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; -import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.DiaryNotFoundException; import com.modernfarmer.farmusspring.domain.user.dto.response.AlarmStatus; import com.modernfarmer.farmusspring.domain.user.dto.response.UserProfileResponse; import com.modernfarmer.farmusspring.domain.user.entity.User; -import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.exception.UserErrorCode; +import com.modernfarmer.farmusspring.domain.user.exception.custom.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.helper.UserHelper; import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; -import com.modernfarmer.farmusspring.infra.s3.S3Config; import com.modernfarmer.farmusspring.infra.s3.S3Service; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -23,7 +20,6 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.Optional; -import java.util.Random; @Slf4j @AllArgsConstructor @@ -32,6 +28,7 @@ public class UserService { private final UserRepository userRepository; private final S3Service s3Service; + private final UserHelper userHelper; @Transactional public BaseResponseDto selectUserProfile(Long userId) { @@ -49,8 +46,13 @@ public BaseResponseDto selectUserProfile(Long userId) { public BaseResponseDto deleteUser(Long userId) { Optional user = userRepository.findUser(userId); // 유저 검증 + verifyUser(user); + + // 유저 도메인 정보 삭제 + // 1.0 유저 도메인 삭제 + userHelper.deleteUser(userId); // 1.1 유저 id를 통한 성장일기 좋아요 삭제 // 1.2 유저 id를 통한 성장일기 댓글 삭제 // 1.3 유저 id를 통한 인증글 좋아요 삭제 @@ -96,10 +98,12 @@ public User selectUserById(Long userId){ public void checkUserData(User user){ if(user == null) { - throw new UserNotFoundException("유저를 찾을 수 없습니다."); + throw new UserNotFoundException("해당 유저가 존재하지 않습니다.",UserErrorCode.NOT_FOUND_USER); } } + + @Transactional public void initUser(Long userId) { User user = userRepository.findUserById(userId); @@ -149,9 +153,15 @@ private void updateProfileAndNickname(Long userId, String imageUrl, String nickn } public Optional selectUser(Long userId){ - Optional user = Optional.ofNullable(userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("해당 유저가 존재하지 않습니다."))); + Optional user = Optional.ofNullable(userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("해당 유저가 존재하지 않습니다.",UserErrorCode.NOT_FOUND_USER))); return user; } + + public void verifyUser(Optional user){ + if(user.isEmpty()) + throw new UserNotFoundException("유저가 존재하지 않습니다.", UserErrorCode.NOT_FOUND_USER); + + } private long calFromToday(LocalDateTime date){ LocalDateTime currentDateTime = LocalDateTime.now(); long daysDifference = ChronoUnit.DAYS.between(date.toLocalDate(), currentDateTime.toLocalDate()); From 84e9f3050cc986664d439fb93e98c821d576b057 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 01:34:30 +0900 Subject: [PATCH 09/18] =?UTF-8?q?[feat]=20Like,=20Comment=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/DiaryCommentHelper.java | 19 ++++++++++++ .../helper/DiaryLikeHelper.java | 19 ++++++++++++ .../myveggiegarden/helper/MyVeggieHelper.java | 6 ++++ .../repository/DiaryCommentRepository.java | 6 ++++ .../repository/DiaryLikeRepository.java | 5 ++++ .../repository/MyVeggieRepository.java | 4 +++ .../domain/user/service/UserService.java | 29 +++++++++++++++---- 7 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java new file mode 100644 index 00000000..13f8f019 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java @@ -0,0 +1,19 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.helper; + + +import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.DiaryCommentRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +@RequiredArgsConstructor +public class DiaryCommentHelper { + + private final DiaryCommentRepository diaryCommentRepository; + + public void deleteCommentsByUserId(Long userId){ + diaryCommentRepository.deleteDiaryCommentsByUserId(userId); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java new file mode 100644 index 00000000..1d954766 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java @@ -0,0 +1,19 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.helper; + + +import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.DiaryLikeRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +@RequiredArgsConstructor +public class DiaryLikeHelper { + + private final DiaryLikeRepository diaryLikeRepository; + + public void deleteLikesByUserId(Long userId){ + diaryLikeRepository.deleteDiaryLikesByUserId(userId); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java index f2f51e65..f579e208 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java @@ -8,6 +8,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.vo.MyVeggieVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Component; import java.util.List; @@ -40,6 +41,11 @@ public void deleteMyVeggie(Long id) { myVeggieRepository.deleteById(id); } + public void deleteMyVeggiesByUserId(Long userId){ + myVeggieRepository.deleteMyVeggiesByUserId(userId); + } + + public List getDiariesByMyVeggie(MyVeggie myVeggie) { return myVeggieRepository.findDiariesByMyVeggie(myVeggie); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryCommentRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryCommentRepository.java index 54ee0947..ff59c36c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryCommentRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryCommentRepository.java @@ -3,6 +3,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryComment; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -13,4 +14,9 @@ public interface DiaryCommentRepository extends JpaRepository { @Query("SELECT count(dc) FROM diary_comment AS dc WHERE dc.diary.id = :diaryId ") int findDiaryCommentCountById(@Param("diaryId") Long diaryId); + + + @Modifying + @Query("delete from diary_comment as dc where dc.user.id = :userId") + void deleteDiaryCommentsByUserId(@Param("userId") Long userId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryLikeRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryLikeRepository.java index 92211860..3f1bc681 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryLikeRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryLikeRepository.java @@ -4,6 +4,7 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryComment; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.DiaryLike; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @@ -20,4 +21,8 @@ public interface DiaryLikeRepository extends JpaRepository { Optional findDiaryLikeByDiaryIdAndUserId(@Param("diaryId") Long diaryId, @Param("userId") Long userId); + @Modifying + @Query("delete from diary_like as dl where dl.user.id = :userId") + void deleteDiaryLikesByUserId(@Param("userId") Long userId); + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java index dd1d6725..8d77a837 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java @@ -74,6 +74,10 @@ void updateMyVeggie(@Param("myVeggieId") Long myVeggieId, @Query("UPDATE routine AS r SET r.date = :date WHERE r.id = :routineId") void updateRoutinePeriod(@Param("routineId") Long routineId, @Param("date") Date date); + @Modifying + @Query("delete from my_veggie as mv where mv.user.id = :userId") + void deleteMyVeggiesByUserId(@Param("userId") Long userId); + @Query("SELECT mv FROM my_veggie AS mv " + "LEFT JOIN mv.routines AS r " + "WHERE mv.user= :user " diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index f62f07c3..85721506 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -1,5 +1,8 @@ package com.modernfarmer.farmusspring.domain.user.service; +import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryCommentHelper; +import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryLikeHelper; +import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.MyVeggieHelper; import com.modernfarmer.farmusspring.domain.user.dto.response.AlarmStatus; import com.modernfarmer.farmusspring.domain.user.dto.response.UserProfileResponse; import com.modernfarmer.farmusspring.domain.user.entity.User; @@ -29,6 +32,9 @@ public class UserService { private final UserRepository userRepository; private final S3Service s3Service; private final UserHelper userHelper; + private final DiaryCommentHelper diaryCommentHelper; + private final DiaryLikeHelper diaryLikeHelper; + private MyVeggieHelper myVeggieHelper; @Transactional public BaseResponseDto selectUserProfile(Long userId) { @@ -48,24 +54,35 @@ public BaseResponseDto deleteUser(Long userId) { // 유저 검증 verifyUser(user); + // 팜클럽 도메인 정보 삭제 + // 유저의 채소 엔티티 조회 + + // 내 채소 id를 통한 유저 팜클럽 삭제 + // 채소 도메인 정보 삭제 + // 유저 id를 통한 내 채소 삭제 + myVeggieHelper.deleteMyVeggiesByUserId(userId); // 유저 도메인 정보 삭제 - // 1.0 유저 도메인 삭제 - userHelper.deleteUser(userId); // 1.1 유저 id를 통한 성장일기 좋아요 삭제 + diaryLikeHelper.deleteLikesByUserId(userId); // 1.2 유저 id를 통한 성장일기 댓글 삭제 + diaryCommentHelper.deleteCommentsByUserId(userId); // 1.3 유저 id를 통한 인증글 좋아요 삭제 // 1.4 유저 id를 통한 인증글 댓글 삭제 - // 채소 도메인 정보 삭제 - // 유저 id를 통한 내 채소 삭제 + // 1.0 유저 도메인 삭제 + userHelper.deleteUser(userId); + + + + + + - // 팜클럽 도메인 정보 삭제 - // 내 채소 id를 통한 유저 팜클럽 삭제 From a638a80da59624340433746a53242e1644c32bd6 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 01:47:08 +0900 Subject: [PATCH 10/18] =?UTF-8?q?[feat]=20=EB=82=B4=20=EC=B1=84=EC=86=8C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/helper/MyVeggieHelper.java | 4 ++++ .../farmusspring/domain/user/service/UserService.java | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java index f579e208..603d3adc 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/MyVeggieHelper.java @@ -25,6 +25,10 @@ public MyVeggie getMyVeggieEntity(Long id) { new MyVeggieGardenBaseException("존재하지 않는 나의 채소입니다.", MyVeggieGardenErrorCode.NOT_FOUND_VEGGIE)); } + public List getMyVeggieUserId(Long userId){ + return myVeggieRepository.findMyVeggieUserId(userId); + } + public MyVeggieVo getMyVeggieInfo(Long userId, String veggieInfoId) { return myVeggieRepository.findMyVeggieInfo(userId, veggieInfoId).orElse(MyVeggieVo.of(0L, "", "")); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 85721506..6071a69e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -1,5 +1,6 @@ package com.modernfarmer.farmusspring.domain.user.service; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryCommentHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryLikeHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.MyVeggieHelper; @@ -22,6 +23,7 @@ import java.io.IOException; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; +import java.util.List; import java.util.Optional; @Slf4j @@ -56,9 +58,10 @@ public BaseResponseDto deleteUser(Long userId) { // 팜클럽 도메인 정보 삭제 // 유저의 채소 엔티티 조회 - + List myVeggieList = myVeggieHelper.getMyVeggieUserId(userId); // 내 채소 id를 통한 유저 팜클럽 삭제 + // 채소 도메인 정보 삭제 // 유저 id를 통한 내 채소 삭제 myVeggieHelper.deleteMyVeggiesByUserId(userId); From 0897e974f436f8944dbfa630f1167590b58cb173 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 11:18:52 +0900 Subject: [PATCH 11/18] =?UTF-8?q?[feat]=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EB=8C=93=EA=B8=80,=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/helper/MissionPostHelper.java | 7 +++++++ .../repository/MissionPostRepositoryCustom.java | 3 +++ .../repository/MissionPostRepositoryImpl.java | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java index 3fcef57e..99c82479 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java @@ -40,4 +40,11 @@ public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId public void deleteMissionPostLike(Long userId, Long missionPostId) { missionPostRepository.deleteMissionPostLike(userId, missionPostId); } + + public void deleteMissionPostComments(Long userId){ + missionPostRepository.deleteMissionPostComments(userId); + } + public void deleteMissionPostLikes(Long userId){ + missionPostRepository.deleteMissionPostLikes(userId); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java index 1b1d5c8c..3039964e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java @@ -16,4 +16,7 @@ public interface MissionPostRepositoryCustom { List getMissionPostList(Long userId, Long missionPostId); List getMissionPostHistory(Long missionPostId); void deleteMissionPostLike(Long userId, Long missionPostId); + void deleteMissionPostComments(Long userId); + void deleteMissionPostLikes(Long userId); + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java index 6e10c371..6c8d3c03 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java @@ -112,4 +112,20 @@ public void deleteMissionPostLike(Long userId, Long missionPostId) { .and(missionPostLike.missionPost.id.eq(missionPostId))) .execute(); } + + @Override + public void deleteMissionPostComments(Long userId){ + queryFactory + .delete(missionPostComment) + .where(missionPostComment.user.id.eq(userId)) + .execute(); + } + + @Override + public void deleteMissionPostLikes(Long userId){ + queryFactory + .delete(missionPostLike) + .where(missionPostLike.user.id.eq(userId)) + .execute(); + } } From 518667f10da3a5f0ad4135a888f51eda9ca8842e Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 11:19:34 +0900 Subject: [PATCH 12/18] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=EC=9D=98=20?= =?UTF-8?q?=ED=8C=9C=ED=81=B4=EB=9F=BD=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/helper/FarmClubHelper.java | 5 +++++ .../repository/UserFarmClubRepositoryCustom.java | 3 +++ .../repository/UserFarmClubRepositoryImpl.java | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java index 89fd9af7..66adb465 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java @@ -10,6 +10,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; import com.modernfarmer.farmusspring.domain.farmclub.repository.UserFarmClubRepository; import com.modernfarmer.farmusspring.domain.history.vo.HistoryDetailVo; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -48,4 +49,8 @@ public List getRecommendedFarmClubList(String level) { public List findFarmClubIdsByUserId(Long userId) { return userFarmClubRepository.findFarmClubIdsByUserId(userId); } + + public void deleteFarmClubDomain(List myVeggieList){ + userFarmClubRepository.deleteFarmClubDomain(myVeggieList); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java index 3031fa84..b02fa784 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryCustom.java @@ -2,6 +2,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.vo.SuccessFarmClubVo; import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import java.util.List; import java.util.Optional; @@ -12,4 +13,6 @@ public interface UserFarmClubRepositoryCustom { List findFarmClubIdsByUserId(Long userId); SuccessFarmClubVo getFarmClubRecord(Long userId, Long farmClubId); + + void deleteFarmClubDomain(List myVeggieList); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java index 4e2cf225..0d46b101 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepositoryImpl.java @@ -2,6 +2,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.vo.SuccessFarmClubVo; import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -55,4 +56,13 @@ public SuccessFarmClubVo getFarmClubRecord(Long userId, Long farmClubId) { .where(userFarmClub.farmClub.id.eq(farmClubId).and(userFarmClub.userId.eq(userId))) .fetchOne(); } + + + @Override + public void deleteFarmClubDomain(List myVeggieList){ + queryFactory + .delete(userFarmClub) + .where(userFarmClub.myVeggie.id.in(myVeggieList.stream().map(MyVeggie::getId).toList())) + .execute(); + } } From 781e7a5437b219d1d2fa65a2b5e246c7498dda8b Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 11:20:08 +0900 Subject: [PATCH 13/18] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=B0=20=EC=A2=8B=EC=95=84=EC=9A=94,=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=ED=95=A8=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/helper/DiaryCommentHelper.java | 2 +- .../domain/myveggiegarden/helper/DiaryLikeHelper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java index 13f8f019..a51f2b3f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryCommentHelper.java @@ -13,7 +13,7 @@ public class DiaryCommentHelper { private final DiaryCommentRepository diaryCommentRepository; - public void deleteCommentsByUserId(Long userId){ + public void deleteComments(Long userId){ diaryCommentRepository.deleteDiaryCommentsByUserId(userId); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java index 1d954766..aa70bd88 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/helper/DiaryLikeHelper.java @@ -13,7 +13,7 @@ public class DiaryLikeHelper { private final DiaryLikeRepository diaryLikeRepository; - public void deleteLikesByUserId(Long userId){ + public void deleteLikes(Long userId){ diaryLikeRepository.deleteDiaryLikesByUserId(userId); } } From 5cdacaa9d6ace9ecf0dadc62975fa21dfea04b6c Mon Sep 17 00:00:00 2001 From: seungryeol Date: Mon, 26 Aug 2024 11:20:29 +0900 Subject: [PATCH 14/18] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 3 +- .../domain/user/service/UserService.java | 30 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java index c998861a..fb83b071 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java @@ -34,7 +34,8 @@ public BaseResponseDto selectUserProfile(@AuthenticationPri @DeleteMapping() public BaseResponseDto deleteUser(@AuthenticationPrincipal CustomUser user) { - return userService.deleteUser(user.getUserId()); + userService.deleteUser(user.getUserId()); + return BaseResponseDto.of(SuccessCode.SUCCESS, null); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 6071a69e..62e2ed7d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -1,5 +1,7 @@ package com.modernfarmer.farmusspring.domain.user.service; +import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; +import com.modernfarmer.farmusspring.domain.farmclub.helper.MissionPostHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryCommentHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryLikeHelper; @@ -36,7 +38,9 @@ public class UserService { private final UserHelper userHelper; private final DiaryCommentHelper diaryCommentHelper; private final DiaryLikeHelper diaryLikeHelper; - private MyVeggieHelper myVeggieHelper; + private final MyVeggieHelper myVeggieHelper; + private final FarmClubHelper farmClubHelper; + private final MissionPostHelper missionPostHelper; @Transactional public BaseResponseDto selectUserProfile(Long userId) { @@ -51,7 +55,7 @@ public BaseResponseDto selectUserProfile(Long userId) { } @Transactional - public BaseResponseDto deleteUser(Long userId) { + public void deleteUser(Long userId) { Optional user = userRepository.findUser(userId); // 유저 검증 verifyUser(user); @@ -60,7 +64,7 @@ public BaseResponseDto deleteUser(Long userId) { // 유저의 채소 엔티티 조회 List myVeggieList = myVeggieHelper.getMyVeggieUserId(userId); // 내 채소 id를 통한 유저 팜클럽 삭제 - + farmClubHelper.deleteFarmClubDomain(myVeggieList); // 채소 도메인 정보 삭제 // 유저 id를 통한 내 채소 삭제 @@ -68,28 +72,16 @@ public BaseResponseDto deleteUser(Long userId) { // 유저 도메인 정보 삭제 // 1.1 유저 id를 통한 성장일기 좋아요 삭제 - diaryLikeHelper.deleteLikesByUserId(userId); + diaryLikeHelper.deleteLikes(userId); // 1.2 유저 id를 통한 성장일기 댓글 삭제 - diaryCommentHelper.deleteCommentsByUserId(userId); + diaryCommentHelper.deleteComments(userId); // 1.3 유저 id를 통한 인증글 좋아요 삭제 + missionPostHelper.deleteMissionPostLikes(userId); // 1.4 유저 id를 통한 인증글 댓글 삭제 - + missionPostHelper.deleteMissionPostComments(userId); // 1.0 유저 도메인 삭제 userHelper.deleteUser(userId); - - - - - - - - - - - - - return null; } From bb2a75af28fe5bb99c9c92c72dff456a664ee348 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Wed, 28 Aug 2024 01:52:21 +0900 Subject: [PATCH 15/18] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20id=EC=97=90?= =?UTF-8?q?=20=EB=94=B0=EB=A5=B8=20=ED=9E=88=EC=8A=A4=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A9=94=EC=84=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/history/helper/HistoryHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java index b9f30f66..d0f9c9fa 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java @@ -50,6 +50,11 @@ public void createUserHistory(Long userId) { historyRepository.save(history); } + public void deleteHistory(Long userId) { + History history = getUserHistory(userId); + historyRepository.delete(history); + } + public String createFarmClubHistoryDetail(Long userId, Long userFarmClubId, String veggieInfoId) { List missionPostHistoryList = missionPostHelper.getMissionPostHistory(userFarmClubId); List stepList = veggieInfoHelper.getStepList(veggieInfoId); From 3d7880c754242cbf2d839d88e05e8273bfc6c00a Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Wed, 28 Aug 2024 01:52:35 +0900 Subject: [PATCH 16/18] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EC=97=90=20=ED=9E=88=EC=8A=A4=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/user/service/UserService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 62e2ed7d..292d2f47 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -2,6 +2,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.helper.MissionPostHelper; +import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryCommentHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.DiaryLikeHelper; @@ -41,6 +42,7 @@ public class UserService { private final MyVeggieHelper myVeggieHelper; private final FarmClubHelper farmClubHelper; private final MissionPostHelper missionPostHelper; + private final HistoryHelper historyHelper; @Transactional public BaseResponseDto selectUserProfile(Long userId) { @@ -80,6 +82,10 @@ public void deleteUser(Long userId) { // 1.4 유저 id를 통한 인증글 댓글 삭제 missionPostHelper.deleteMissionPostComments(userId); + // 히스토리 도메인 정보 삭제 + // 유저 id를 통한 히스토리 삭제 + historyHelper.deleteHistory(userId); + // 1.0 유저 도메인 삭제 userHelper.deleteUser(userId); } From 14f876731ed8a6999e2109aac6ca503112025dda Mon Sep 17 00:00:00 2001 From: seungryeol Date: Tue, 3 Sep 2024 20:39:33 +0900 Subject: [PATCH 17/18] =?UTF-8?q?[style]=20=EC=9C=A0=EC=A0=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20service=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserService.java | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 292d2f47..bd5753bb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -59,34 +59,15 @@ public BaseResponseDto selectUserProfile(Long userId) { @Transactional public void deleteUser(Long userId) { Optional user = userRepository.findUser(userId); - // 유저 검증 verifyUser(user); - - // 팜클럽 도메인 정보 삭제 - // 유저의 채소 엔티티 조회 - List myVeggieList = myVeggieHelper.getMyVeggieUserId(userId); - // 내 채소 id를 통한 유저 팜클럽 삭제 - farmClubHelper.deleteFarmClubDomain(myVeggieList); - - // 채소 도메인 정보 삭제 - // 유저 id를 통한 내 채소 삭제 - myVeggieHelper.deleteMyVeggiesByUserId(userId); - - // 유저 도메인 정보 삭제 - // 1.1 유저 id를 통한 성장일기 좋아요 삭제 - diaryLikeHelper.deleteLikes(userId); - // 1.2 유저 id를 통한 성장일기 댓글 삭제 - diaryCommentHelper.deleteComments(userId); - // 1.3 유저 id를 통한 인증글 좋아요 삭제 - missionPostHelper.deleteMissionPostLikes(userId); - // 1.4 유저 id를 통한 인증글 댓글 삭제 - missionPostHelper.deleteMissionPostComments(userId); - - // 히스토리 도메인 정보 삭제 - // 유저 id를 통한 히스토리 삭제 - historyHelper.deleteHistory(userId); - - // 1.0 유저 도메인 삭제 + List myVeggieList = myVeggieHelper.getMyVeggieUserId(userId); + farmClubHelper.deleteFarmClubDomain(myVeggieList); + myVeggieHelper.deleteMyVeggiesByUserId(userId); + diaryLikeHelper.deleteLikes(userId); + diaryCommentHelper.deleteComments(userId); + missionPostHelper.deleteMissionPostLikes(userId); + missionPostHelper.deleteMissionPostComments(userId); + historyHelper.deleteHistory(userId); userHelper.deleteUser(userId); } From 4e6bae59b8f55bdd449f43d8b1d349f4a8ea60c5 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Tue, 3 Sep 2024 20:40:12 +0900 Subject: [PATCH 18/18] =?UTF-8?q?[fix]=20=ED=9E=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=82=AD=EC=A0=9C=20=ED=95=A8=EC=88=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20->=20=EA=B0=92=EC=9D=B4=20=EC=9E=88=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20=EC=82=AD=EC=A0=9C,=20=EC=97=86=EC=9C=BC=EB=A9=B4?= =?UTF-8?q?=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/history/helper/HistoryHelper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java index d0f9c9fa..8550cfc6 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/history/helper/HistoryHelper.java @@ -27,6 +27,7 @@ import java.time.LocalDate; import java.util.List; +import java.util.Optional; import static com.modernfarmer.farmusspring.domain.history.utils.StringUtil.getHistoryPeriod; import static com.modernfarmer.farmusspring.domain.history.utils.StringUtil.getPostFormattedDate; @@ -51,8 +52,8 @@ public void createUserHistory(Long userId) { } public void deleteHistory(Long userId) { - History history = getUserHistory(userId); - historyRepository.delete(history); + Optional historyOptional = historyRepository.findByUserId(userId); + historyOptional.ifPresent(historyRepository::delete); } public String createFarmClubHistoryDetail(Long userId, Long userFarmClubId, String veggieInfoId) {