Skip to content
Closed
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 @@ -27,17 +27,13 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
""")
List<Application> findAllByUnivApplyInfoIds(@Param("univApplyInfoIds") List<Long> univApplyInfoIds, @Param("status") VerifyStatus status, @Param("termId") long termId);

@Query("""
SELECT a
FROM Application a
WHERE a.siteUserId = :siteUserId
AND a.termId = :termId
AND a.isDelete = false
""")
Optional<Application> findBySiteUserIdAndTermId(@Param("siteUserId") long siteUserId, @Param("termId") long termId);
// TODO: 근본 해결 필요
// 지원서 유일성은 DB 제약으로 강제하고
// 이 조회는 임시 회피 로직을 제거하는 방향으로 수정 필요.
Optional<Application> findTopBySiteUserIdAndTermIdAndIsDeleteFalseOrderByIdDesc(long siteUserId, long termId);

default Application getApplicationBySiteUserIdAndTermId(long siteUserId, long termId) {
return findBySiteUserIdAndTermId(siteUserId, termId)
return findTopBySiteUserIdAndTermIdAndIsDeleteFalseOrderByIdDesc(siteUserId, termId)
.orElseThrow(() -> new CustomException(APPLICATION_NOT_FOUND));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public ApplicationSubmissionResponse apply(long siteUserId, ApplyRequest applyRe
Long secondChoiceUnivApplyInfoId = univApplyInfoChoiceRequest.secondChoiceUnivApplyInfoId();
Long thirdChoiceUnivApplyInfoId = univApplyInfoChoiceRequest.thirdChoiceUnivApplyInfoId();

Optional<Application> existingApplication = applicationRepository.findBySiteUserIdAndTermId(siteUser.getId(), term.getId());
Optional<Application> existingApplication =
applicationRepository.findTopBySiteUserIdAndTermIdAndIsDeleteFalseOrderByIdDesc(siteUser.getId(), term.getId());
int updateCount = existingApplication
.map(application -> {
validateUpdateLimitNotExceed(application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ void setUp() {
ApplicationSubmissionResponse response = applicationSubmissionService.apply(user.getId(), request);

// then
Application savedApplication = applicationRepository.findBySiteUserIdAndTermId(user.getId(), term.getId()).orElseThrow();
Application savedApplication = applicationRepository
.findTopBySiteUserIdAndTermIdAndIsDeleteFalseOrderByIdDesc(user.getId(), term.getId())
.orElseThrow();
assertAll(
() -> assertThat(response.totalApplyCount())
.isEqualTo(APPLICATION_UPDATE_COUNT_LIMIT),
Expand Down
Loading