diff --git a/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungBriefService.java b/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungBriefService.java index 49775c6..1e73543 100644 --- a/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungBriefService.java +++ b/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungBriefService.java @@ -52,8 +52,8 @@ public ReadOnjungBriefResponseDto execute(UUID accountId) { // 온정 생성 Onjung onjung = onjungService.createOnjung(donations, receipts, shares); - // 온정 총 개수 계산 - Integer totalOnjungCount = onjungService.calculateTotalOnjungCount(onjung); + // 온정 총 개수 계산 (가게별 중복 제외) + Integer totalOnjungCount = onjungService.calculateTotalUniqueOnjungStoreCount(onjung); // 온정 총 금액 계산 Integer totalOnjungAmount = onjungService.calculateTotalOnjungAmount(onjung); diff --git a/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java b/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java index 9b4f8b3..3231226 100644 --- a/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java +++ b/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java @@ -54,8 +54,8 @@ public ReadOnjungCountResponseDto execute( // Onjung 생성 Onjung onjung = onjungService.createOnjung(donations, receipts, shares); - // User의 총 온정 횟수 조회 - Integer totalOnjungCount = onjungService.calculateTotalOnjungCount(onjung); + // User의 총 온정 횟수 조회 (가게 중복 제외) + Integer totalOnjungCount = onjungService.calculateTotalUniqueOnjungStoreCount(onjung); return ReadOnjungCountResponseDto.builder() .totalOnjungCount(totalOnjungCount) diff --git a/src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java b/src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java index b623be1..9e519e2 100644 --- a/src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java +++ b/src/main/java/com/daon/onjung/onjung/domain/service/OnjungService.java @@ -1,5 +1,6 @@ package com.daon.onjung.onjung.domain.service; +import com.daon.onjung.account.domain.Store; import com.daon.onjung.account.domain.User; import com.daon.onjung.onjung.domain.Donation; import com.daon.onjung.onjung.domain.Onjung; @@ -15,6 +16,7 @@ @Service public class OnjungService { + // 기부, 영수증, 공유 객체를 받아서 온정 객체를 생성 public Onjung createOnjung( List donations, List receipts, @@ -27,10 +29,32 @@ public Onjung createOnjung( .build(); } + // 온정 객체를 받아서 총 온정 횟수를 계산 public Integer calculateTotalOnjungCount(Onjung onjung) { return onjung.getDonations().size() + onjung.getReceipts().size() + onjung.getShares().size(); } + // 온정 객체를 받아서 총 온정 횟수를 계산(가게 중복 제외) + public Integer calculateTotalUniqueOnjungStoreCount(Onjung onjung) { + Set uniqueStores = new HashSet<>(); + + // 각 리스트에서 Store 객체를 수집하여 Set에 추가 + uniqueStores.addAll(onjung.getDonations().stream() + .map(Donation::getStore) + .collect(Collectors.toSet())); + + uniqueStores.addAll(onjung.getReceipts().stream() + .map(Receipt::getStore) + .collect(Collectors.toSet())); + + uniqueStores.addAll(onjung.getShares().stream() + .map(Share::getStore) + .collect(Collectors.toSet())); + + return uniqueStores.size(); + } + + // 온정 객체를 받아서 총 함께한 온정인 수를 계산(중복 제외) public Integer calculateTotalUniqueOnjungUserCount(Onjung onjung) { Set uniqueUsers = new HashSet<>();