Skip to content

[Fix] 재지원 순번 계산 기준 수정#84

Merged
whc9999 merged 3 commits into
mainfrom
fix/reapply-sequence
May 26, 2026
Merged

[Fix] 재지원 순번 계산 기준 수정#84
whc9999 merged 3 commits into
mainfrom
fix/reapply-sequence

Conversation

@whc9999
Copy link
Copy Markdown
Collaborator

@whc9999 whc9999 commented May 26, 2026

✨ 어떤 이유로 PR를 하셨나요?

  • feature 병합
  • 버그 수정(아래에 issue #를 남겨주세요)
  • 코드 개선
  • 코드 수정
  • 배포
  • 기타(아래에 자세한 내용 기입해주세요)

📋 세부 내용 - 왜 해당 PR이 필요한지 작업 내용을 자세하게 설명해주세요

  • 자동 sequence 계산 기준을 공고 ID에서 사용자, 회사, 직무 기준으로 변경
  • 재지원 시 공고가 복제되어도 같은 회사와 직무이면 다음 순번이 저장되도록 수정
  • 같은 회사와 직무의 다른 공고로 재지원할 때 sequence가 증가하는 테스트 추가
  • 기존 명시 sequence 저장 및 중복 충돌 처리 로직은 유지

📸 작업 화면 스크린샷

⚠️ PR하기 전에 확인해주세요

  • 로컬테스트를 진행하셨나요?
  • 머지할 브랜치를 확인하셨나요?
  • 관련 label을 선택하셨나요?

🚨 관련 이슈 번호 []

Summary by CodeRabbit

  • New Features

    • Application sequence numbers now persist and increment per user + company + classification, keeping order consistent across positions.
    • Sequence allocation is more robust under concurrent submissions, reducing conflicts and improving reliability.
  • Tests

    • Added test verifying sequence increments when reapplying across different positions that share company and classification.

Review Change Stack

- 자동 sequence 계산 기준을 공고 ID에서 사용자, 회사, 직무 기준으로 변경
- 재지원 시 공고가 복제되어도 같은 회사와 직무이면 다음 순번이 저장되도록 수정
- 같은 회사와 직무의 다른 공고로 재지원할 때 sequence가 증가하는 테스트 추가
- 기존 명시 sequence 저장 및 중복 충돌 처리 로직은 유지
@whc9999 whc9999 self-assigned this May 26, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 18e655d9-0778-402f-8a04-22489ff4155f

📥 Commits

Reviewing files that changed from the base of the PR and between 9519110 and dde2ada.

📒 Files selected for processing (1)
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyService.java

📝 Walkthrough

Walkthrough

Sequence allocation is refactored from per-job-posting to per-(user,company,detailClassification): new MockApplySequence entity and repo, allocator service (REQUIRES_NEW + pessimistic lock), a repo query for initial max, service retry wiring, and tests validating cross-posting increments.

Changes

Mock Application Sequence Scope

Layer / File(s) Summary
Repository query for max sequence
src/main/java/com/jobdri/jobdri_api/domain/mockapply/repository/MockApplyRepository.java
New findMaxSequenceByUserIdAndCompanyIdAndDetailClassificationId method returns coalesce(max(ma.sequence), 0) filtered by user, company, and detail classification.
Sequence entity and locking repository
src/main/java/com/jobdri/jobdri_api/domain/mockapply/entity/MockApplySequence.java, src/main/java/com/jobdri/jobdri_api/domain/mockapply/repository/MockApplySequenceRepository.java
Adds MockApplySequence JPA entity with unique constraint on (user_id, company_id, detail_classification_id) and MockApplySequenceRepository.findByKeyForUpdate(...) using PESSIMISTIC_WRITE.
Sequence allocation service (REQUIRES_NEW)
src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplySequenceService.java
New service allocate(userId, companyId, detailClassificationId) opens a new transaction, locks/reads sequence row, lazily creates it using the repo max, increments, and returns the next sequence.
MockApplyService: allocation retry and wiring
src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyService.java
Injects MockApplySequenceService, adds SEQUENCE_ALLOCATE_MAX_RETRY, and retries allocate(...) on DataIntegrityViolationException; throws GeneralException(INTERNAL_SERVER_ERROR) if retries exhausted.
Sequence integration tests and helpers
src/test/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyServiceTest.java
Adds test asserting incremental sequences when a user reapplies (ACTUAL) across postings that share company and detail classification; adds saveJobPosting helper overload to persist postings from provided entities.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • JobDri-Developer/BackEnd#82: Modifies mock-application sequence computation and persistence in MockApplyService and MockApplyRepository.

Suggested labels

fix

Suggested reviewers

  • shinae1023

Poem

🐰 I hopped through rows to find the next in line,
From postings many to one company sign,
With locks and retries I nudge numbers true,
Each sequence grows steady — one, then two,
Hooray — the order holds, neat and fine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title '[Fix] 재지원 순번 계산 기준 수정' clearly summarizes the main change: fixing the reapplication sequence calculation criteria.
Description check ✅ Passed The PR description addresses key template sections with meaningful content: explicitly marks the type of change (code improvement and fix), provides detailed explanation of modifications, and confirms pre-merge checks (local testing, branch verification, and labels).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/reapply-sequence

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyService.java`:
- Around line 204-208: The current max+1 allocation in MockApplyService is racy;
replace it with an atomic sequence lookup/increment keyed by (user_id,
company_id, detail_classification_id). Add a dedicated sequence
entity/repository (e.g., MockApplySequence) with a method like
findByKeyForUpdate or incrementAndGet that runs inside a `@Transactional` method
using a row lock (SELECT ... FOR UPDATE) or PESSIMISTIC_WRITE lock to
insert-if-missing then increment the counter, and call that method from
MockApplyService instead of
mockApplyRepository.findMaxSequenceByUserIdAndCompanyIdAndDetailClassificationId(...)+1;
ensure the new allocation method is transactional so concurrent requests
serialize on the sequence row (alternatively implement DB-enforced unique
constraint + retry loop if insert fails).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 17a51003-b560-4708-a6f2-12b983e930ac

📥 Commits

Reviewing files that changed from the base of the PR and between e1bf2cf and b254f0f.

📒 Files selected for processing (3)
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/repository/MockApplyRepository.java
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyService.java
  • src/test/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyServiceTest.java

- 사용자, 회사, 직무 기준 순번 관리를 위한 MockApplySequence 엔티티 추가
- 순번 row를 비관적 락으로 조회한 뒤 증가시키는 전용 서비스 추가
- 자동 sequence 생성 시 max+1 직접 계산 대신 원자적 allocator를 사용하도록 수정
- sequence row 최초 생성 시 기존 모의 서류 지원의 최대 순번을 기준으로 초기화
- 최초 row 생성 충돌 시 재시도하도록 처리
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyService.java`:
- Around line 217-227: The catch currently rethrows
DataIntegrityViolationException on the final attempt which bypasses the intended
mapping to GeneralException; in MockApplyService (the loop that uses
SEQUENCE_ALLOCATE_MAX_RETRY) stop rethrowing inside the catch and instead either
let the loop exit or throw the GeneralException there — e.g., replace "if
(attempt == SEQUENCE_ALLOCATE_MAX_RETRY - 1) { throw e; }" with logic that does
not rethrow (or directly throws new
GeneralException(GeneralErrorCode.INTERNAL_SERVER_ERROR, "모의 서류 지원 순번 할당에
실패했습니다.")) so the DataIntegrityViolationException no longer bypasses the
GeneralException path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bc72c06-8166-4b86-803f-bcf57619bd62

📥 Commits

Reviewing files that changed from the base of the PR and between b254f0f and 9519110.

📒 Files selected for processing (4)
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/entity/MockApplySequence.java
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/repository/MockApplySequenceRepository.java
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplySequenceService.java
  • src/main/java/com/jobdri/jobdri_api/domain/mockapply/service/MockApplyService.java

- sequence row 생성 재시도 최종 실패 시 DataIntegrityViolationException이 그대로 전파되지 않도록 수정
- 순번 할당 실패를 기존 정책에 맞춰 INTERNAL_SERVER_ERROR GeneralException으로 변환
- 모의 서류 지원 생성 경로의 예외 응답 일관성 보강
@whc9999 whc9999 merged commit b470b0c into main May 26, 2026
3 checks passed
@whc9999 whc9999 added the fix label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant