-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,4 @@ public interface PaymentDatabaseHelper { | |
void clean(); | ||
|
||
void saveTestData(); | ||
|
||
void setOrderId(String orderId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, "[email protected]", 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<PaymentOrder> paymentOrders = | ||
// Save payment orders and events | ||
List<PaymentOrder> 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<PaymentOrder> 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<PaymentOrder> 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<PaymentOrder> 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<PaymentOrder> 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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters