Skip to content

Commit

Permalink
Merge pull request #114 from Mojacknong/feature_112/회원탈퇴
Browse files Browse the repository at this point in the history
Feature 112/회원탈퇴
  • Loading branch information
Ryeolee authored Sep 3, 2024
2 parents aa4a68f + 4e6bae5 commit f467cc3
Show file tree
Hide file tree
Showing 34 changed files with 262 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -44,7 +43,7 @@ public LoginResponseDto login(SocialUserResponseDto socialUserData){
return null;
});

Optional<User> userLoginData = Optional.ofNullable(userRepository.findByUserNumber(String.valueOf(socialUserData.getId())).orElseThrow(() -> new UserNotFoundException("해당 유저의 정보가 존재하지 않습니다.")));
Optional<User> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,10 +35,13 @@ public class MissionPost extends BaseEntity {
@Builder.Default
private List<MissionPostLike> missionPostLikes = new ArrayList<>();


@OneToMany(mappedBy = "missionPost", cascade = CascadeType.ALL)
@Builder.Default
private List<MissionPostComment> missionPostComments = new ArrayList<>();


@OnDelete(action = OnDeleteAction.CASCADE)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_farm_club_id")
private UserFarmClub userFarmClub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -24,6 +26,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;



@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +35,7 @@ public class UserFarmClub extends BaseEntity {
@Column(nullable = false)
private boolean isComplete;


@OneToMany(mappedBy = "userFarmClub", cascade = CascadeType.REMOVE)
@Builder.Default
private List<MissionPost> missionPosts = new ArrayList<>();
Expand All @@ -41,6 +44,7 @@ public class UserFarmClub extends BaseEntity {
@JoinColumn(name = "farm_club_id")
private FarmClub farmClub;


@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "my_veggie_id")
private MyVeggie myVeggie;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,4 +49,8 @@ public List<FarmClub> getRecommendedFarmClubList(String level) {
public List<Long> findFarmClubIdsByUserId(Long userId) {
return userFarmClubRepository.findFarmClubIdsByUserId(userId);
}

public void deleteFarmClubDomain(List<MyVeggie> myVeggieList){
userFarmClubRepository.deleteFarmClubDomain(myVeggieList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public interface MissionPostRepositoryCustom {
List<MissionPostVo> getMissionPostList(Long userId, Long missionPostId);
List<MissionPostHistoryVo> getMissionPostHistory(Long missionPostId);
void deleteMissionPostLike(Long userId, Long missionPostId);
void deleteMissionPostComments(Long userId);
void deleteMissionPostLikes(Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,4 +13,6 @@ public interface UserFarmClubRepositoryCustom {

List<Long> findFarmClubIdsByUserId(Long userId);
SuccessFarmClubVo getFarmClubRecord(Long userId, Long farmClubId);

void deleteFarmClubDomain(List<MyVeggie> myVeggieList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MyVeggie> myVeggieList){
queryFactory
.delete(userFarmClub)
.where(userFarmClub.myVeggie.id.in(myVeggieList.stream().map(MyVeggie::getId).toList()))
.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,6 +51,11 @@ public void createUserHistory(Long userId) {
historyRepository.save(history);
}

public void deleteHistory(Long userId) {
Optional<History> historyOptional = historyRepository.findByUserId(userId);
historyOptional.ifPresent(historyRepository::delete);
}

public String createFarmClubHistoryDetail(Long userId, Long userFarmClubId, String veggieInfoId) {
List<MissionPostHistoryVo> missionPostHistoryList = missionPostHelper.getMissionPostHistory(userFarmClubId);
List<StepVo> stepList = veggieInfoHelper.getStepList(veggieInfoId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;


@OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Builder.Default
private List<DiaryComment> diaryComments = new ArrayList<>();



@OneToMany(mappedBy = "diary", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Builder.Default
private List<DiaryLike> diaryLikes = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class DiaryLike extends BaseEntity {
@JoinColumn(name = "diary_id")
private Diary diary;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,19 +42,21 @@ public class MyVeggie extends BaseEntity {
@Column(name = "veggie_image")
private String veggieImage;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;


@OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Builder.Default
private List<Routine> routines = new ArrayList<>();


@OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Builder.Default
private List<Diary> diaries = new ArrayList<>();


@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "user_farm_club_id")
private UserFarmClub userFarmClub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -56,6 +57,5 @@ public static Routine createRoutine(Date date, String content, int period, MyVeg

myVeggie.addRoutine(newRoutine);
return newRoutine;

}
}
Original file line number Diff line number Diff line change
@@ -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 deleteComments(Long userId){
diaryCommentRepository.deleteDiaryCommentsByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -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 deleteLikes(Long userId){
diaryLikeRepository.deleteDiaryLikesByUserId(userId);
}
}
Loading

0 comments on commit f467cc3

Please sign in to comment.