Skip to content

[#61] REFACTOR: 파트너 하위 거래 기준 인센티브 합계 조회 수정 #80

Merged
Hwan0518 merged 2 commits intodevelopfrom
feature/incentive/fix
Jan 30, 2026
Merged

[#61] REFACTOR: 파트너 하위 거래 기준 인센티브 합계 조회 수정 #80
Hwan0518 merged 2 commits intodevelopfrom
feature/incentive/fix

Conversation

@Hwan0518
Copy link
Contributor

Issue ✨

변경점 👍

  • 파트너 하위 거래 기준 인센티브 합계 조회 수정

- 인센티브 합계 조회를 Querydsl 전용 리포지토리로 분리

- Facade → Service → Port → Repository 구조 정리

- 하위 파트너 조회 N+1 제거 및 테스트 보완
Copilot AI review requested due to automatic review settings January 30, 2026 11:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 + subPartnerUuid filtering instead of just partnerUuid
  • Replaced N+1 queries for level 2 partner relationships with a single batch query using findAllByReferrerUuidIn
  • Introduced new service layer GetIncentiveTotalDataService for 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.

Comment on lines +56 to +63
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));
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +47
// 2-1. 추천인 uuid 목록으로 하위 파트너 관계 조회
public List<PartnerRelationship> getDownlinesRelationshipByReferrerUuidIn(List<UUID> referrerUuids) {
return partnerRelationshipQueryRepository.findAllByReferrerUuidIn(referrerUuids);
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +29
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);
}

}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
- 상위 파트너 기준으로 하위 파트너별 인센티브 합계 집계

- 파트너 관계 조회 응답 매핑 및 테스트 Fake/단위테스트 정합성 보정

- E2E 테스트 인센티브 Job 조회를 거래 단위로 제한
@Hwan0518 Hwan0518 force-pushed the feature/incentive/fix branch from 2f30186 to 9e9ba49 Compare January 30, 2026 12:08
@Hwan0518 Hwan0518 merged commit 0957d53 into develop Jan 30, 2026
@Hwan0518 Hwan0518 deleted the feature/incentive/fix branch January 30, 2026 12:09
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