Skip to content

Commit

Permalink
hotfix: 회원탈퇴 리크루트 처리 핫픽스
Browse files Browse the repository at this point in the history
* fix: 삭제된 리크루트가 조회되지 않도록 엔티티 클래스의 where clause 추가

* chore: 미사용 import 제거

* fix: 매칭 완료된 리크루트 존재시, current number 일괄 변경 추가
  • Loading branch information
khs960616 authored Oct 25, 2023
1 parent 7497de3 commit 118ff1a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.RequiredArgsConstructor;

import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.time.LocalDateTime;
Expand All @@ -24,6 +25,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Where(clause = "deleted_recruit = false")
public class Recruit extends BaseTimeEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ssafy.ssafsound.domain.recruit.event;

import com.ssafy.ssafsound.domain.event.MemberLeavedEvent;
import com.ssafy.ssafsound.domain.recruit.repository.RecruitLimitationRepository;
import com.ssafy.ssafsound.domain.recruit.repository.RecruitRepository;
import com.ssafy.ssafsound.domain.recruitapplication.repository.RecruitApplicationRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,13 +16,15 @@
public class RecruitEventListener {

private final RecruitRepository recruitRepository;
private final RecruitLimitationRepository recruitLimitationRepository
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);
recruitLimitationRepository.decreaseCurrentNumberByMemberId(memberId);
recruitApplicationrepository.cancelAllByMemberId(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.ssafy.ssafsound.domain.recruit.domain.Recruit;
import com.ssafy.ssafsound.domain.recruit.domain.RecruitLimitation;
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 java.util.List;
Expand All @@ -11,4 +13,15 @@ public interface RecruitLimitationRepository extends JpaRepository<RecruitLimita
List<RecruitLimitation> findByRecruitId(Long recruitId);

void deleteAllByRecruit(@Param("recruit") Recruit recruit);

@Modifying
@Query(value = "update recruit_limitation rl " +
"set rl.currentNumber = rl.currentNumber-1 " +
"where (rl.recruit, rl.type) in " +
"(" +
" select ra.recruit, ra.type from recruit_application ra " +
" where ra.matchStatus = com.ssafy.ssafsound.domain.recruitapplication.domain.MatchStatus.DONE and ra.member.id = :memberId" +
")"
)
void decreaseCurrentNumberByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;

import javax.persistence.*;

Expand All @@ -17,6 +18,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Where(clause = "match_status != 'CANCEL'")
public class RecruitApplication extends BaseTimeEntity {

@Id
Expand Down

0 comments on commit 118ff1a

Please sign in to comment.