From 3ee05e9d1ab2d6aae396459f526d0bcf12e0f8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Mon, 4 Nov 2024 13:56:01 +0900 Subject: [PATCH 01/10] =?UTF-8?q?remove:=20=EC=A4=91=EB=B3=B5=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/service/PointUpdateService.java | 31 ---------- .../service/PointUpdateServiceTest.java | 62 ------------------- 2 files changed, 93 deletions(-) delete mode 100644 src/main/java/com/ordertogether/team14_be/payment/service/PointUpdateService.java delete mode 100644 src/test/java/com/ordertogether/team14_be/payment/service/PointUpdateServiceTest.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/service/PointUpdateService.java b/src/main/java/com/ordertogether/team14_be/payment/service/PointUpdateService.java deleted file mode 100644 index c3cec251..00000000 --- a/src/main/java/com/ordertogether/team14_be/payment/service/PointUpdateService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.ordertogether.team14_be.payment.service; - -import com.ordertogether.team14_be.member.application.service.MemberService; -import com.ordertogether.team14_be.payment.domain.PaymentEvent; -import com.ordertogether.team14_be.payment.persistence.repository.PaymentEventRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class PointUpdateService { - - private final PaymentEventRepository paymentEventRepository; - private final MemberService memberService; - - @Transactional - public Integer increasePoint(String orderId) { - PaymentEvent paymentEvent = - paymentEventRepository - .findByOrderId(orderId) - .orElseThrow( - () -> - new IllegalArgumentException( - "orderId : %s 에 해당하는 PaymentEvent 가 없습니다.".formatted(orderId))); - - return memberService - .findMember(paymentEvent.getBuyerId()) - .increasePoint(paymentEvent.totalAmount().intValue()); - } -} diff --git a/src/test/java/com/ordertogether/team14_be/payment/service/PointUpdateServiceTest.java b/src/test/java/com/ordertogether/team14_be/payment/service/PointUpdateServiceTest.java deleted file mode 100644 index 89abc11f..00000000 --- a/src/test/java/com/ordertogether/team14_be/payment/service/PointUpdateServiceTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ordertogether.team14_be.payment.service; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -import com.ordertogether.team14_be.helper.PaymentDatabaseHelper; -import com.ordertogether.team14_be.member.persistence.MemberRepository; -import com.ordertogether.team14_be.payment.persistence.repository.PaymentEventRepository; -import java.util.NoSuchElementException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; - -@SpringBootTest -@ActiveProfiles(profiles = "test") -class PointUpdateServiceTest { - - @Autowired PointUpdateService pointUpdateService; - - @Autowired MemberRepository memberRepository; - @Autowired PaymentEventRepository paymentEventRepository; - - @Autowired PaymentDatabaseHelper paymentDatabaseHelper; - - @BeforeEach - void setUp() { - paymentDatabaseHelper.clean(); - - paymentDatabaseHelper.setOrderId("test-order-id"); - paymentDatabaseHelper.saveTestData(); - } - - @Test - @DisplayName("구매 금액만큼 포인트가 증가한다") - void shouldIncreaseSuccessWhenNormallyRequest() { - // given - int beforePoint = - memberRepository - .findById(1L) - .orElseThrow(() -> new NoSuchElementException("Member not found")) - .getPoint(); - Long chargeAmount = - paymentEventRepository - .findByOrderId("test-order-id") - .orElseThrow(() -> new NoSuchElementException("PaymentEvent not found")) - .totalAmount(); - - // when - pointUpdateService.increasePoint("test-order-id"); - - // then - int afterPoint = - memberRepository - .findById(1L) - .orElseThrow(() -> new NoSuchElementException("Member not found")) - .getPoint(); - assertThat(afterPoint).isEqualTo(beforePoint + chargeAmount); - } -} From fa758027b8812769b6691613dd12c1891ed0f7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Mon, 4 Nov 2024 13:56:28 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20Point=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD/=EC=9D=91=EB=8B=B5=20dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/payment/web/request/UsePointRequest.java | 4 ++++ .../team14_be/payment/web/response/PointResponse.java | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/request/UsePointRequest.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/response/PointResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/request/UsePointRequest.java b/src/main/java/com/ordertogether/team14_be/payment/web/request/UsePointRequest.java new file mode 100644 index 00000000..ce9114f9 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/request/UsePointRequest.java @@ -0,0 +1,4 @@ +package com.ordertogether.team14_be.payment.web.request; + +public record UsePointRequest(Integer paymentPoint // 사용할 포인트 총액 + ) {} diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PointResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PointResponse.java new file mode 100644 index 00000000..35d49a28 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PointResponse.java @@ -0,0 +1,6 @@ +package com.ordertogether.team14_be.payment.web.response; + +import lombok.Builder; + +@Builder +public record PointResponse(Integer remainingPoint) {} From 6e6ba1c8899acf0b036c795ee138a0aea7c1f880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Mon, 4 Nov 2024 13:56:45 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=B0=A8=EA=B0=90=20API=20=EB=8D=94=EB=AF=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/PointController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/controller/PointController.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/controller/PointController.java b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PointController.java new file mode 100644 index 00000000..3b6bf491 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PointController.java @@ -0,0 +1,26 @@ +package com.ordertogether.team14_be.payment.web.controller; + +import com.ordertogether.team14_be.common.web.response.ApiResponse; +import com.ordertogether.team14_be.payment.web.request.UsePointRequest; +import com.ordertogether.team14_be.payment.web.response.PointResponse; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/points") +public class PointController { + + @PutMapping + public ResponseEntity> usePoint(@RequestBody UsePointRequest request) { + return ResponseEntity.ok( + ApiResponse.with(HttpStatus.OK, "포인트 사용이 완료되었습니다.", createUsePointResponse())); + } + + private PointResponse createUsePointResponse() { + return PointResponse.builder().remainingPoint(100000).build(); + } +} From 4332ca08e641cddf0112d2651cd67de95b6f1b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 16:55:50 +0900 Subject: [PATCH 04/10] =?UTF-8?q?remove:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/MemberService.java | 26 ------------------- .../memebr/persistence/MemberRepository.java | 12 --------- 2 files changed, 38 deletions(-) delete mode 100644 src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java delete mode 100644 src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java b/src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java deleted file mode 100644 index 9ae1f05a..00000000 --- a/src/main/java/com/ordertogether/team14_be/memebr/application/service/MemberService.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ordertogether.team14_be.memebr.application.service; - -import com.ordertogether.team14_be.memebr.persistence.MemberRepository; -import com.ordertogether.team14_be.memebr.persistence.entity.Member; -import org.springframework.stereotype.Service; - -@Service -public class MemberService { - - private final MemberRepository memberRepository; - - public MemberService(MemberRepository memberRepository) { - this.memberRepository = memberRepository; - } - - public void findOrCreateMember(String email) { - Member member = - memberRepository - .findByEmail(email) - .orElseGet( - () -> { - Member newMember = Member.createMember(email); - return memberRepository.saveAndFlush(newMember); - }); - } -} diff --git a/src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java b/src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java deleted file mode 100644 index cea83bb6..00000000 --- a/src/main/java/com/ordertogether/team14_be/memebr/persistence/MemberRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.ordertogether.team14_be.memebr.persistence; - -import com.ordertogether.team14_be.memebr.persistence.entity.Member; -import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface MemberRepository extends JpaRepository { - - Optional findByEmail(String email); -} From 1c78763c3da124650520bf676a579620e4af4f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 16:56:05 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20data.sql=20=EB=8D=94=EB=AF=B8=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/data.sql | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index b3610722..4b7ecbf0 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -1,5 +1,26 @@ -INSERT INTO member (id, email, point, phone_number, delivery_name, platform) VALUES (1, 'member1@example.com', 100000, '010-1234-5678', 'John Doe', 'Kakao'); +INSERT INTO member (id, email, point, phone_number, delivery_name, platform) VALUES (1, 'member1@example.com', 1000000, '010-0000-0001', 'Member01', 'Kakao'); +INSERT INTO member (id, email, point, phone_number, delivery_name, platform) VALUES (2, 'member2@example.com', 1000000, '010-0000-0002', 'Member02', 'Kakao'); INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (1, 'Product 1', 10000, now(), now(), 1, 1); INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (2, 'Product 2', 20000, now(), now(), 1, 1); INSERT INTO product (id, name, price, created_at, modified_at, created_by, modified_by) VALUES (3, 'Product 3', 30000, now(), now(), 1, 1); + +INSERT INTO payment_event (id, buyer_id, created_at, modified_at, order_id, order_name, payment_key, payment_status) VALUES (1, 1, now(), now(), 'test-order-id-1', 'Product 1, Product 2, Product 3', 'test-payment-key-1', 'SUCCESS'); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (1, 1, 'test-order-id-1', 'Product 1', 10000, now(), now()); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (2, 2, 'test-order-id-1', 'Product 2', 20000, now(), now()); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (3, 3, 'test-order-id-1', 'Product 3', 30000, now(), now()); + +INSERT INTO payment_event (id, buyer_id, created_at, modified_at, order_id, order_name, payment_key, payment_status) VALUES (2, 1, now(), now(), 'test-order-id-2', 'Product 1, Product 2', 'test-payment-key-2', 'SUCCESS'); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (4, 1, 'test-order-id-2', 'Product 1', 10000, now(), now()); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (5, 2, 'test-order-id-2', 'Product 2', 20000, now(), now()); + +INSERT INTO payment_event (id, buyer_id, created_at, modified_at, order_id, order_name, payment_key, payment_status) VALUES (3, 1, now(), now(), 'test-order-id-3', 'Product 1, Product 3', 'test-payment-key-3', 'FAIL'); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (6, 1, 'test-order-id-3', 'Product 1', 10000, now(), now()); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (7, 3, 'test-order-id-3', 'Product 3', 30000, now(), now()); + +INSERT INTO payment_event (id, buyer_id, created_at, modified_at, order_id, order_name, payment_key, payment_status) VALUES (4, 2, now(), now(), 'test-order-id-4', 'Product 1', 'test-payment-key-4', 'SUCCESS'); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (8, 1, 'test-order-id-4', 'Product 1', 10000, now(), now()); + +INSERT INTO payment_event (id, buyer_id, created_at, modified_at, order_id, order_name, payment_key, payment_status) VALUES (5, 2, now(), now(), 'test-order-id-5', 'Product 1, Product 2', 'test-payment-key-5', 'SUCCESS'); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (9, 1, 'test-order-id-5', 'Product 1', 10000, now(), now()); +INSERT INTO payment_order (id, product_id, order_id, order_name, amount, created_at, modified_at) VALUES (10, 2, 'test-order-id-5', 'Product 2', 20000, now(), now()); From d5590255f19bc25edec976430a40d9ec4a2a798b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 16:56:29 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=9D=B4=EB=A6=84=EC=9C=BC=EB=A1=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/payment/domain/PaymentStatus.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java index c8b22524..79f45496 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java +++ b/src/main/java/com/ordertogether/team14_be/payment/domain/PaymentStatus.java @@ -1,5 +1,6 @@ package com.ordertogether.team14_be.payment.domain; +import java.util.Arrays; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -21,4 +22,12 @@ public boolean isSuccess() { public boolean isFail() { return this == FAIL; } + + public static PaymentStatus fromString(String statusName) { + return Arrays.stream(PaymentStatus.values()) + .filter(paymentStatus -> paymentStatus.name().equalsIgnoreCase(statusName)) + .findFirst() + .orElseThrow( + () -> new IllegalArgumentException("%s 는 올바른 결제 상태가 아닙니다.".formatted(statusName))); + } } From ec87a03128a770a3224cdd30fb8e64aa42cd1f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 17:57:11 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20DTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/payment/web/dto/PaymentHistory.java | 6 ++++++ .../payment/web/request/PaymentHistoryRequest.java | 3 +++ .../payment/web/response/PaymentHistoryResponse.java | 8 ++++++++ 3 files changed, 17 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/dto/PaymentHistory.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentHistoryRequest.java create mode 100644 src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentHistoryResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/dto/PaymentHistory.java b/src/main/java/com/ordertogether/team14_be/payment/web/dto/PaymentHistory.java new file mode 100644 index 00000000..5651d872 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/dto/PaymentHistory.java @@ -0,0 +1,6 @@ +package com.ordertogether.team14_be.payment.web.dto; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +public record PaymentHistory(BigDecimal amount, LocalDateTime date) {} diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentHistoryRequest.java b/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentHistoryRequest.java new file mode 100644 index 00000000..19406f2d --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/request/PaymentHistoryRequest.java @@ -0,0 +1,3 @@ +package com.ordertogether.team14_be.payment.web.request; + +public record PaymentHistoryRequest(String paymentStatus) {} diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentHistoryResponse.java b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentHistoryResponse.java new file mode 100644 index 00000000..27f002f5 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/web/response/PaymentHistoryResponse.java @@ -0,0 +1,8 @@ +package com.ordertogether.team14_be.payment.web.response; + +import com.ordertogether.team14_be.payment.web.dto.PaymentHistory; +import java.util.List; +import lombok.Builder; + +@Builder +public record PaymentHistoryResponse(List histories) {} From d609f3d720dad12da175b1fd6a3f8d64cfd11b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 17:57:23 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JpaPaymentOrderRepository.java | 7 ++++++ .../SimpleJpaPaymentOrderRepository.java | 10 +++++++++ .../repository/PaymentOrderRepository.java | 4 ++++ .../service/PaymentHistoryService.java | 22 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/payment/service/PaymentHistoryService.java diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java index 6db87db5..d8b9e7f1 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/JpaPaymentOrderRepository.java @@ -1,11 +1,13 @@ package com.ordertogether.team14_be.payment.persistence.jpa.repository; import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.domain.PaymentStatus; import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; import com.ordertogether.team14_be.payment.persistence.jpa.entity.ProductEntity; import com.ordertogether.team14_be.payment.persistence.jpa.mapper.PaymentOrderMapper; import com.ordertogether.team14_be.payment.persistence.jpa.mapper.ProductMapper; import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository; +import com.ordertogether.team14_be.payment.web.dto.PaymentHistory; import java.math.BigDecimal; import java.util.List; import java.util.NoSuchElementException; @@ -74,6 +76,11 @@ public BigDecimal getPaymentTotalAmount(String orderId) { () -> new NoSuchElementException("주문 번호: %s 에 해당하는 주문이 존재하지 않습니다.".formatted(orderId))); } + @Override + public List getChargeHistory(Long memberId, PaymentStatus paymentStatus) { + return simpleJpaPaymentOrderRepository.getChargeHistory(memberId, paymentStatus); + } + private ProductEntity getProductEntity(PaymentOrder paymentOrder) { return simpleJpaProductRepository .findById(paymentOrder.getProductId()) diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java index 5c2c0342..221edf0f 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/jpa/repository/SimpleJpaPaymentOrderRepository.java @@ -1,6 +1,8 @@ package com.ordertogether.team14_be.payment.persistence.jpa.repository; +import com.ordertogether.team14_be.payment.domain.PaymentStatus; import com.ordertogether.team14_be.payment.persistence.jpa.entity.PaymentOrderEntity; +import com.ordertogether.team14_be.payment.web.dto.PaymentHistory; import java.math.BigDecimal; import java.util.List; import java.util.Optional; @@ -15,4 +17,12 @@ public interface SimpleJpaPaymentOrderRepository extends JpaRepository getPaymentTotalAmount(String orderId); List findByOrderId(String orderId); + + @Query( + "SELECT new com.ordertogether.team14_be.payment.web.dto.PaymentHistory(poe.amount, poe.createdAt) FROM PaymentOrderEntity poe" + + " WHERE poe.orderId IN " + + " (SELECT bpee.orderId " + + " FROM PaymentEventEntity bpee " + + " WHERE bpee.buyerId = :memberId AND bpee.paymentStatus = :paymentStatus) ") + List getChargeHistory(Long memberId, PaymentStatus paymentStatus); } diff --git a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java index 38eba9c1..eb016512 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java +++ b/src/main/java/com/ordertogether/team14_be/payment/persistence/repository/PaymentOrderRepository.java @@ -1,6 +1,8 @@ package com.ordertogether.team14_be.payment.persistence.repository; import com.ordertogether.team14_be.payment.domain.PaymentOrder; +import com.ordertogether.team14_be.payment.domain.PaymentStatus; +import com.ordertogether.team14_be.payment.web.dto.PaymentHistory; import java.math.BigDecimal; import java.util.List; import java.util.Optional; @@ -22,4 +24,6 @@ public interface PaymentOrderRepository { * @return 총 결제 금액 */ BigDecimal getPaymentTotalAmount(String orderId); + + List getChargeHistory(Long memberId, PaymentStatus paymentStatus); } diff --git a/src/main/java/com/ordertogether/team14_be/payment/service/PaymentHistoryService.java b/src/main/java/com/ordertogether/team14_be/payment/service/PaymentHistoryService.java new file mode 100644 index 00000000..547426f9 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/payment/service/PaymentHistoryService.java @@ -0,0 +1,22 @@ +package com.ordertogether.team14_be.payment.service; + +import com.ordertogether.team14_be.payment.domain.PaymentStatus; +import com.ordertogether.team14_be.payment.persistence.repository.PaymentOrderRepository; +import com.ordertogether.team14_be.payment.web.dto.PaymentHistory; +import com.ordertogether.team14_be.payment.web.response.PaymentHistoryResponse; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PaymentHistoryService { + + private final PaymentOrderRepository paymentOrderRepository; + + public PaymentHistoryResponse getChargeHistory(Long memberId, PaymentStatus paymentStatus) { + List histories = + paymentOrderRepository.getChargeHistory(memberId, paymentStatus); + return PaymentHistoryResponse.builder().histories(histories).build(); + } +} From e1ba62c0997fc1da9ff0168c2d6b674236360f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 17:57:45 +0900 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/PaymentController.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java index e567160d..80935875 100644 --- a/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java +++ b/src/main/java/com/ordertogether/team14_be/payment/web/controller/PaymentController.java @@ -1,15 +1,22 @@ package com.ordertogether.team14_be.payment.web.controller; import com.ordertogether.team14_be.common.web.response.ApiResponse; +import com.ordertogether.team14_be.member.persistence.entity.Member; +import com.ordertogether.team14_be.member.presentation.LoginMember; +import com.ordertogether.team14_be.payment.domain.PaymentStatus; import com.ordertogether.team14_be.payment.service.PaymentConfirmService; +import com.ordertogether.team14_be.payment.service.PaymentHistoryService; import com.ordertogether.team14_be.payment.service.PaymentPreparationService; import com.ordertogether.team14_be.payment.web.request.PaymentConfirmRequest; +import com.ordertogether.team14_be.payment.web.request.PaymentHistoryRequest; import com.ordertogether.team14_be.payment.web.request.PaymentPrepareRequest; import com.ordertogether.team14_be.payment.web.response.PaymentConfirmationResponse; +import com.ordertogether.team14_be.payment.web.response.PaymentHistoryResponse; import com.ordertogether.team14_be.payment.web.response.PaymentPrepareResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -22,12 +29,12 @@ public class PaymentController { private final PaymentPreparationService paymentPreparationService; private final PaymentConfirmService paymentConfirmService; + private final PaymentHistoryService paymentHistoryService; @PostMapping public ResponseEntity> preparePayment( - @RequestBody PaymentPrepareRequest request) { - // todo: 1L -> UserDetail.getUserId() - request.addBuyerId(1L); + @RequestBody PaymentPrepareRequest request, @LoginMember Member member) { + request.addBuyerId(member.getId()); PaymentPrepareResponse data = paymentPreparationService.prepare(request); return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "결제 정보를 저장하였습니다.", data)); @@ -43,4 +50,15 @@ public ResponseEntity> confirmPayment( } return ResponseEntity.ok(ApiResponse.with(HttpStatus.OK, "결제가 완료되었습니다.", data)); } + + @GetMapping("/history") + public ResponseEntity> getHistory( + @RequestBody PaymentHistoryRequest request, @LoginMember Member member) { + return ResponseEntity.ok( + ApiResponse.with( + HttpStatus.OK, + "포인트 사용 내역을 조회하였습니다.", + paymentHistoryService.getChargeHistory( + member.getId(), PaymentStatus.fromString(request.paymentStatus())))); + } } From d025f63e85a350013be5ca588c1267f60649ad6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EC=A0=9C=EB=B2=95?= Date: Tue, 5 Nov 2024 17:58:42 +0900 Subject: [PATCH 10/10] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9C=A0=EC=A7=80=EB=B3=B4=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/PaymentDatabaseHelper.java | 2 - .../helper/jpa/JpaPaymentDatabaseHelper.java | 141 +++++++++++++++--- .../service/PaymentConfirmServiceTest.java | 4 +- .../service/PointManagementServiceTest.java | 6 +- 4 files changed, 123 insertions(+), 30 deletions(-) diff --git a/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java b/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java index c8b44021..298ccb1f 100644 --- a/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java +++ b/src/test/java/com/ordertogether/team14_be/helper/PaymentDatabaseHelper.java @@ -5,6 +5,4 @@ public interface PaymentDatabaseHelper { void clean(); void saveTestData(); - - void setOrderId(String orderId); } diff --git a/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java index c2b6da2e..2ff09a27 100644 --- a/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java +++ b/src/test/java/com/ordertogether/team14_be/helper/jpa/JpaPaymentDatabaseHelper.java @@ -12,7 +12,6 @@ import com.ordertogether.team14_be.payment.persistence.repository.ProductRepository; import java.math.BigDecimal; import java.util.List; -import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -27,8 +26,6 @@ public class JpaPaymentDatabaseHelper implements PaymentDatabaseHelper { private final ProductRepository productRepository; private final MemberRepository memberRepository; - private String orderId; - @Override public void clean() { jpaDatabaseCleanup.execute(); @@ -37,56 +34,158 @@ public void clean() { @Override @Transactional public void saveTestData() { - if (Objects.isNull(orderId)) { - throw new IllegalStateException("orderId is not set"); - } - memberRepository.save( - new Member(1L, "member1@example.com", 100000, "010-1234-5678", "member1", "Kakao")); + // Save members + memberRepository.saveAll( + List.of( + new Member(1L, "member1@example.com", 1000000, "010-0000-0001", "Member01", "Kakao"), + new Member(2L, "member2@example.com", 1000000, "010-0000-0002", "Member02", "Kakao"))); + // Save products productRepository.saveAll( List.of( Product.builder().id(1L).name("Product 1").price(BigDecimal.valueOf(10000)).build(), Product.builder().id(2L).name("Product 2").price(BigDecimal.valueOf(20000)).build(), Product.builder().id(3L).name("Product 3").price(BigDecimal.valueOf(30000)).build())); - List paymentOrders = + // Save payment orders and events + List paymentOrders1 = paymentOrderRepository.saveAll( List.of( PaymentOrder.builder() .id(1L) .productId(1L) - .orderId(orderId) + .orderId("test-order-id-1") .orderName("Product 1") - .amount(BigDecimal.valueOf(10000L)) + .amount(BigDecimal.valueOf(10000)) .build(), PaymentOrder.builder() .id(2L) .productId(2L) - .orderId(orderId) + .orderId("test-order-id-1") .orderName("Product 2") - .amount(BigDecimal.valueOf(20000L)) + .amount(BigDecimal.valueOf(20000)) .build(), PaymentOrder.builder() .id(3L) .productId(3L) - .orderId(orderId) + .orderId("test-order-id-1") .orderName("Product 3") - .amount(BigDecimal.valueOf(30000L)) + .amount(BigDecimal.valueOf(30000)) .build())); paymentEventRepository.save( PaymentEvent.builder() .id(1L) .buyerId(1L) - .orderId(orderId) - .paymentOrders(paymentOrders) + .orderId("test-order-id-1") + .paymentOrders(paymentOrders1) .orderName("Product 1, Product 2, Product 3") .paymentStatus(PaymentStatus.READY) .build()); - } - @Override - public void setOrderId(String orderId) { - this.orderId = orderId; + List paymentOrders2 = + paymentOrderRepository.saveAll( + List.of( + PaymentOrder.builder() + .id(4L) + .productId(1L) + .orderId("test-order-id-2") + .orderName("Product 1") + .amount(BigDecimal.valueOf(10000)) + .build(), + PaymentOrder.builder() + .id(5L) + .productId(2L) + .orderId("test-order-id-2") + .orderName("Product 2") + .amount(BigDecimal.valueOf(20000)) + .build())); + + paymentEventRepository.save( + PaymentEvent.builder() + .id(2L) + .buyerId(1L) + .orderId("test-order-id-2") + .paymentOrders(paymentOrders2) + .orderName("Product 1, Product 2") + .paymentStatus(PaymentStatus.SUCCESS) + .build()); + + List paymentOrders3 = + paymentOrderRepository.saveAll( + List.of( + PaymentOrder.builder() + .id(6L) + .productId(1L) + .orderId("test-order-id-3") + .orderName("Product 1") + .amount(BigDecimal.valueOf(10000)) + .build(), + PaymentOrder.builder() + .id(7L) + .productId(3L) + .orderId("test-order-id-3") + .orderName("Product 3") + .amount(BigDecimal.valueOf(30000)) + .build())); + + paymentEventRepository.save( + PaymentEvent.builder() + .id(3L) + .buyerId(1L) + .orderId("test-order-id-3") + .paymentOrders(paymentOrders3) + .orderName("Product 1, Product 3") + .paymentStatus(PaymentStatus.FAIL) + .build()); + + List paymentOrders4 = + paymentOrderRepository.saveAll( + List.of( + PaymentOrder.builder() + .id(8L) + .productId(1L) + .orderId("test-order-id-4") + .orderName("Product 1") + .amount(BigDecimal.valueOf(10000)) + .build())); + + paymentEventRepository.save( + PaymentEvent.builder() + .id(4L) + .buyerId(2L) + .orderId("test-order-id-4") + .paymentOrders(paymentOrders4) + .orderName("Product 1") + .paymentStatus(PaymentStatus.SUCCESS) + .build()); + + List paymentOrders5 = + paymentOrderRepository.saveAll( + List.of( + PaymentOrder.builder() + .id(9L) + .productId(1L) + .orderId("test-order-id-5") + .orderName("Product 1") + .amount(BigDecimal.valueOf(10000)) + .build(), + PaymentOrder.builder() + .id(10L) + .productId(2L) + .orderId("test-order-id-5") + .orderName("Product 2") + .amount(BigDecimal.valueOf(20000)) + .build())); + + paymentEventRepository.save( + PaymentEvent.builder() + .id(5L) + .buyerId(2L) + .orderId("test-order-id-5") + .paymentOrders(paymentOrders5) + .orderName("Product 1, Product 2") + .paymentStatus(PaymentStatus.SUCCESS) + .build()); } } diff --git a/src/test/java/com/ordertogether/team14_be/payment/service/PaymentConfirmServiceTest.java b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentConfirmServiceTest.java index b5543afd..ced0c5f9 100644 --- a/src/test/java/com/ordertogether/team14_be/payment/service/PaymentConfirmServiceTest.java +++ b/src/test/java/com/ordertogether/team14_be/payment/service/PaymentConfirmServiceTest.java @@ -57,8 +57,6 @@ void setUp() { pointManagementService); paymentDatabaseHelper.clean(); - - paymentDatabaseHelper.setOrderId("test-order-id"); paymentDatabaseHelper.saveTestData(); } @@ -75,7 +73,7 @@ void shouldSaveSuccessStatusWhenNormallyRequest() { long chargeAmount = 60000L; PaymentConfirmRequest request = PaymentConfirmRequest.builder() - .orderId("test-order-id") + .orderId("test-order-id-1") .paymentKey(UUID.randomUUID().toString()) .amount(chargeAmount) .build(); diff --git a/src/test/java/com/ordertogether/team14_be/payment/service/PointManagementServiceTest.java b/src/test/java/com/ordertogether/team14_be/payment/service/PointManagementServiceTest.java index 9daadf15..086f35bb 100644 --- a/src/test/java/com/ordertogether/team14_be/payment/service/PointManagementServiceTest.java +++ b/src/test/java/com/ordertogether/team14_be/payment/service/PointManagementServiceTest.java @@ -27,8 +27,6 @@ class PointManagementServiceTest { @BeforeEach void setUp() { paymentDatabaseHelper.clean(); - - paymentDatabaseHelper.setOrderId("test-order-id"); paymentDatabaseHelper.saveTestData(); } @@ -43,12 +41,12 @@ void shouldIncreaseSuccessWhenNormallyRequest() { .getPoint(); Long chargeAmount = paymentEventRepository - .findByOrderId("test-order-id") + .findByOrderId("test-order-id-1") .orElseThrow(() -> new NoSuchElementException("PaymentEvent not found")) .totalAmount(); // when - pointManagementService.increasePoint("test-order-id"); + pointManagementService.increasePoint("test-order-id-1"); // then int afterPoint =