Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -17,9 +17,23 @@ public interface JobPostRepository extends JpaRepository<JobPost, Long> {
@EntityGraph(attributePaths = {"author", "author.positions"})
Optional<JobPost> findById(Long id);

// 🔁 (삭제) 증분 방식
// @Modifying(clearAutomatically = true, flushAutomatically = true)
// @Query("update JobPost p set p.applicantCount = p.applicantCount + 1 where p.id = :postId")
// int incrementApplicantCount(@Param("postId") Long postId);

// ✅ 항상 실제 건수로 동기화(네이티브 쿼리)
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("update JobPost p set p.applicantCount = p.applicantCount + 1 where p.id = :postId")
int incrementApplicantCount(Long postId);
@Query(value = """
UPDATE job_post p
SET p.applicant_count = (
SELECT COUNT(*)
FROM job_application a
WHERE a.post_id = :postId
)
WHERE p.id = :postId
""", nativeQuery = true)
int syncApplicantCount(@Param("postId") Long postId);

@Query("""
select jp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void applyToJob(Long postId, Long applicantId, Long resumeId) {
application.setCreatedAt(LocalDateTime.now());
jobApplicationRepository.save(application);

jobPostRepository.incrementApplicantCount(postId);
jobPostRepository.syncApplicantCount(postId);

// ✅ 지원 저장 직후 바로 알림 생성 (이벤트/트랜잭션 훅 의존 X)
Notification noti = Notification.builder()
Expand Down