[#61] REFACTOR: 파트너 하위 거래 기준 인센티브 합계 조회 수정 #80
Conversation
- 인센티브 합계 조회를 Querydsl 전용 리포지토리로 분리 - Facade → Service → Port → Repository 구조 정리 - 하위 파트너 조회 N+1 제거 및 테스트 보완
There was a problem hiding this comment.
Pull request overview
This PR refactors the incentive total query logic to properly track incentives based on the relationship between the partner who receives the incentive and the sub-partner whose transaction generated it. The main improvement is replacing N+1 query patterns with efficient batch queries.
Changes:
- Refactored incentive total query to use
partnerUuid+subPartnerUuidfiltering instead of justpartnerUuid - Replaced N+1 queries for level 2 partner relationships with a single batch query using
findAllByReferrerUuidIn - Introduced new service layer
GetIncentiveTotalDataServicefor better separation of concerns
Reviewed changes
Copilot reviewed 9 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| FakePartnerRelationshipQueryRepository.java | Added fake implementation for batch query method |
| FakeIncentiveTotalQueryPort.java | Updated fake to track partner-subpartner relationship |
| PartnerRelationshipFacadeUnitTest.java | Updated tests to use new service and parameter signature |
| TradeCreateApiE2ETest.java | Improved query specificity in E2E test |
| PartnerRelationshipAssembler.java | Added groupByReferrerUuid helper method |
| GetPartnerRelationshipDataService.java | Added batch query method for partner relationships |
| GetIncentiveTotalDataService.java | New service layer for incentive total queries |
| PartnerRelationshipQueryRepository.java | Added interface for batch query method |
| IncentiveTotalQueryPort.java | Updated signature to include partnerUuid filter |
| PartnerRelationshipFacade.java | Refactored to use batch queries and new service |
| IncentiveTotalQueryPortImpl.java (old) | Removed old implementation in wrong package |
| PartnerRelationshipQueryRepositoryImpl.java | Implemented batch query method |
| IncentiveTotalQueryPortImpl.java (new) | New implementation using QueryDSL repository |
| IncentiveTotalQuerydslRepository.java | New QueryDSL repository with proper filtering |
| PartnerRelationshipJpaRepository.java | Added JPA method for batch query |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public Map<UUID, List<PartnerRelationship>> groupByReferrerUuid(List<PartnerRelationship> relationships) { | ||
| if (relationships == null || relationships.isEmpty()) { | ||
| return Map.of(); | ||
| } | ||
| return relationships.stream() | ||
| .filter(rel -> rel.getReferrerUuid() != null) | ||
| .collect(Collectors.groupingBy(PartnerRelationship::getReferrerUuid)); | ||
| } |
There was a problem hiding this comment.
The new groupByReferrerUuid method lacks unit test coverage. While it's exercised indirectly through integration tests, the existing test file PartnerRelationshipAssemblerUnitTest.java has tests for other methods in this class (like buildLevel2RelationshipMap and extractAllLevel2DownlineUuids), but not for this new method. Consider adding unit tests for this method to maintain consistency with the testing approach used for other methods in this class.
| // 2-1. 추천인 uuid 목록으로 하위 파트너 관계 조회 | ||
| public List<PartnerRelationship> getDownlinesRelationshipByReferrerUuidIn(List<UUID> referrerUuids) { | ||
| return partnerRelationshipQueryRepository.findAllByReferrerUuidIn(referrerUuids); | ||
| } |
There was a problem hiding this comment.
The new service method getDownlinesRelationshipByReferrerUuidIn lacks direct unit test coverage. While the fake implementation in test code and integration tests exercise this functionality, there are no dedicated unit tests for this service method in GetPartnerRelationshipDataServiceUnitTest.java. Consider adding unit tests to verify edge cases such as null input, empty list, and normal operation.
| package greenfirst.be.user.application.service; | ||
|
|
||
|
|
||
| import greenfirst.be.user.application.port.out.incentive.IncentiveTotalQueryPort; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
|
|
||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class GetIncentiveTotalDataService { | ||
|
|
||
| // port | ||
| private final IncentiveTotalQueryPort incentiveTotalQueryPort; | ||
|
|
||
| /** | ||
| * 인센티브 합계 조회 서비스 | ||
| * - 상위 파트너 기준, 하위 파트너 거래로 얻은 인센티브 합계 조회 | ||
| */ | ||
| public Map<UUID, BigDecimal> getTotalIncentiveBySubPartnerUuids(UUID partnerUuid, List<UUID> subPartnerUuids) { | ||
| return incentiveTotalQueryPort.getTotalIncentiveBySubPartnerUuids(partnerUuid, subPartnerUuids); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
The entire GetIncentiveTotalDataService class lacks unit test coverage. This is a new service layer that wraps the port call, and while it's tested through integration tests, following the codebase pattern of having dedicated unit tests for service classes would improve maintainability and debugging.
- 상위 파트너 기준으로 하위 파트너별 인센티브 합계 집계 - 파트너 관계 조회 응답 매핑 및 테스트 Fake/단위테스트 정합성 보정 - E2E 테스트 인센티브 Job 조회를 거래 단위로 제한
2f30186 to
9e9ba49
Compare
Issue ✨
변경점 👍