From 64049856e05e83babd40b5bf7181cf7ff52b561a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=A5=EB=8F=99=EA=B2=B8?= Date: Tue, 12 Nov 2024 04:00:20 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Refactor/#34:=20User=EC=9D=98=20?= =?UTF-8?q?=EC=98=A8=EA=B8=B0=20=EC=B4=9D=20=ED=9A=9F=EC=88=98=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=20=EB=A1=9C=EC=A7=81=EC=97=90=EC=84=9C=20=EA=B0=80?= =?UTF-8?q?=EA=B2=8C=EB=B3=84=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?(#35)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReadOnjungBriefService.java | 4 ++-- .../service/ReadOnjungCountService.java | 4 ++-- .../onjung/domain/service/OnjungService.java | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) 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<>();