Skip to content

Commit 52b62bd

Browse files
authored
Merge pull request #110 from Loopers-dev-lab/revert-109-revert-86-3round
Revert "Revert "[volume-3] 도메인 모델링 및 구현""
2 parents 0074ea9 + b84525a commit 52b62bd

File tree

86 files changed

+3927
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3927
-439
lines changed

apps/commerce-api/src/main/java/com/loopers/application/example/ExampleFacade.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

apps/commerce-api/src/main/java/com/loopers/application/example/ExampleInfo.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.loopers.application.like;
2+
3+
import com.loopers.domain.like.LikeService;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* packageName : com.loopers.application.like
9+
* fileName : LikeFacade
10+
* author : byeonsungmun
11+
* date : 2025. 11. 14.
12+
* description :
13+
* ===========================================
14+
* DATE AUTHOR NOTE
15+
* -------------------------------------------
16+
* 2025. 11. 14. byeonsungmun 최초 생성
17+
*/
18+
@Component
19+
@RequiredArgsConstructor
20+
public class LikeFacade {
21+
22+
private final LikeService likeService;
23+
24+
public void createLike(String userId, Long productId) {
25+
likeService.like(userId, productId);
26+
}
27+
28+
public void deleteLike(String userId, Long productId) {
29+
likeService.unlike(userId, productId);
30+
}
31+
}
32+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.loopers.application.order;
2+
3+
import java.util.List;
4+
5+
/**
6+
* packageName : com.loopers.application.order
7+
* fileName : CreateOrderCommand
8+
* author : byeonsungmun
9+
* date : 2025. 11. 14.
10+
* description :
11+
* ===========================================
12+
* DATE AUTHOR NOTE
13+
* -------------------------------------------
14+
* 2025. 11. 14. byeonsungmun 최초 생성
15+
*/
16+
public record CreateOrderCommand(
17+
String userId,
18+
List<OrderItemCommand> items
19+
) {}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.loopers.application.order;
2+
3+
import com.loopers.domain.order.Order;
4+
import com.loopers.domain.order.OrderItem;
5+
import com.loopers.domain.order.OrderService;
6+
import com.loopers.domain.order.OrderStatus;
7+
import com.loopers.domain.point.PointService;
8+
import com.loopers.domain.product.Product;
9+
import com.loopers.domain.product.ProductService;
10+
import com.loopers.support.error.CoreException;
11+
import com.loopers.support.error.ErrorType;
12+
import lombok.RequiredArgsConstructor;
13+
import lombok.extern.slf4j.Slf4j;
14+
import org.springframework.stereotype.Component;
15+
import org.springframework.transaction.annotation.Transactional;
16+
17+
/**
18+
* packageName : com.loopers.application.order
19+
* fileName : OrderFacade
20+
* author : byeonsungmun
21+
* date : 2025. 11. 13.
22+
* description :
23+
* ===========================================
24+
* DATE AUTHOR NOTE
25+
* -------------------------------------------
26+
* 2025. 11. 13. byeonsungmun 최초 생성
27+
*/
28+
29+
@Slf4j
30+
@Component
31+
@RequiredArgsConstructor
32+
public class OrderFacade {
33+
34+
private final OrderService orderService;
35+
private final ProductService productService;
36+
private final PointService pointService;
37+
38+
@Transactional
39+
public OrderInfo createOrder(CreateOrderCommand command) {
40+
41+
if (command == null || command.items() == null || command.items().isEmpty()) {
42+
throw new CoreException(ErrorType.BAD_REQUEST, "상품 정보가 비어있습니다");
43+
}
44+
45+
Order order = Order.create(command.userId());
46+
47+
for (OrderItemCommand itemCommand : command.items()) {
48+
49+
//상품가져오고
50+
Product product = productService.getProduct(itemCommand.productId());
51+
52+
// 재고감소
53+
product.decreaseStock(itemCommand.quantity());
54+
55+
// OrderItem생성
56+
OrderItem orderItem = OrderItem.create(
57+
product.getId(),
58+
product.getName(),
59+
itemCommand.quantity(),
60+
product.getPrice());
61+
62+
order.addOrderItem(orderItem);
63+
orderItem.setOrder(order);
64+
}
65+
66+
//총 가격구하고
67+
long totalAmount = order.getOrderItems().stream()
68+
.mapToLong(OrderItem::getAmount)
69+
.sum();
70+
71+
order.updateTotalAmount(totalAmount);
72+
73+
pointService.usePoint(command.userId(), totalAmount);
74+
75+
//저장
76+
Order saved = orderService.createOrder(order);
77+
saved.updateStatus(OrderStatus.COMPLETE);
78+
79+
return OrderInfo.from(saved);
80+
}
81+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.loopers.application.order;
2+
3+
import com.loopers.domain.order.Order;
4+
import com.loopers.domain.order.OrderStatus;
5+
6+
import java.time.LocalDateTime;
7+
import java.util.List;
8+
9+
/**
10+
* packageName : com.loopers.application.order
11+
* fileName : OrderInfo
12+
* author : byeonsungmun
13+
* date : 2025. 11. 14.
14+
* description :
15+
* ===========================================
16+
* DATE AUTHOR NOTE
17+
* -------------------------------------------
18+
* 2025. 11. 14. byeonsungmun 최초 생성
19+
*/
20+
public record OrderInfo(
21+
Long orderId,
22+
String userId,
23+
Long totalAmount,
24+
OrderStatus status,
25+
LocalDateTime createdAt,
26+
List<OrderItemInfo> items
27+
) {
28+
public static OrderInfo from(Order order) {
29+
List<OrderItemInfo> itemInfos = order.getOrderItems().stream()
30+
.map(OrderItemInfo::from)
31+
.toList();
32+
33+
return new OrderInfo(
34+
order.getId(),
35+
order.getUserId(),
36+
order.getTotalAmount(),
37+
order.getStatus(),
38+
order.getCreatedAt(),
39+
itemInfos
40+
);
41+
}
42+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.loopers.application.order;
2+
3+
/**
4+
* packageName : com.loopers.application.order
5+
* fileName : OrderItemCommand
6+
* author : byeonsungmun
7+
* date : 2025. 11. 14.
8+
* description :
9+
* ===========================================
10+
* DATE AUTHOR NOTE
11+
* -------------------------------------------
12+
* 2025. 11. 14. byeonsungmun 최초 생성
13+
*/
14+
public record OrderItemCommand(
15+
Long productId,
16+
Long quantity
17+
) {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.loopers.application.order;
2+
3+
import com.loopers.domain.order.OrderItem;
4+
5+
/**
6+
* packageName : com.loopers.application.order
7+
* fileName : OrderInfo
8+
* author : byeonsungmun
9+
* date : 2025. 11. 13.
10+
* description :
11+
* ===========================================
12+
* DATE AUTHOR NOTE
13+
* -------------------------------------------
14+
* 2025. 11. 13. byeonsungmun 최초 생성
15+
*/
16+
public record OrderItemInfo(
17+
Long productId,
18+
String productName,
19+
Long quantity,
20+
Long price,
21+
Long amount
22+
) {
23+
public static OrderItemInfo from(OrderItem item) {
24+
return new OrderItemInfo(
25+
item.getProductId(),
26+
item.getProductName(),
27+
item.getQuantity(),
28+
item.getPrice(),
29+
item.getAmount()
30+
);
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.loopers.application.point;
2+
3+
import com.loopers.domain.point.Point;
4+
import com.loopers.domain.point.PointService;
5+
import com.loopers.interfaces.api.point.PointV1Dto;
6+
import com.loopers.support.error.CoreException;
7+
import com.loopers.support.error.ErrorType;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.stereotype.Component;
10+
11+
@RequiredArgsConstructor
12+
@Component
13+
public class PointFacade {
14+
private final PointService pointService;
15+
16+
public PointInfo getPoint(String userId) {
17+
Point point = pointService.findPointByUserId(userId);
18+
19+
if (point == null) {
20+
throw new CoreException(ErrorType.NOT_FOUND, "사용자 존재하지 않습니다.");
21+
}
22+
return PointInfo.from(point);
23+
}
24+
25+
public PointInfo chargePoint(PointV1Dto.ChargePointRequest request) {
26+
return PointInfo.from(pointService.chargePoint(request.userId(), request.chargeAmount()));
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.loopers.application.point;
2+
3+
import com.loopers.domain.point.Point;
4+
5+
public record PointInfo(String userId, Long amount) {
6+
public static PointInfo from(Point info) {
7+
return new PointInfo(
8+
info.getUserId(),
9+
info.getBalance()
10+
);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)