Skip to content

[fix] 급여명세서 계산 정확도 개선 및 Worker API null 안전성 보완#179

Merged
geunyong16 merged 6 commits into
mainfrom
fix/154-salary-calculation-accuracy
May 4, 2026
Merged

[fix] 급여명세서 계산 정확도 개선 및 Worker API null 안전성 보완#179
geunyong16 merged 6 commits into
mainfrom
fix/154-salary-calculation-accuracy

Conversation

@geunyong16
Copy link
Copy Markdown
Collaborator

@geunyong16 geunyong16 commented May 3, 2026

🔖 관련 GitHub Issue

📝 변경 사항

주요 변경 내용

  • Worker/Contract DTO에 profileImageUrl 필드 추가 및 null 안전성 개선 (NPE 방지)
  • 급여 계산 로직 개선: 일일 연장수당(8시간 초과)과 주간 연장수당(40시간 초과) 이중 계산 방지
  • WorkerContractRepository 쿼리에 JOIN FETCH w.user 추가로 N+1 문제 해결
  • WeeklyAllowance 주간 연장수당 계산 시 이미 일일 연장으로 처리된 시간 차감
  • Refresh Token을 Body 응답에서 HttpOnly Cookie 방식으로 변경 (보안 강화)
  • AWS S3 프로필 이미지 업로드 기능 제거

상세 설명

