Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/member] 회원 탈퇴 기능 구현 #93

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.guzzing.studayserver.domain.calendar.model.AcademyTimeTemplate;
import org.guzzing.studayserver.domain.calendar.repository.dto.AcademyTimeTemplateDateInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface AcademyTimeTemplateJpaRepository extends JpaRepository<AcademyTimeTemplate, Long>,
AcademyTimeTemplateRepository {
Expand All @@ -16,4 +18,12 @@ public interface AcademyTimeTemplateJpaRepository extends JpaRepository<AcademyT

AcademyTimeTemplate getById(Long academyTimeTemplateId);

@Modifying(clearAutomatically = true)
@Query("select att.id from AcademyTimeTemplate att where att.childId in :childIds")
List<Long> findByChildIds(List<Long> childIds);
Comment on lines +22 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<AcademyTimeTemplate> findByChildIdIn(List<Long> childIds);

이렇게도 사용할 수 있지 않나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 그러네요
in 키워드가 없을 수가 없는뎅..
그래도 확실하게 쿼리문으로 해결해보고 싶습니다!!


@Modifying(clearAutomatically = true)
@Query("delete from AcademyTimeTemplate att where att.childId in :childIds")
void deleteAllByChildIds(List<Long> childIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public interface AcademyTimeTemplateRepository {

AcademyTimeTemplate getById(Long academyTimeTemplateId);

List<Long> findByChildIds(List<Long> childIds);

void deleteAllByChildIds(List<Long> childIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,19 @@ private void changeBeforeTimeTemplateOfEndDate(
}

@Transactional
public void deleteSchedulesByDashboard(AcademyCalendarDeleteByDashboardParam Param) {
public void deleteSchedulesByDashboard(AcademyCalendarDeleteByDashboardParam param) {
List<AcademyTimeTemplateDateInfo> academyTimeTemplates
= academyTimeTemplateRepository.findAcademyTimeTemplateByDashboardId(Param.dashboardId());
= academyTimeTemplateRepository.findAcademyTimeTemplateByDashboardId(param.dashboardId());

deleteAcademySchedulesAfterStartDate(academyTimeTemplates, Param.requestedDate());
changeBeforeTimeTemplateOfEndDate(academyTimeTemplates, Param.requestedDate());
deleteAcademySchedulesAfterStartDate(academyTimeTemplates, param.requestedDate());
changeBeforeTimeTemplateOfEndDate(academyTimeTemplates, param.requestedDate());
}

@Transactional
public void removeCalendar(final List<Long> childIds) {
academyTimeTemplateRepository.findByChildIds(childIds)
.forEach(academyScheduleRepository::deleteAllByAcademyTimeTemplateId);
academyTimeTemplateRepository.deleteAllByChildIds(childIds);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

public interface ChildRepository extends JpaRepository<Child, Long> {

void deleteByMemberId(final long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public void delete(ChildDeleteParam param) {
member.removeChild(param.childId());
}

public void removeChild(long memberId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactional 필요할 것 같습니다!

childRepository.deleteByMemberId(memberId);
}

@Transactional
public Long modify(ChildModifyParam param) {
Member member = getMember(param.memberId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import org.guzzing.studayserver.domain.dashboard.model.Dashboard;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface DashboardJpaRepository extends
Expand All @@ -12,4 +13,11 @@ public interface DashboardJpaRepository extends
+ "JOIN FETCH dab.dashboardSchedules dabschs "
+ "WHERE dab.id IN :dashboardIds")
List<Dashboard> findByIds(List<Long> dashboardIds);

@Modifying(clearAutomatically = true)
@Query("""
delete from Dashboard d
where d.childId in :childIds
""")
void deleteByChildIds(List<Long> childIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ default Dashboard findDashboardById(final Long dashboardId) {
List<Dashboard> findAll();

List<Dashboard> findByIds(List<Long> dashboardIds);

void deleteByChildIds(List<Long> childIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void deleteDashboard(final long dashboardId) {
.delete();
}

@Transactional
public void removeDashboard(final List<Long> childIds) {
dashboardRepository.deleteByChildIds(childIds);
}

@Transactional
public DashboardResult editDashboard(final DashboardPutParam param) {
final FeeInfo feeInfo = serviceConverter.convertToFeeInfo(param.paymentInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface LikeRepository {

void deleteById(final Long likeId);

void deleteByMemberId(final long memberId);

void deleteByAcademyId(final Long academyId);

boolean existsById(final Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void removeLike(final Long likeId, final Long memberId) {
likeRepository.deleteById(likeId);
}

@Transactional
public void removeLike(final long memberId) {
likeRepository.deleteByMemberId(memberId);
}

@ValidMember
public void deleteLikeOfAcademy(final Long academyId, @ValidatedMemberId final Long memberId) {
likeRepository.deleteByAcademyId(academyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import org.guzzing.studayserver.domain.auth.memberId.MemberId;
import org.guzzing.studayserver.domain.member.controller.request.MemberRegisterRequest;
import org.guzzing.studayserver.domain.member.controller.response.MemberInformationResponse;
import org.guzzing.studayserver.domain.member.service.MemberFacade;
import org.guzzing.studayserver.domain.member.service.MemberService;
import org.guzzing.studayserver.domain.member.service.result.MemberInformationResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -20,9 +22,11 @@
public class MemberRestController {

private final MemberService memberService;
private final MemberFacade memberFacade;

public MemberRestController(MemberService memberService) {
public MemberRestController(MemberService memberService, MemberFacade memberFacade) {
this.memberService = memberService;
this.memberFacade = memberFacade;
}

@PatchMapping(
Expand All @@ -37,6 +41,25 @@ public ResponseEntity<Long> register(@MemberId Long memberId, @RequestBody @Vali
.body(registeredMemberId);
}

/**
* 회원탈퇴
* <p>
* 1. 회원 정보 제거 2. 아이 정보 제거 3. 학원 타임 템플릿 제거 3-1. 학원 스케줄 제거 4. 대시보드 제거 4-1. 대시보드 스케줄 5. 좋아요 제거 6. 리뷰 제거
*
* @param memberId
* @return void
*/
@DeleteMapping
public ResponseEntity<Void> remove(
@MemberId final Long memberId
) {
memberFacade.removeMember(memberId);

return ResponseEntity
.noContent()
.build();
}

@GetMapping(
produces = MediaType.APPLICATION_JSON_VALUE
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.guzzing.studayserver.domain.member.service;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.guzzing.studayserver.domain.calendar.service.AcademyCalendarService;
import org.guzzing.studayserver.domain.child.service.ChildService;
import org.guzzing.studayserver.domain.child.service.result.ChildrenFindResult.ChildFindResult;
import org.guzzing.studayserver.domain.dashboard.service.DashboardService;
import org.guzzing.studayserver.domain.like.service.LikeService;
import org.guzzing.studayserver.domain.review.service.ReviewService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
public class MemberFacade {

private final MemberService memberService;
private final ChildService childService;
private final AcademyCalendarService calendarService;
private final DashboardService dashboardService;
private final LikeService likeService;
private final ReviewService reviewService;

public MemberFacade(
final MemberService memberService,
final ChildService childService,
final AcademyCalendarService calendarService,
final DashboardService dashboardService,
final LikeService likeService,
final ReviewService reviewService
) {
this.memberService = memberService;
this.childService = childService;
this.calendarService = calendarService;
this.dashboardService = dashboardService;
this.likeService = likeService;
this.reviewService = reviewService;
}

@Transactional
public void removeMember(final long memberId) {
List<Long> childIds = childService.findByMemberId(memberId).children()
.stream()
.map(ChildFindResult::childId)
.toList();

reviewService.removeReview(memberId);
likeService.removeLike(memberId);
calendarService.removeCalendar(childIds);
dashboardService.removeDashboard(childIds);
childService.removeChild(memberId);
memberService.remove(memberId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public Long register(MemberRegisterParam param, Long memberId) {
return member.getId();
}

@Transactional
public void remove(final long memberId) {
memberRepository.deleteById(memberId);
}

public MemberInformationResult getById(Long memberId) {
Member member = getMember(memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface ReviewJpaRepository extends JpaRepository<Review, Long>, Review

boolean existsByMemberIdAndAcademyId(final Long memberId, final Long academyId);

void deleteByMemberId(final long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface ReviewRepository {

boolean existsByMemberIdAndAcademyId(final Long memberId, final Long academyId);

void deleteByMemberId(final long memberId);

void deleteAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public ReviewPostResult createReviewOfAcademy(final ReviewPostParam param) {
return ReviewPostResult.from(savedReview);
}

@Transactional
public void removeReview(final long memberId){
reviewRepository.deleteByMemberId(memberId);
}

public ReviewableResult getReviewableToAcademy(final Long memberId, final Long academyId) {
memberAccessService.validateMember(memberId);
academyAccessService.validateAcademy(academyId);
Expand Down