Skip to content

Commit b76e00f

Browse files
committed
feat(settlement): 정산 도메인 구현 및 전 모듈 동시성 보강
- 정산 서비스/컨트롤러/엔티티/스케줄러 구현 - 전 엔티티 @Version 낙관적 락 적용 - ID 생성 AtomicLong → UUID 전환 - 스케줄러 무제한 조회 → 페이지 배치 처리 - docker-compose에 settlementdb 추가 - 전 모듈 순수 유닛 테스트 추가
1 parent 3fb70f0 commit b76e00f

File tree

39 files changed

+3039
-75
lines changed

39 files changed

+3039
-75
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
CLAUDE.md
44

55
### Docs ###
6-
**/TEST_LIST.md
6+
**/*.md
77

88
### Gradle ###
99
.gradle/

buildSrc/src/main/groovy/paybook.java-conventions.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id 'io.spring.dependency-management'
4+
id 'jacoco'
45
}
56

67
group = 'com.paybook'
@@ -31,4 +32,12 @@ dependencyManagement {
3132

3233
test {
3334
useJUnitPlatform()
35+
finalizedBy jacocoTestReport
36+
}
37+
38+
jacocoTestReport {
39+
dependsOn test
40+
reports {
41+
csv.required = true
42+
}
3443
}

core/src/main/java/com/paybook/core/entity/CouponEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class CouponEntity {
3636

3737
private Integer minOrderAmount;
3838

39+
@Version
40+
private Long version;
41+
3942
public CouponEntity(String couponId, CouponStatus status, CouponType couponType,
4043
DiscountType discountType, int discountValue, Integer maxDiscountAmount) {
4144
this(couponId, status, couponType, discountType, discountValue, maxDiscountAmount, null);

core/src/main/java/com/paybook/core/entity/PaymentEntity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PaymentEntity {
2020
@Column(nullable = false, unique = true)
2121
private String paymentId;
2222

23-
@Column(nullable = false)
23+
@Column(nullable = false, unique = true)
2424
private String orderId;
2525

2626
private int pgPaymentAmount;
@@ -34,6 +34,9 @@ public class PaymentEntity {
3434
@Column(nullable = false)
3535
private LocalDateTime createdAt;
3636

37+
@Version
38+
private Long version;
39+
3740
public PaymentEntity(String paymentId, String orderId, int pgPaymentAmount) {
3841
this.paymentId = paymentId;
3942
this.orderId = orderId;

core/src/main/java/com/paybook/core/entity/UserPointEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class UserPointEntity {
2020

2121
private int balance;
2222

23+
@Version
24+
private Long version;
25+
2326
public UserPointEntity(String userId, int balance) {
2427
this.userId = userId;
2528
this.balance = balance;

docker-compose.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
services:
2+
orderdb:
3+
image: postgres:17
4+
container_name: paybook-orderdb
5+
environment:
6+
POSTGRES_DB: orderdb
7+
POSTGRES_USER: paybook
8+
POSTGRES_PASSWORD: paybook
9+
ports:
10+
- "5432:5432"
11+
volumes:
12+
- orderdb-data:/var/lib/postgresql/data
13+
14+
paymentdb:
15+
image: postgres:17
16+
container_name: paybook-paymentdb
17+
environment:
18+
POSTGRES_DB: paymentdb
19+
POSTGRES_USER: paybook
20+
POSTGRES_PASSWORD: paybook
21+
ports:
22+
- "5433:5432"
23+
volumes:
24+
- paymentdb-data:/var/lib/postgresql/data
25+
26+
settlementdb:
27+
image: postgres:17
28+
container_name: paybook-settlementdb
29+
environment:
30+
POSTGRES_DB: settlementdb
31+
POSTGRES_USER: paybook
32+
POSTGRES_PASSWORD: paybook
33+
ports:
34+
- "5434:5432"
35+
volumes:
36+
- settlementdb-data:/var/lib/postgresql/data
37+
38+
volumes:
39+
orderdb-data:
40+
paymentdb-data:
41+
settlementdb-data:

order/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ dependencies {
77
implementation 'org.springframework.boot:spring-boot-starter-web'
88
implementation 'org.springframework.boot:spring-boot-starter-validation'
99
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
10-
runtimeOnly 'com.h2database:h2'
10+
runtimeOnly 'org.postgresql:postgresql'
11+
testRuntimeOnly 'com.h2database:h2'
1112
testImplementation 'org.springframework.boot:spring-boot-starter-test'
1213
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
1314
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'

order/src/main/java/com/paybook/order/dto/OrderResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public record OrderResponse(
1212
int pgPaymentAmount,
1313
int deliveryFee,
1414
String status,
15+
String couponId,
1516
String createdAt
1617
) {
1718
public record OrderItemResponse(

order/src/main/java/com/paybook/order/entity/OrderEntity.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import com.paybook.order.exception.OrderException;
44
import jakarta.persistence.*;
5-
import lombok.AccessLevel;
6-
import lombok.Getter;
7-
import lombok.NoArgsConstructor;
5+
import lombok.*;
86

97
import java.time.LocalDateTime;
108
import java.util.ArrayList;
@@ -16,6 +14,8 @@
1614
@Table(name = "orders")
1715
@Getter
1816
@NoArgsConstructor(access = AccessLevel.PROTECTED)
17+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
18+
@Builder
1919
public class OrderEntity {
2020

2121
private static final Set<OrderStatus> NON_CANCELLABLE_STATUSES = EnumSet.of(
@@ -34,6 +34,7 @@ public class OrderEntity {
3434
private String userId;
3535

3636
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
37+
@Builder.Default
3738
private List<OrderItemEntity> items = new ArrayList<>();
3839

3940
private int totalAmount;
@@ -48,7 +49,8 @@ public class OrderEntity {
4849

4950
@Enumerated(EnumType.STRING)
5051
@Column(nullable = false)
51-
private OrderStatus status;
52+
@Builder.Default
53+
private OrderStatus status = OrderStatus.PENDING_PAYMENT;
5254

5355
private String deliveryAddress;
5456

@@ -57,25 +59,11 @@ public class OrderEntity {
5759
private Integer pointAmountToUse;
5860

5961
@Column(nullable = false)
60-
private LocalDateTime createdAt;
61-
62-
public OrderEntity(String orderId, String userId, int totalAmount,
63-
int couponDiscountAmount, int pointDiscountAmount, int pgPaymentAmount,
64-
int deliveryFee, String deliveryAddress, String couponId,
65-
Integer pointAmountToUse) {
66-
this.orderId = orderId;
67-
this.userId = userId;
68-
this.totalAmount = totalAmount;
69-
this.couponDiscountAmount = couponDiscountAmount;
70-
this.pointDiscountAmount = pointDiscountAmount;
71-
this.pgPaymentAmount = pgPaymentAmount;
72-
this.deliveryFee = deliveryFee;
73-
this.deliveryAddress = deliveryAddress;
74-
this.couponId = couponId;
75-
this.pointAmountToUse = pointAmountToUse;
76-
this.status = OrderStatus.PENDING_PAYMENT;
77-
this.createdAt = LocalDateTime.now();
78-
}
62+
@Builder.Default
63+
private LocalDateTime createdAt = LocalDateTime.now();
64+
65+
@Version
66+
private Long version;
7967

8068
public void addItem(OrderItemEntity item) {
8169
items.add(item);

order/src/main/java/com/paybook/order/repository/OrderRepository.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.springframework.data.jpa.repository.JpaRepository;
88

99
import java.time.LocalDateTime;
10-
import java.util.List;
1110
import java.util.Optional;
1211

1312
public interface OrderRepository extends JpaRepository<OrderEntity, Long> {
@@ -18,5 +17,5 @@ public interface OrderRepository extends JpaRepository<OrderEntity, Long> {
1817

1918
Page<OrderEntity> findByUserIdAndStatusOrderByCreatedAtDesc(String userId, OrderStatus status, Pageable pageable);
2019

21-
List<OrderEntity> findByStatusAndCreatedAtBefore(OrderStatus status, LocalDateTime cutoff);
20+
Page<OrderEntity> findByStatusAndCreatedAtBefore(OrderStatus status, LocalDateTime cutoff, Pageable pageable);
2221
}

0 commit comments

Comments
 (0)