1. 급여 계산 정확도 개선 (이슈 #154 핵심)

기존에는 일 8시간 초과분이 WorkRecord 레벨에서 연장수당으로 계산된 후, WeeklyAllowance에서 주간 40시간 초과분을 계산할 때 같은 시간이 다시 포함되어 이중 계산이 발생했습니다.

  • WorkRecordovertimeHours, overtimeSalary 필드 추가 (일일 8시간 초과분 명시)
  • WorkRecord.calculateSalaryWithAllowanceRules()를 단순화: 기본급(1.0배) + 야간/휴일/연장 가산분(0.5배)으로 통일
  • WeeklyAllowance에서 주간 연장 계산 시 totalDailyOvertimeHours를 차감한 순수 주간 초과분에만 0.5배 적용
  • SalaryService에서 totalDailyOvertimePaytotalWeeklyOvertimePay 분리 집계

2. Worker API null 안전성 개선

contract.getWorker().getUser().getName() 방식 접근 시 User 탈퇴/null인 경우 NPE 발생 가능성 제거.
ContractDto.Response, ContractDto.ListResponse, WorkerDto.Responsefrom() 메서드에 null 체크 추가.

3. N+1 쿼리 해결

WorkerContractRepository의 4개 조회 쿼리 모두에 JOIN FETCH w.user u 추가하여 Worker → User 접근 시 추가 쿼리 방지.

4. Refresh Token HttpOnly Cookie 전환

기존 응답 Body로 전달되던 Refresh Token을 HttpOnly Cookie로 변경. XSS 공격을 통한 토큰 탈취 위험 차단.

5. AWS S3 프로필 이미지 업로드 제거

ProfileImageStorageService, S3Config, FileUploadException 및 관련 엔드포인트 제거.

📸 스크린샷 (선택사항)

스크린샷 보기

Before

After

✅ 체크리스트

  • PR 제목이 형식에 맞는가? (유형: 작업 요약)
  • 코드가 정상적으로 빌드되는가?
  • 새로운 기능에 대한 테스트 코드를 작성했는가?
  • 모든 테스트가 통과하는가?
  • 코드 스타일 가이드를 따랐는가?
  • 관련 문서를 업데이트했는가?

🔗 관련 PR

Summary by CodeRabbit

릴리스 노트

  • 새로운 기능

    • 근로자 및 계약 조회 응답에 profileImageUrl 필드 추가
    • 일일 초과근무와 주간 초과근무를 구분하여 급여 계산 개선
  • 개선 사항

    • 초과근무료 계산 로직 최적화로 급여 정확도 향상
    • API 응답에 추가 정보 포함으로 사용자 경험 개선

- Add null safety checks for User object in WorkerDto.Response.from()

- Add null safety checks for Worker/User objects in ContractDto

- Update API_SPECIFICATION.md with profileImageUrl field

- Fixes review feedback for fix/154-worker-kakao-info
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

Walkthrough

근로자 프로필 이미지 필드를 추가하고, 일일 초과근무와 주간 초과근무를 분리하여 계산하도록 급여 산출 로직을 재구성했습니다. 데이터 접근 최적화와 API 명세 업데이트를 포함합니다.

Changes

초과근무 계산 및 급여 항목 분리

Layer / File(s) 요약
Data Shape
src/main/java/com/example/paycheck/domain/workrecord/entity/WorkRecord.java
WorkRecordovertimeHours(일일 초과근무 시간)와 overtimeSalary(초과근무 수당) 필드를 추가하고, 시간 및 급여 계산 로직을 재정의했습니다.
Core Calculation
src/main/java/com/example/paycheck/domain/allowance/entity/WeeklyAllowance.java, src/main/java/com/example/paycheck/domain/workrecord/entity/WorkRecord.java
주간 초과근무 계산에서 일일 초과근무(WorkRecord)를 차감하여 순 주간 초과근무 시간을 도출하고, 시간당 급여 계산을 0.5배로 통일했습니다. WorkRecord 급여 계산을 기본급(시간 × 시급), 초과근무/야간/휴일 수당(각 시간 × 시급 × 0.5)으로 단순화했습니다.
Service Integration
src/main/java/com/example/paycheck/domain/salary/service/SalaryService.java
일일 초과근무 수당(totalDailyOvertimePay)과 주간 초과근무 수당(totalWeeklyOvertimePay)을 분리 누적한 후 합산하여 최종 초과근무 수당을 산출합니다.
API Response
src/main/java/com/example/paycheck/domain/workrecord/dto/WorkRecordDto.java
WorkRecordDto.DetailedResponseovertimeSalary 필드를 추가하고, 팩토리 메서드를 갱신했습니다.
Tests
src/test/java/com/example/paycheck/domain/allowance/..., src/test/java/com/example/paycheck/domain/salary/..., src/test/java/com/example/paycheck/domain/workrecord/...
초과근무 수당 기댓값, 급여 항목별 예상 금액, 야간/휴일 시간 배분 등을 새로운 계산 로직에 맞게 수정했습니다.

프로필 이미지 필드 및 데이터 조회 최적화

Layer / File(s) 요약
Data Shape
src/main/java/com/example/paycheck/domain/worker/dto/WorkerDto.java, src/main/java/com/example/paycheck/domain/contract/dto/ContractDto.java
WorkerDto.ResponseContractDto.Response/ListResponseprofileImageUrl 필드를 추가했습니다.
Data Access Optimization
src/main/java/com/example/paycheck/domain/contract/repository/WorkerContractRepository.java, src/main/java/com/example/paycheck/domain/workrecord/repository/WorkRecordRepository.java
JPQL 쿼리에 JOIN FETCH w.user 절을 추가하여 worker의 User 정보를 eager-loading하도록 최적화했습니다.
API Response
src/main/java/com/example/paycheck/domain/worker/dto/WorkerDto.java, src/main/java/com/example/paycheck/domain/contract/dto/ContractDto.java
팩토리 메서드를 null-safe 조건식으로 업데이트하여 User 정보(userId, profileImageUrl 등)를 안전하게 추출합니다.
API Documentation
docs/API_SPECIFICATION.md
근로자/계약 조회 응답 예시에 profileImageUrl 필드를 추가했습니다.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Refresh Token HttpOnly Cookie 전환, AWS S3 프로필 이미지 제거 등의 변경은 PR 설명에 언급되어 있지만 Issue #154의 급여 계산 정확도 개선과는 직접적 관련이 없습니다. Refresh Token 변경과 AWS S3 기능 제거는 별도의 Issue나 PR로 분리하거나, Issue #154 범위에 포함된 작업임을 명확히 문서화해야 합니다.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 주요 변경 내용(급여 계산 정확도 개선, Worker API null 안전성)을 명확하게 요약하고 있으며, 변경사항의 핵심을 잘 반영하고 있습니다.
Linked Issues check ✅ Passed 급여 계산 로직 개선을 통해 일일 연장수당과 주간 연장수당 이중 계산 방지, WorkRecord에 overtimeHours/overtimeSalary 필드 추가, WeeklyAllowance 개선으로 Issue #154의 급여 계산 정확도 향상 요구사항을 충족합니다.
Description check ✅ Passed PR 설명이 템플릿의 모든 필수 섹션을 포함하고 있으며, 변경 사항을 명확하고 상세하게 기술하고 있습니다.

✏️ 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/154-salary-calculation-accuracy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

geunyong16 and others added 2 commits May 4, 2026 11:27
- Fix regularHours bug in WorkRecord: use totalHours - nightHours (not totalHours)
- Add missing getOvertimeSalary()/getOvertimeHours() mock stubs to prevent NPE
- Update test assertions to match new salary decomposition:
  basePay = totalHours × rate × 1.0, premiums = hours × rate × 0.5
- Update WeeklyAllowance overtime assertions: 1.5x rate → 0.5x rate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@geunyong16 geunyong16 merged commit cdf1ae1 into main May 4, 2026
1 check passed
@geunyong16 geunyong16 deleted the fix/154-salary-calculation-accuracy branch May 4, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 급여명세서 값이 제대로 표시되지 않음

1 participant