From 8d7761246e579ca266dc368ea5e275b9c0e69734 Mon Sep 17 00:00:00 2001 From: Ganghee-Lee-0522 Date: Sun, 28 Apr 2024 03:43:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=9B=94=EB=A0=9B=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=97=90=EC=84=9C=20=EB=B0=94=EB=A1=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=B6=80=ED=95=98=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 월렛 화면에서 바로 기부하기를 구현하였습니다. --- .../donut/controller/DonationController.java | 10 ++++--- .../eight/donut/service/DonationService.java | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/zero/eight/donut/controller/DonationController.java b/src/main/java/zero/eight/donut/controller/DonationController.java index bfcb0c3..fccbe8c 100644 --- a/src/main/java/zero/eight/donut/controller/DonationController.java +++ b/src/main/java/zero/eight/donut/controller/DonationController.java @@ -1,10 +1,7 @@ package zero.eight.donut.controller; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import zero.eight.donut.common.response.ApiResponse; import zero.eight.donut.dto.donation.DonateGiftRequestDto; import zero.eight.donut.dto.donation.GiftboxRequestDto; @@ -28,4 +25,9 @@ public ApiResponse assignGiftbox(@RequestBody GiftboxRequestDto giftboxReques public ApiResponse donateGift(DonateGiftRequestDto donateGiftRequestDto) throws IOException { return donationService.donateGift(donateGiftRequestDto); } + + @PatchMapping("/wallet/{giftId}") + public ApiResponse walletDonation(@PathVariable Long giftId) { + return donationService.walletDonation(giftId); + } } diff --git a/src/main/java/zero/eight/donut/service/DonationService.java b/src/main/java/zero/eight/donut/service/DonationService.java index b045ead..77076a1 100644 --- a/src/main/java/zero/eight/donut/service/DonationService.java +++ b/src/main/java/zero/eight/donut/service/DonationService.java @@ -7,10 +7,14 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import zero.eight.donut.common.response.ApiResponse; +import zero.eight.donut.config.jwt.AuthUtils; import zero.eight.donut.domain.Gift; +import zero.eight.donut.domain.Giver; import zero.eight.donut.domain.enums.Status; import zero.eight.donut.dto.donation.DonateGiftRequestDto; import zero.eight.donut.dto.donation.GiftboxRequestDto; +import zero.eight.donut.exception.Error; +import zero.eight.donut.exception.Success; import zero.eight.donut.repository.GiftRepository; import java.io.IOException; @@ -22,6 +26,7 @@ @Service public class DonationService { + private final AuthUtils authUtils; private final SerialDonationService donationService; private final GiftRepository giftRepository; @@ -43,4 +48,25 @@ public synchronized ApiResponse assignGiftbox(GiftboxRequestDto giftboxReques public ApiResponse donateGift(DonateGiftRequestDto requestDto) throws IOException { return donationService.donateGift(requestDto); } + + @Transactional + public ApiResponse walletDonation(Long giftId) { + // 기프티콘 찾기 + Gift gift = giftRepository.findById(giftId).orElse(null); + if (gift == null) { + return ApiResponse.failure(Error.GIFT_NOT_FOUND_EXCEPTION); + } + + // 기프티콘 소유자 == 사용자 확인 + Giver giver = authUtils.getGiver(); + if (!gift.getGiver().equals(giver)) { + return ApiResponse.failure(Error.NOT_AUTHENTICATED_EXCEPTION); + } + + // 기프티콘 status 변경하기(-> UNUSED) + gift.updateStatus("UNUSED"); + giftRepository.save(gift); + + return ApiResponse.success(Success.DONATE_GIFT_SUCCESS); + } } \ No newline at end of file From 8cd835da57096f01afe7883eb7147ec9499e9a82 Mon Sep 17 00:00:00 2001 From: Ganghee-Lee-0522 Date: Sun, 28 Apr 2024 04:25:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=EA=B8=B0=EB=B6=80=20=EB=B6=80?= =?UTF-8?q?=EA=B0=80=EC=A0=95=EB=B3=B4=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 월렛에서 기부 실행 시, 기부자별 정보(Donation 테이블)를 업데이트하도록 수정하였습니다. - 월렛에서 기부 실행 시, 기부 통계(DonationInfo 테이블)를 업데이트하도록 수정하였습니다. --- .../eight/donut/service/DonationService.java | 19 +---------- .../donut/service/SerialDonationService.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/java/zero/eight/donut/service/DonationService.java b/src/main/java/zero/eight/donut/service/DonationService.java index 77076a1..ba2fd36 100644 --- a/src/main/java/zero/eight/donut/service/DonationService.java +++ b/src/main/java/zero/eight/donut/service/DonationService.java @@ -49,24 +49,7 @@ public ApiResponse donateGift(DonateGiftRequestDto requestDto) throws IOExcep return donationService.donateGift(requestDto); } - @Transactional public ApiResponse walletDonation(Long giftId) { - // 기프티콘 찾기 - Gift gift = giftRepository.findById(giftId).orElse(null); - if (gift == null) { - return ApiResponse.failure(Error.GIFT_NOT_FOUND_EXCEPTION); - } - - // 기프티콘 소유자 == 사용자 확인 - Giver giver = authUtils.getGiver(); - if (!gift.getGiver().equals(giver)) { - return ApiResponse.failure(Error.NOT_AUTHENTICATED_EXCEPTION); - } - - // 기프티콘 status 변경하기(-> UNUSED) - gift.updateStatus("UNUSED"); - giftRepository.save(gift); - - return ApiResponse.success(Success.DONATE_GIFT_SUCCESS); + return donationService.donateWalletGift(giftId); } } \ No newline at end of file diff --git a/src/main/java/zero/eight/donut/service/SerialDonationService.java b/src/main/java/zero/eight/donut/service/SerialDonationService.java index 80d8658..315489e 100644 --- a/src/main/java/zero/eight/donut/service/SerialDonationService.java +++ b/src/main/java/zero/eight/donut/service/SerialDonationService.java @@ -279,4 +279,38 @@ private void sendImageToAI(Long giftId, MultipartFile giftImage){ }) .subscribe(); } + + @Transactional + public ApiResponse donateWalletGift(Long giftId) { + // 기프티콘 찾기 + Gift gift = giftRepository.findById(giftId).orElse(null); + if (gift == null) { + return ApiResponse.failure(Error.GIFT_NOT_FOUND_EXCEPTION); + } + + // 기프티콘 소유자 == 사용자 확인 + Giver giver = authUtils.getGiver(); + if (!gift.getGiver().equals(giver)) { + return ApiResponse.failure(Error.NOT_AUTHENTICATED_EXCEPTION); + } + + // 기프티콘 status 변경하기(-> UNUSED) + gift.updateStatus("UNUSED"); + giftRepository.save(gift); + + //기부자별 정보 Donation 업데이트 + Donation donation = donationRepository.findByGiver(giver); + donation.updateSumCount( + donation.getSum() + gift.getPrice().longValue(), + donation.getCount()+1L); + + //기부 통계 업데이트 + LocalDate now = LocalDate.now(); + DonationInfo donationInfo = donationInfoRepository.findDonationInfoByMonthAndYear(now.getMonthValue(), now.getYear()); + donationInfo.updateSumCount( + donationInfo.getSum() + gift.getPrice().longValue(), + donationInfo.getCount()+1L); + + return ApiResponse.success(Success.DONATE_GIFT_SUCCESS); + } } \ No newline at end of file