Skip to content

Commit

Permalink
feat: 회원 탈퇴시 리크루트 일괄 삭제 및 리크루트 신청 일괄 취소
Browse files Browse the repository at this point in the history
  • Loading branch information
khs960616 authored Oct 25, 2023
1 parent 75f1437 commit 7497de3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ssafy.ssafsound.domain.recruit.event;

import com.ssafy.ssafsound.domain.event.MemberLeavedEvent;
import com.ssafy.ssafsound.domain.recruit.repository.RecruitRepository;
import com.ssafy.ssafsound.domain.recruitapplication.repository.RecruitApplicationRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
@RequiredArgsConstructor
public class RecruitEventListener {

private final RecruitRepository recruitRepository;
private final RecruitApplicationRepository recruitApplicationrepository;

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void transactionalEventListenerAfterCommit(MemberLeavedEvent memberLeavedEvent) {
Long memberId = memberLeavedEvent.getMemberId();
log.info("{} 회원 탈퇴로 인한 등록 리크루트글 일괄 삭제 및 리크루트 신청 일괄 취소", memberLeavedEvent.getMemberId());
recruitRepository.deleteAllByMemberId(memberId);
recruitApplicationrepository.cancelAllByMemberId(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;

import java.time.LocalDateTime;
Expand All @@ -26,4 +27,8 @@ public interface RecruitRepository extends JpaRepository<Recruit, Long>, Recruit
@Modifying
@Query(value = "update recruit r set r.finishedRecruit = true where r.endDateTime < :todayMaxTime")
int expiredTimeOutRecruits(LocalDateTime todayMaxTime);

@Modifying
@Query(value = "update recruit r set r.deletedRecruit = true where r.member.id = :memberId")
void deleteAllByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ssafy.ssafsound.domain.recruitapplication.dto.RecruitApplicationElement;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -47,4 +48,8 @@ public interface RecruitApplicationRepository extends JpaRepository<RecruitAppli
void deleteByTypeNotIn(List<MetaData> recruitTypes);

RecruitApplication findTopByRecruitIdAndMemberIdOrderByIdDesc(Long recruitId, Long memberId);

@Modifying
@Query(value = "update recruit_application ra set ra.matchStatus = com.ssafy.ssafsound.domain.recruitapplication.domain.MatchStatus.CANCEL where ra.member.id = :memberId")
void cancelAllByMemberId(Long memberId);
}

0 comments on commit 7497de3

Please sign in to comment.