Skip to content

refactor(family):가족공유 api 조회 redis+db로 재구성#253

Closed
pjh813 wants to merge 1 commit into
mainfrom
refactor/336-family-jaehyeon
Closed

refactor(family):가족공유 api 조회 redis+db로 재구성#253
pjh813 wants to merge 1 commit into
mainfrom
refactor/336-family-jaehyeon

Conversation

@pjh813
Copy link
Copy Markdown
Contributor

@pjh813 pjh813 commented Mar 16, 2026

개요

가족 공유 api 조회 로직 db -> redis +db로 변경

관련 BackLog

Resolves: (Backlog Number, ...)

PR 유형

  • [] 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • [ x] 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

PR Checklist

  • 커밋 메시지 컨벤션에 맞게 작성했습니다.
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

Summary by CodeRabbit

Release Notes

  • New Features

    • Live balance query service for family shared pool calculations
    • Shared limit status indicators added to family member profiles
  • Updates

    • Remaining data calculations now integrated with real-time balance sources
    • Family pool responses include additional status information fields
    • Enhanced remaining amount display across shared pool details

@pjh813 pjh813 requested review from Iwantcod, Misu0616 and hyeonRS March 16, 2026 18:35
@pjh813 pjh813 self-assigned this Mar 16, 2026
@github-actions
Copy link
Copy Markdown

정책 위반: main에는 dev에서만 PR이 가능합니다. 이 PR은 자동으로 닫습니다.

@github-actions github-actions Bot closed this Mar 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f094f68a-48fb-4f53-979b-60c07e76465d

📥 Commits

Reviewing files that changed from the base of the PR and between 195ed24 and eaba715.

📒 Files selected for processing (7)
  • src/main/java/com/pooli/family/domain/dto/response/FamilyMembersResDto.java
  • src/main/java/com/pooli/family/service/FamilySharedPoolsService.java
  • src/main/java/com/pooli/family/service/impl/FamilyServiceImpl.java
  • src/main/java/com/pooli/traffic/service/runtime/TrafficRemainingBalanceQueryService.java
  • src/main/resources/mapper/family/FamilyMapper.xml
  • src/test/java/com/pooli/family/service/FamilySharedPoolsServiceTest.java
  • src/test/java/com/pooli/family/service/impl/FamilyServiceImplTest.java

📝 Walkthrough

Walkthrough

This PR introduces TrafficRemainingBalanceQueryService to compute actual remaining data balances by combining database values with Redis cache, integrating it across family service layer to provide accurate shared pool and individual member balance calculations instead of static stored values.

Changes

Cohort / File(s) Summary
Response DTOs
src/main/java/.../FamilyMembersResDto.java
Added sharedPoolRemainingData (Long) and sharedLimitActive (Boolean) fields with @JsonIgnore and @Schema(hidden = true) annotations.
New Balance Query Service
src/main/java/.../TrafficRemainingBalanceQueryService.java
Introduced new Spring service with resolveIndividualActualRemaining and resolveSharedActualRemaining methods; combines DB values with Redis-cached balances via BalanceKeyResolver, includes overflow-safe addition and fallback to normalized DB value.
Family Service Implementations
src/main/java/.../FamilySharedPoolsService.java, src/main/java/.../impl/FamilyServiceImpl.java
Integrated TrafficRemainingBalanceQueryService dependency; updated getters and response construction to use actual remaining balance computations; added helper methods (enrichFamilyMember, resolveSharedPoolRemainingAmount, applySharedLimit) for balance enrichment and clamping.
Mapper Configuration
src/main/resources/mapper/family/FamilyMapper.xml
Added sharedPoolRemainingData alias to selectFamilyMembersHeader result and sharedLimitActive alias (via COALESCE) to selectFamilyMembers result.
Test Updates
src/test/java/.../FamilySharedPoolsServiceTest.java, src/test/java/.../FamilyServiceImplTest.java
Introduced mocked TrafficRemainingBalanceQueryService dependency; updated test expectations for actual remaining values; added new test case for unlimited shared data limit scenario; enriched FamilyMembersResDto construction with additional fields.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FamilyService as Family Service
    participant BalanceService as TrafficRemainingBalanceQueryService
    participant Redis as Redis Cache
    participant Database as Database

    Client->>FamilyService: getFamilyMembers() / getSharedPoolStatus()
    FamilyService->>Database: Fetch family/member data<br/>(dbRemaining value)
    Database-->>FamilyService: Return family header & members
    
    FamilyService->>BalanceService: resolveSharedActualRemaining<br/>(familyId, dbRemaining)
    BalanceService->>BalanceService: Normalize dbRemaining
    BalanceService->>Redis: Read balance key<br/>(owner, yearMonth)
    Redis-->>BalanceService: Redis balance value<br/>(or null if miss)
    
    BalanceService->>BalanceService: safeAdd(normalized, redisValue)<br/>with overflow protection
    BalanceService-->>FamilyService: Actual remaining balance
    
    FamilyService->>FamilyService: Enrich members with<br/>actual remaining data
    FamilyService->>FamilyService: Apply shared limit<br/>clamping if needed
    FamilyService-->>Client: Return response with<br/>actual remaining amounts
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Dev to main #228: Modifies FamilySharedPoolsService and family/traffic runtime integration for balance synchronization and runtime resolution.
  • Dev #233: Updates FamilyMapper.xml selectFamilyMembers query to compute shared pool remaining and related field aliases.
  • Dev #226: Makes related modifications across family/shared-pool codebase including DTOs, services, and mapper configurations.

Suggested labels

feature, priority: midium

Suggested reviewers

  • Iwantcod
  • hyeonRS
  • Misu0616

Poem

🐰 A query service hops with glee,
Redis cache and database agree,
Actual balances now ring true,
No more stale numbers in the zoo,
Family pools refresh with care,
Real remaining data, debts laid bare!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/336-family-jaehyeon
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.

Add a .trivyignore file to your project to customize which findings Trivy reports.

@github-actions
Copy link
Copy Markdown

정책 위반: main에는 dev에서만 PR이 가능합니다. 이 PR은 자동으로 닫습니다.

@pjh813 pjh813 deleted the refactor/336-family-jaehyeon branch March 17, 2026 08:34
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.

1 participant