Skip to content

Commit c5754ff

Browse files
committed
fix : PR코드 수정
1 parent 1087ea2 commit c5754ff

19 files changed

Lines changed: 59 additions & 51 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/like/LikeFacade.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.loopers.domain.like.LikeService;
44
import lombok.RequiredArgsConstructor;
55
import org.springframework.stereotype.Component;
6-
import org.springframework.transaction.annotation.Transactional;
76

87
/**
98
* packageName : com.loopers.application.like
@@ -18,7 +17,6 @@
1817
*/
1918
@Component
2019
@RequiredArgsConstructor
21-
@Transactional
2220
public class LikeFacade {
2321

2422
private final LikeService likeService;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.loopers.domain.order.OrderItem;
55
import com.loopers.domain.order.OrderService;
66
import com.loopers.domain.order.OrderStatus;
7-
import com.loopers.domain.point.Point;
87
import com.loopers.domain.point.PointService;
98
import com.loopers.domain.product.Product;
109
import com.loopers.domain.product.ProductService;
@@ -40,7 +39,7 @@ public class OrderFacade {
4039
public OrderInfo createOrder(CreateOrderCommand command) {
4140

4241
if (command == null || command.items() == null || command.items().isEmpty()) {
43-
throw new CoreException(ErrorType.NOT_FOUND, "상품 정보가 비어있습니다");
42+
throw new CoreException(ErrorType.BAD_REQUEST, "상품 정보가 비어있습니다");
4443
}
4544

4645
Order order = Order.create(command.userId());
@@ -71,8 +70,7 @@ public OrderInfo createOrder(CreateOrderCommand command) {
7170

7271
order.updateTotalAmount(totalAmount);
7372

74-
Point point = pointService.findPointByUserId(command.userId());
75-
point.use(totalAmount);
73+
pointService.usePoint(command.userId(), totalAmount);
7674

7775
//저장
7876
Order saved = orderService.createOrder(order);

apps/commerce-api/src/main/java/com/loopers/application/product/ProductFacade.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public class ProductFacade {
3131
private final LikeService likeService;
3232
private final ProductDomainService productDomainService;
3333

34-
public Page<ProductInfo> getProducts(Pageable pageable) {
35-
return productService.getProducts(pageable)
34+
public Page<ProductInfo> getProducts(String sort, Pageable pageable) {
35+
return productService.getProducts(sort ,pageable)
3636
.map(product -> {
37-
Brand brand = brandService.getBrand(product.getId());
37+
Brand brand = brandService.getBrand(product.getBrandId());
3838
long likeCount = likeService.countByProductId(product.getId());
3939
return ProductInfo.of(product, brand, likeCount);
4040
});

apps/commerce-api/src/main/java/com/loopers/domain/brand/Brand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static Brand create(String name) {
4040

4141
private String requireValidName(String name) {
4242
if (name == null || name.isEmpty()) {
43-
throw new CoreException(ErrorType.BAD_REQUEST, "상품명 비어 있을수 없습니다.");
43+
throw new CoreException(ErrorType.BAD_REQUEST, "브랜드명은 비어 있을 수 없습니다.");
4444
}
4545
return name.trim();
4646
}

apps/commerce-api/src/main/java/com/loopers/domain/brand/BrandService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class BrandService {
2323

2424
private final BrandRepository brandRepository;
2525

26-
@Transactional
2726
public void save(Brand brand) {
2827
brandRepository.save(brand);
2928
}

apps/commerce-api/src/main/java/com/loopers/domain/order/Order.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static Order create(String userId) {
5858
}
5959

6060
public void addOrderItem(OrderItem orderItem) {
61+
orderItem.setOrder(this);
6162
this.orderItems.add(orderItem);
6263
}
6364

apps/commerce-api/src/main/java/com/loopers/domain/point/Point.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public void charge(Long chargeAmount) {
4242
throw new CoreException(ErrorType.BAD_REQUEST, "0원 이하로 포인트를 충전 할수 없습니다.");
4343
}
4444
this.balance += chargeAmount;
45-
new Point(this.userId, this.balance);
4645
}
4746

4847
public void use(Long useAmount) {

apps/commerce-api/src/main/java/com/loopers/domain/point/PointService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public Point usePoint(String userId, Long useAmount) {
3030
.orElseThrow(() -> new CoreException(ErrorType.NOT_FOUND, "포인트 정보를 찾을 수 없습니다."));
3131

3232
if (useAmount == null || useAmount <= 0) {
33-
throw new CoreException(ErrorType.NOT_FOUND, "차감할 포인트는 1 이상이어야 합니다.");
33+
throw new CoreException(ErrorType.BAD_REQUEST, "차감할 포인트는 1 이상이어야 합니다.");
3434
}
3535

3636
if (point.getBalance() < useAmount) {
37-
throw new CoreException(ErrorType.NOT_FOUND, "포인트가 부족합니다.");
37+
throw new CoreException(ErrorType.BAD_REQUEST, "포인트가 부족합니다.");
3838
}
3939

4040
point.use(useAmount);

apps/commerce-api/src/main/java/com/loopers/domain/product/Product.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ private Long requireValidPrice(Long price) {
8383
return price;
8484
}
8585

86-
public Long requireValidLikeCount(Long likeCount) {
86+
private Long requireValidLikeCount(Long likeCount) {
8787
if (likeCount == null || likeCount < 0) {
8888
throw new CoreException(ErrorType.BAD_REQUEST, "좋아요 개수는 0개 미만으로 설정할 수 없습니다.");
8989
}
9090
return likeCount;
9191
}
9292

9393
private Long requireValidStock(Long stock) {
94+
if (stock == null) {
95+
throw new CoreException(ErrorType.BAD_REQUEST, "상품 재고는 필수입니다.");
96+
}
9497
if (stock < 0) {
9598
throw new CoreException(ErrorType.BAD_REQUEST, "상품 재고는 0 미만으로 설정할 수 없습니다.");
9699
}

apps/commerce-api/src/main/java/com/loopers/domain/product/ProductDomainService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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
/**
1213
* packageName : com.loopers.domain.product
@@ -27,6 +28,7 @@ public class ProductDomainService {
2728
private final BrandRepository brandRepository;
2829
private final LikeRepository likeRepository;
2930

31+
@Transactional(readOnly = true)
3032
public ProductDetail getProductDetail(Long id) {
3133
Product product = productRepository.findById(id)
3234
.orElseThrow(() -> new CoreException(ErrorType.NOT_FOUND, "상품을 찾을 수 없습니다."));

0 commit comments

Comments
 (0)