Skip to content

Commit a8ae603

Browse files
authored
주문 생성 관련 에러 해ê결 (#396)
1 parent b77fa0e commit a8ae603

File tree

8 files changed

+315
-82
lines changed

8 files changed

+315
-82
lines changed

src/main/java/com/back/domain/cart/repository/CartRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public interface CartRepository extends JpaRepository<Cart, Long> {
6464
@Modifying
6565
@Query("DELETE FROM Cart c WHERE c.user = :user AND c.product.productUuid IN :productUuids")
6666
void deleteByUserAndProductUuidIn(@Param("user") User user, @Param("productUuids") List<java.util.UUID> productUuids);
67+
68+
/**
69+
* 주문 완료 후 펀딩 장바구니에서 제거 (Funding ID 기반)
70+
*/
71+
@Modifying
72+
@Query("DELETE FROM Cart c WHERE c.user = :user AND c.funding.id IN :fundingIds")
73+
void deleteByUserAndFundingIdIn(@Param("user") User user, @Param("fundingIds") List<Long> fundingIds);
6774
}

src/main/java/com/back/domain/cart/service/CartService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public List<CartResponseDto> getAllCartItems(User user, boolean validateForOrder
292292
public void validateCartItemsForOrder(User user, boolean isFullOrder) {
293293
List<Cart> cartItems = isFullOrder ?
294294
cartRepository.findByUserWithProduct(user) :
295-
cartRepository.findByUserAndIsSelectedTrue(user);
295+
cartRepository.findByUserAndIsSelectedTrueWithProduct(user);
296296

297297
if (cartItems.isEmpty()) {
298298
throw new ServiceException("CART_EMPTY", "주문할 장바구니 아이템이 없습니다.");

src/main/java/com/back/domain/funding/entity/Funding.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,19 @@ public void decreaseStock(int quantity) {
264264
this.soldCount += quantity;
265265
}
266266

267+
public void increaseStock(int quantity) {
268+
if (quantity <= 0) {
269+
throw new IllegalArgumentException("복원 수량은 0보다 커야 합니다.");
270+
}
271+
if (stock != null) {
272+
this.stock += quantity;
273+
}
274+
this.soldCount -= quantity;
275+
if (this.soldCount < 0) {
276+
this.soldCount = 0;
277+
}
278+
}
279+
267280
public boolean hasStock(int quantity) {
268281
return stock == null || stock >= quantity;
269282
}

src/main/java/com/back/domain/order/order/dto/request/OrderRequestDto.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,23 @@ public record OrderRequestDto(
3838
) {
3939

4040
/**
41-
* 주문 상품 요청 DTO
41+
* 주문 상품 요청 DTO (NORMAL/FUNDING 통합)
4242
*/
4343
public record OrderItemRequestDto(
44-
@NotNull(message = "상품 UUID는 필수입니다.")
44+
// NORMAL 상품용 (FUNDING일 때는 null 가능)
4545
UUID productUuid,
46-
46+
47+
// FUNDING 상품용 (NORMAL일 때는 null 가능)
48+
Long fundingId,
49+
Integer fundingPrice,
50+
Integer fundingStock,
51+
4752
@NotNull(message = "수량은 필수입니다.")
4853
Integer quantity,
49-
50-
String optionInfo
54+
55+
String optionInfo,
56+
57+
// 장바구니 타입: NORMAL 또는 FUNDING
58+
String cartType
5159
) {}
5260
}

0 commit comments

Comments
 (0)