From 47f3478dd104feb0aad1c48bb30b06c6d52bd8a1 Mon Sep 17 00:00:00 2001 From: dongkyeomjang Date: Tue, 19 Nov 2024 02:55:53 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Feature/#24:=204.2=20=ED=9B=84?= =?UTF-8?q?=EC=9B=90=20=ED=9A=9F=EC=88=98=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http/onjung/OnjungControllerHttpRequest.http | 10 ++- .../query/OnjungQueryV1Controller.java | 19 +++++- .../response/ReadOnjungCountResponseDto.java | 17 +++++ .../service/ReadOnjungCountService.java | 64 +++++++++++++++++++ .../usecase/ReadOnjungCountUseCase.java | 11 ++++ .../repository/mysql/DonationRepository.java | 5 ++ .../repository/mysql/ReceiptRepository.java | 5 ++ .../repository/mysql/ShareRepository.java | 5 ++ 8 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/daon/onjung/onjung/application/dto/response/ReadOnjungCountResponseDto.java create mode 100644 src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java create mode 100644 src/main/java/com/daon/onjung/onjung/application/usecase/ReadOnjungCountUseCase.java diff --git a/http/onjung/OnjungControllerHttpRequest.http b/http/onjung/OnjungControllerHttpRequest.http index 0baa6bd..00aa2a0 100644 --- a/http/onjung/OnjungControllerHttpRequest.http +++ b/http/onjung/OnjungControllerHttpRequest.http @@ -1,4 +1,10 @@ ### 4.1 전체 온기 통계 조회 // @no-log -GET {{host_url}}/api/v1/onjung/summaries -Authorization: Bearer {{access_token}} \ No newline at end of file +GET {{host_url}}/api/v1/onjungs/summaries +Authorization: Bearer {{access_token}} + +### 4.2 후원 횟수 조회 +// @no-log +GET {{host_url}}/api/v1/onjungs/count +Authorization: Bearer {{access_token}} + diff --git a/src/main/java/com/daon/onjung/onjung/application/controller/query/OnjungQueryV1Controller.java b/src/main/java/com/daon/onjung/onjung/application/controller/query/OnjungQueryV1Controller.java index 7dcad8c..d378eda 100644 --- a/src/main/java/com/daon/onjung/onjung/application/controller/query/OnjungQueryV1Controller.java +++ b/src/main/java/com/daon/onjung/onjung/application/controller/query/OnjungQueryV1Controller.java @@ -1,22 +1,39 @@ package com.daon.onjung.onjung.application.controller.query; +import com.daon.onjung.core.annotation.security.AccountID; import com.daon.onjung.core.dto.ResponseDto; +import com.daon.onjung.onjung.application.dto.response.ReadOnjungCountResponseDto; import com.daon.onjung.onjung.application.dto.response.ReadOnjungSummaryResponseDto; +import com.daon.onjung.onjung.application.usecase.ReadOnjungCountUseCase; import com.daon.onjung.onjung.application.usecase.ReadOnjungSummaryUseCase; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.UUID; + @RestController @RequiredArgsConstructor public class OnjungQueryV1Controller { + private final ReadOnjungSummaryUseCase readOnjungSummaryUseCase; + private final ReadOnjungCountUseCase readOnjungCountUseCase; /** * 4.1 전체 온기 통계 조회하기 */ - @GetMapping("/api/v1/onjung/summaries") + @GetMapping("/api/v1/onjungs/summaries") public ResponseDto readOnjungSummary() { return ResponseDto.ok(readOnjungSummaryUseCase.execute()); } + + /** + * 4.2 후원 횟수 조회하기 + */ + @GetMapping("/api/v1/onjungs/count") + public ResponseDto readOnjungCount( + @AccountID UUID accountId + ) { + return ResponseDto.ok(readOnjungCountUseCase.execute(accountId)); + } } diff --git a/src/main/java/com/daon/onjung/onjung/application/dto/response/ReadOnjungCountResponseDto.java b/src/main/java/com/daon/onjung/onjung/application/dto/response/ReadOnjungCountResponseDto.java new file mode 100644 index 0000000..4509a83 --- /dev/null +++ b/src/main/java/com/daon/onjung/onjung/application/dto/response/ReadOnjungCountResponseDto.java @@ -0,0 +1,17 @@ +package com.daon.onjung.onjung.application.dto.response; + +import com.daon.onjung.core.dto.SelfValidating; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; + +public class ReadOnjungCountResponseDto extends SelfValidating { + + @JsonProperty("total_onjung_count") + private final Integer totalOnjungCount; + + @Builder + public ReadOnjungCountResponseDto(Integer totalOnjungCount) { + this.totalOnjungCount = totalOnjungCount; + this.validateSelf(); + } +} 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 new file mode 100644 index 0000000..9b4f8b3 --- /dev/null +++ b/src/main/java/com/daon/onjung/onjung/application/service/ReadOnjungCountService.java @@ -0,0 +1,64 @@ +package com.daon.onjung.onjung.application.service; + +import com.daon.onjung.account.domain.User; +import com.daon.onjung.account.repository.mysql.UserRepository; +import com.daon.onjung.core.exception.error.ErrorCode; +import com.daon.onjung.core.exception.type.CommonException; +import com.daon.onjung.onjung.application.dto.response.ReadOnjungCountResponseDto; +import com.daon.onjung.onjung.application.usecase.ReadOnjungCountUseCase; +import com.daon.onjung.onjung.domain.Donation; +import com.daon.onjung.onjung.domain.Onjung; +import com.daon.onjung.onjung.domain.Receipt; +import com.daon.onjung.onjung.domain.Share; +import com.daon.onjung.onjung.domain.service.OnjungService; +import com.daon.onjung.onjung.repository.mysql.DonationRepository; +import com.daon.onjung.onjung.repository.mysql.ReceiptRepository; +import com.daon.onjung.onjung.repository.mysql.ShareRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class ReadOnjungCountService implements ReadOnjungCountUseCase { + + private final UserRepository userRepository; + private final DonationRepository donationRepository; + private final ReceiptRepository receiptRepository; + private final ShareRepository shareRepository; + + private final OnjungService onjungService; + + @Override + @Transactional(readOnly = true) + public ReadOnjungCountResponseDto execute( + UUID accountId + ) { + + // User 조회 + User user = userRepository.findById(accountId) + .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE)); + + // User의 모든 동참 내역 조회 + List donations = donationRepository.findAllByUser(user); + + // User의 모든 영수증 인증 내역 조회 + List receipts = receiptRepository.findAllByUser(user); + + // User의 모든 공유 내역 조회 + List shares = shareRepository.findAllByUser(user); + + // Onjung 생성 + Onjung onjung = onjungService.createOnjung(donations, receipts, shares); + + // User의 총 온정 횟수 조회 + Integer totalOnjungCount = onjungService.calculateTotalOnjungCount(onjung); + + return ReadOnjungCountResponseDto.builder() + .totalOnjungCount(totalOnjungCount) + .build(); + } +} diff --git a/src/main/java/com/daon/onjung/onjung/application/usecase/ReadOnjungCountUseCase.java b/src/main/java/com/daon/onjung/onjung/application/usecase/ReadOnjungCountUseCase.java new file mode 100644 index 0000000..642a58d --- /dev/null +++ b/src/main/java/com/daon/onjung/onjung/application/usecase/ReadOnjungCountUseCase.java @@ -0,0 +1,11 @@ +package com.daon.onjung.onjung.application.usecase; + +import com.daon.onjung.core.annotation.bean.UseCase; +import com.daon.onjung.onjung.application.dto.response.ReadOnjungCountResponseDto; + +import java.util.UUID; + +@UseCase +public interface ReadOnjungCountUseCase { + ReadOnjungCountResponseDto execute(UUID accountId); +} diff --git a/src/main/java/com/daon/onjung/onjung/repository/mysql/DonationRepository.java b/src/main/java/com/daon/onjung/onjung/repository/mysql/DonationRepository.java index 06bf1ee..cebfd6b 100644 --- a/src/main/java/com/daon/onjung/onjung/repository/mysql/DonationRepository.java +++ b/src/main/java/com/daon/onjung/onjung/repository/mysql/DonationRepository.java @@ -1,7 +1,12 @@ package com.daon.onjung.onjung.repository.mysql; +import com.daon.onjung.account.domain.User; import com.daon.onjung.onjung.domain.Donation; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface DonationRepository extends JpaRepository { + + List findAllByUser(User user); } diff --git a/src/main/java/com/daon/onjung/onjung/repository/mysql/ReceiptRepository.java b/src/main/java/com/daon/onjung/onjung/repository/mysql/ReceiptRepository.java index c2c80fa..6097339 100644 --- a/src/main/java/com/daon/onjung/onjung/repository/mysql/ReceiptRepository.java +++ b/src/main/java/com/daon/onjung/onjung/repository/mysql/ReceiptRepository.java @@ -1,7 +1,12 @@ package com.daon.onjung.onjung.repository.mysql; +import com.daon.onjung.account.domain.User; import com.daon.onjung.onjung.domain.Receipt; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ReceiptRepository extends JpaRepository { + + List findAllByUser(User user); } diff --git a/src/main/java/com/daon/onjung/onjung/repository/mysql/ShareRepository.java b/src/main/java/com/daon/onjung/onjung/repository/mysql/ShareRepository.java index f10fb41..c411919 100644 --- a/src/main/java/com/daon/onjung/onjung/repository/mysql/ShareRepository.java +++ b/src/main/java/com/daon/onjung/onjung/repository/mysql/ShareRepository.java @@ -1,7 +1,12 @@ package com.daon.onjung.onjung.repository.mysql; +import com.daon.onjung.account.domain.User; import com.daon.onjung.onjung.domain.Share; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ShareRepository extends JpaRepository { + + List findAllByUser(User user); }