Skip to content

Commit

Permalink
๐Ÿ”จ Refactor/#34: User์˜ ์˜จ๊ธฐ ์ด ํšŸ์ˆ˜ ๊ณ„์‚ฐ ๋กœ์ง์—์„œ ๊ฐ€๊ฒŒ๋ณ„ ์ค‘๋ณต ์ œ๊ฑฐ (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
dongkyeomjang authored Nov 11, 2024
1 parent 94a17b3 commit 6404985
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +16,7 @@
@Service
public class OnjungService {

// ๊ธฐ๋ถ€, ์˜์ˆ˜์ฆ, ๊ณต์œ  ๊ฐ์ฒด๋ฅผ ๋ฐ›์•„์„œ ์˜จ์ • ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑ
public Onjung createOnjung(
List<Donation> donations,
List<Receipt> receipts,
Expand All @@ -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<Store> 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<User> uniqueUsers = new HashSet<>();

Expand Down

0 comments on commit 6404985

Please sign in to comment.