Skip to content

Commit 1bc3858

Browse files
committed
refactor: 9round 리팩토링
1 parent 31afd01 commit 1bc3858

9 files changed

Lines changed: 45 additions & 14 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/order/OrderFacade.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public OrderInfo createOrder(CreateOrderCommand command) {
8888
command.userId(),
8989
orderReference,
9090
cardType,
91-
paymentCommand.cardNo(),
91+
maskCardNumber(paymentCommand.cardNo()),
9292
saved.getTotalAmount(),
9393
callbackUrl
9494
)
@@ -97,6 +97,13 @@ public OrderInfo createOrder(CreateOrderCommand command) {
9797
return OrderInfo.from(saved);
9898
}
9999

100+
private String maskCardNumber(String cardNo) {
101+
if (cardNo == null || cardNo.length() < 4) {
102+
return "****";
103+
}
104+
return "*".repeat(cardNo.length() - 4) + cardNo.substring(cardNo.length() - 4);
105+
}
106+
100107
private String createOrderReference(Long orderId) {
101108
return "order-" + orderId;
102109
}

apps/commerce-api/src/main/java/com/loopers/application/order/OrderPaymentCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
public record OrderPaymentCommand(
44
String cardType,
55
String cardNo
6-
) {}
6+
) {
7+
@Override
8+
public String toString() {
9+
return "OrderPaymentCommand[cardType=" + cardType +
10+
", cardNo=****" + (cardNo != null && cardNo.length() > 4 ? cardNo.substring(cardNo.length() - 4) : "") + "]";
11+
}
12+
}

apps/commerce-api/src/main/java/com/loopers/application/order/OrderPaymentProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public void syncPayment(Long orderId) {
6262
}
6363

6464
PgPaymentV1Dto.TransactionRecord record = data.transactions().get(data.transactions().size() - 1);
65+
66+
if (payment.getTransactionKey() != null && payment.getTransactionKey().equals(record.transactionKey())) {
67+
log.info("이미 처리된 결제입니다. orderId={}, transactionKey={}", orderId, record.transactionKey());
68+
return;
69+
}
6570
applyPaymentResult(order, payment, record.status(), record.transactionKey(), record.reason());
6671
}
6772

apps/commerce-api/src/main/java/com/loopers/application/ranking/RankingFacade.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.transaction.annotation.Transactional;
1212

1313
import java.util.List;
14+
import java.util.Objects;
1415
import java.util.stream.Collectors;
1516

1617
@Service
@@ -26,6 +27,7 @@ public List<RankingInfo> getRankingItems(String date, int page, int size) {
2627
return rankingService.getRankingRows(date, page, size)
2728
.stream()
2829
.map(this::toDto)
30+
.filter(Objects::nonNull)
2931
.collect(Collectors.toList());
3032
}
3133

@@ -50,7 +52,7 @@ private RankingInfo toDto(RankingRow row) {
5052
if (row.productId() == null) {
5153
return null;
5254
}
53-
55+
5456
Product product = productService.getProduct(row.productId());
5557
ProductInfo productInfo = ProductInfo.of(product, brandService.getBrand(product.getBrandId()));
5658
return new RankingInfo(row.rank(), row.score(), productInfo);

apps/commerce-api/src/main/java/com/loopers/application/user/UserFacade.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import com.loopers.support.error.ErrorType;
88
import lombok.RequiredArgsConstructor;
99
import org.springframework.stereotype.Component;
10+
import org.springframework.transaction.annotation.Transactional;
1011

1112
@RequiredArgsConstructor
1213
@Component
1314
public class UserFacade {
1415
private final UserService userService;
1516
private final PointService pointService;
1617

18+
@Transactional
1719
public UserInfo register(String userId, String email, String birth, String gender) {
1820
User user = userService.register(userId, email, birth, gender);
1921
pointService.initPoint(user.getUserId());

apps/commerce-api/src/main/java/com/loopers/infrastructure/outbox/OutboxEventPublisher.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.springframework.kafka.core.KafkaTemplate;
1212
import org.springframework.scheduling.annotation.Scheduled;
1313
import org.springframework.stereotype.Component;
14-
import org.springframework.transaction.annotation.Transactional;
1514

1615
import java.util.List;
1716

@@ -34,7 +33,6 @@ void logConfiguration() {
3433
}
3534

3635
@Scheduled(fixedDelayString = "${outbox.publisher.fixed-delay-ms:1000}")
37-
@Transactional
3836
public void publishPendingEvents() {
3937
if (!publisherEnabled) {
4038
return;

apps/commerce-streamer/src/main/java/com/loopers/interfaces/consumer/CatalogMetricsConsumer.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.loopers.confg.kafka.KafkaConfig;
44
import com.loopers.domain.event.EventHandledService;
55
import com.loopers.domain.metrics.ProductMetricsService;
6-
import com.loopers.ranking.RankingService;
76
import com.loopers.interfaces.consumer.message.CatalogEventMessage;
7+
import com.loopers.ranking.RankingService;
88
import lombok.RequiredArgsConstructor;
99
import lombok.extern.slf4j.Slf4j;
1010
import org.springframework.kafka.annotation.KafkaListener;
@@ -40,7 +40,7 @@ public void consume(
4040

4141
try {
4242
for (CatalogEventMessage message : messages) {
43-
if (message == null || message.eventId() == null) {
43+
if (!isValid(message)) {
4444
continue;
4545
}
4646
if (eventHandledService.isHandled(message.eventId())) {
@@ -66,4 +66,10 @@ public void consume(
6666
throw exception;
6767
}
6868
}
69+
70+
private boolean isValid(CatalogEventMessage message) {
71+
return message != null
72+
&& message.eventId() != null
73+
&& message.productId() != null;
74+
}
6975
}

apps/pg-simulator/src/main/resources/application.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spring:
1414
main:
1515
web-application-type: servlet
1616
application:
17-
name: commerce-api
17+
name: pg-simulator
1818
profiles:
1919
active: local
2020
config:
@@ -24,11 +24,6 @@ spring:
2424
- logging.yml
2525
- monitoring.yml
2626

27-
datasource:
28-
mysql-jpa:
29-
main:
30-
jdbc-url: jdbc:mysql://localhost:3306/paymentgateway
31-
3227
springdoc:
3328
use-fqn: true
3429
swagger-ui:
@@ -40,6 +35,11 @@ spring:
4035
activate:
4136
on-profile: local, test
4237

38+
datasource:
39+
mysql-jpa:
40+
main:
41+
jdbc-url: jdbc:mysql://localhost:3306/paymentgateway
42+
4343
server:
4444
port: 8082
4545

modules/redis/src/main/java/com/loopers/ranking/RankingScorePolicy.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.springframework.stereotype.Component;
44

5+
import java.math.BigDecimal;
6+
57
@Component
68
public class RankingScorePolicy {
79

@@ -21,6 +23,9 @@ public double orderScore(Long price, Long quantity) {
2123
if (price == null || quantity == null || price <= 0 || quantity <= 0) {
2224
return 0d;
2325
}
24-
return price * quantity * ORDER_WEIGHT;
26+
return BigDecimal.valueOf(price)
27+
.multiply(BigDecimal.valueOf(quantity))
28+
.multiply(BigDecimal.valueOf(ORDER_WEIGHT))
29+
.doubleValue();
2530
}
2631
}

0 commit comments

Comments
 (0)