Skip to content

Commit 8630d7a

Browse files
authored
장바구니 주문 UUID 변경 (#364)
1 parent 71f7aa9 commit 8630d7a

File tree

9 files changed

+67
-48
lines changed

9 files changed

+67
-48
lines changed

src/main/java/com/back/domain/cart/dto/request/CartRequestDto.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
import jakarta.validation.constraints.Min;
55
import jakarta.validation.constraints.NotNull;
66

7+
import java.util.UUID;
8+
79
/**
810
* 장바구니 추가/수정 요청 DTO
9-
* - 일반 장바구니: productId, optionInfo 사용
11+
* - 일반 장바구니: productUuid, optionInfo 사용
1012
* - 펀딩 장바구니: fundingId, fundingPrice, fundingStock 사용
1113
*/
1214
@Schema(description = "장바구니 추가 요청")
1315
public record CartRequestDto(
14-
@Schema(description = "상품 ID (일반 장바구니만 필수)", example = "123", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
15-
Long productId, // 상품 ID (일반 장바구니만 사용)
16+
@Schema(description = "상품 UUID (일반 장바구니만 필수)", example = "550e8400-e29b-41d4-a716-446655440000", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
17+
UUID productUuid, // 상품 UUID (일반 장바구니만 사용)
1618

1719
@NotNull(message = "수량은 필수입니다")
1820
@Min(value = 1, message = "수량은 1개 이상이어야 합니다")
@@ -40,8 +42,8 @@ public record CartRequestDto(
4042
* 유효성 검증
4143
*/
4244
public void validate() {
43-
if ("NORMAL".equals(cartType) && productId == null) {
44-
throw new IllegalArgumentException("일반 장바구니는 productId가 필수입니다.");
45+
if ("NORMAL".equals(cartType) && productUuid == null) {
46+
throw new IllegalArgumentException("일반 장바구니는 productUuid가 필수입니다.");
4547
}
4648
if ("FUNDING".equals(cartType) && fundingId == null) {
4749
throw new IllegalArgumentException("펀딩 장바구니는 fundingId가 필수입니다.");

src/main/java/com/back/domain/cart/dto/response/CartResponseDto.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import com.back.domain.cart.entity.Cart;
44

55
import java.time.LocalDateTime;
6+
import java.util.UUID;
67

78
/**
89
* 장바구니 개별 상품 응답 DTO
910
*/
1011
public record CartResponseDto(
1112
Long cartId, // 장바구니 아이템 ID
12-
Long productId, // 상품 ID
13+
UUID productUuid, // 상품 UUID
1314
String productName, // 상품명
1415
String productImageUrl, // 상품 이미지 URL
1516
Integer price, // 상품 가격
@@ -33,7 +34,7 @@ public static CartResponseDto from(Cart cart) {
3334

3435
return new CartResponseDto(
3536
cart.getId(),
36-
productInfo.getId(),
37+
productInfo.getUuid(),
3738
productInfo.getName(),
3839
productInfo.getImageUrl(), // ProductInfo에서 이미지 URL 가져오기
3940
productInfo.getPrice(),

src/main/java/com/back/domain/cart/entity/Cart.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public ProductInfo getProductInfo() {
220220
// 펀딩 장바구니: Funding 정보 사용
221221
return new ProductInfo(
222222
this.funding.getId(),
223+
null, // 펀딩은 UUID 없음
223224
this.funding.getTitle(),
224225
this.fundingPrice != null ? this.fundingPrice : (int) this.funding.getPrice(),
225226
this.funding.getImageUrl() // Funding 이미지
@@ -232,6 +233,7 @@ public ProductInfo getProductInfo() {
232233
}
233234
return new ProductInfo(
234235
this.product.getId(),
236+
this.product.getProductUuid(),
235237
this.product.getName(),
236238
this.product.getPrice(),
237239
imageUrl // Product 첫 번째 이미지
@@ -246,18 +248,21 @@ public ProductInfo getProductInfo() {
246248
*/
247249
public static class ProductInfo {
248250
private final Long id;
251+
private final java.util.UUID uuid;
249252
private final String name;
250253
private final Integer price;
251254
private final String imageUrl;
252255

253-
public ProductInfo(Long id, String name, Integer price, String imageUrl) {
256+
public ProductInfo(Long id, java.util.UUID uuid, String name, Integer price, String imageUrl) {
254257
this.id = id;
258+
this.uuid = uuid;
255259
this.name = name;
256260
this.price = price;
257261
this.imageUrl = imageUrl;
258262
}
259263

260264
public Long getId() { return id; }
265+
public java.util.UUID getUuid() { return uuid; }
261266
public String getName() { return name; }
262267
public Integer getPrice() { return price; }
263268
public String getImageUrl() { return imageUrl; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public CartResponseDto addToCart(User user, CartRequestDto requestDto) {
5454
*/
5555
private CartResponseDto addNormalCart(User user, CartRequestDto requestDto, Cart.CartType cartType) {
5656
// 상품 존재 확인
57-
Product product = productRepository.findById(requestDto.productId())
57+
Product product = productRepository.findByProductUuid(requestDto.productUuid())
5858
.orElseThrow(() -> new ServiceException("PRODUCT_NOT_FOUND", "존재하지 않는 상품입니다."));
5959

6060
// 중복 확인

src/main/java/com/back/domain/order/order/dto/response/OrderResponseDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.math.BigDecimal;
77
import java.time.LocalDateTime;
88
import java.util.List;
9+
import java.util.UUID;
910

1011
/**
1112
* 주문 상세 응답 DTO
@@ -34,7 +35,7 @@ public record OrderResponseDto(
3435
*/
3536
public record OrderItemResponseDto(
3637
Long orderItemId,
37-
Long productId,
38+
UUID productUuid,
3839
String productName,
3940
String productThumbnailUrl,
4041
Integer quantity,

src/main/java/com/back/domain/order/order/service/OrderService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ private OrderResponseDto convertToOrderResponseDto(Order order) {
445445
List<OrderResponseDto.OrderItemResponseDto> orderItemDtos = order.getOrderItems().stream()
446446
.map(item -> new OrderResponseDto.OrderItemResponseDto(
447447
item.getId(),
448-
item.getProduct().getId(),
448+
item.getProduct().getProductUuid(),
449449
item.getProduct().getName(),
450450
getProductThumbnailUrl(item.getProduct()),
451451
item.getQuantity(),

src/test/java/com/back/domain/cart/controller/CartControllerTest.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.time.LocalDateTime;
2323
import java.util.Arrays;
2424
import java.util.List;
25+
import java.util.UUID;
2526

2627
import static org.mockito.ArgumentMatchers.any;
2728
import static org.mockito.ArgumentMatchers.eq;
@@ -57,6 +58,8 @@ class CartControllerTest {
5758
private CartRequestDto cartRequestDto;
5859
private CartResponseDto cartResponseDto;
5960
private CartListResponseDto cartListResponseDto;
61+
62+
private static final UUID TEST_PRODUCT_UUID = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
6063

6164
@BeforeEach
6265
void setUp() {
@@ -70,18 +73,18 @@ void setUp() {
7073
org.springframework.test.util.ReflectionTestUtils.setField(testUser, "id", 1L);
7174

7275
cartRequestDto = new CartRequestDto(
73-
1L, // productId
74-
2, // quantity
75-
"옵션정보", // optionInfo
76-
"NORMAL", // cartType
77-
null, // fundingId
78-
null, // fundingPrice
79-
null // fundingStock
76+
TEST_PRODUCT_UUID, // productUuid
77+
2, // quantity
78+
"옵션정보", // optionInfo
79+
"NORMAL", // cartType
80+
null, // fundingId
81+
null, // fundingPrice
82+
null // fundingStock
8083
);
8184

8285
cartResponseDto = new CartResponseDto(
8386
1L, // cartId
84-
1L, // productId
87+
TEST_PRODUCT_UUID, // productUuid
8588
"임시 상품명", // productName
8689
"test-image.jpg", // productImageUrl
8790
10000, // price
@@ -169,9 +172,9 @@ void updateQuantity_Success() throws Exception {
169172
Long cartId = 1L;
170173
Integer newQuantity = 3;
171174
CartResponseDto updatedCart = new CartResponseDto(
172-
cartId, // cartId
173-
1L, // productId
174-
"임시 상품명", // productName
175+
cartId, // cartId
176+
TEST_PRODUCT_UUID, // productUuid
177+
"임시 상품명", // productName
175178
"test-image.jpg", // productImageUrl
176179
10000, // price
177180
newQuantity, // quantity
@@ -246,9 +249,9 @@ void toggleSelection_Success() throws Exception {
246249
// given
247250
Long cartId = 1L;
248251
CartResponseDto toggledCart = new CartResponseDto(
249-
cartId, // cartId
250-
1L, // productId
251-
"임시 상품명", // productName
252+
cartId, // cartId
253+
TEST_PRODUCT_UUID, // productUuid
254+
"임시 상품명", // productName
252255
"test-image.jpg", // productImageUrl
253256
10000, // price
254257
2, // quantity
@@ -279,7 +282,7 @@ void getSelectedCartItems_Success() throws Exception {
279282
List<CartResponseDto> selectedItems = Arrays.asList(
280283
new CartResponseDto(
281284
1L, // cartId
282-
1L, // productId
285+
TEST_PRODUCT_UUID, // productUuid
283286
"테스트 상품1", // productName
284287
"test-image1.jpg", // productImageUrl
285288
10000, // price

src/test/java/com/back/domain/cart/service/CartServiceTest.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626
import java.util.Optional;
27+
import java.util.UUID;
2728

2829
import static org.assertj.core.api.Assertions.*;
2930
import static org.mockito.ArgumentMatchers.*;
@@ -57,6 +58,8 @@ class CartServiceTest {
5758
private Cart testFundingCart;
5859
private CartRequestDto normalCartRequestDto;
5960
private CartRequestDto fundingCartRequestDto;
61+
62+
private static final UUID TEST_PRODUCT_UUID = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
6063

6164
@BeforeEach
6265
void setUp() {
@@ -72,6 +75,7 @@ void setUp() {
7275
// 테스트용 상품 생성 (Mock 사용)
7376
testProduct = mock(Product.class);
7477
when(testProduct.getId()).thenReturn(1L);
78+
when(testProduct.getProductUuid()).thenReturn(TEST_PRODUCT_UUID);
7579
when(testProduct.getName()).thenReturn("테스트 상품");
7680
when(testProduct.getPrice()).thenReturn(10000);
7781
when(testProduct.getDiscountPrice()).thenReturn(10000);
@@ -112,18 +116,18 @@ void setUp() {
112116

113117
// 테스트용 요청 DTO 생성 (일반)
114118
normalCartRequestDto = new CartRequestDto(
115-
1L, // productId
116-
2, // quantity
117-
"일반 상품 옵션", // optionInfo
118-
"NORMAL", // cartType
119-
null, // fundingId
120-
null, // fundingPrice
121-
null // fundingStock
119+
TEST_PRODUCT_UUID, // productUuid
120+
2, // quantity
121+
"일반 상품 옵션", // optionInfo
122+
"NORMAL", // cartType
123+
null, // fundingId
124+
null, // fundingPrice
125+
null // fundingStock
122126
);
123127

124128
// 테스트용 요청 DTO 생성 (펀딩)
125129
fundingCartRequestDto = new CartRequestDto(
126-
null, // productId (펀딩은 필요 없음)
130+
null, // productUuid (펀딩은 필요 없음)
127131
1, // quantity
128132
null, // optionInfo (펀딩은 옵션 안씀)
129133
"FUNDING", // cartType
@@ -141,7 +145,7 @@ void setUp() {
141145
@DisplayName("장바구니에 새 상품 추가 성공")
142146
void addToCart_NewProduct_Success() {
143147
// Given
144-
given(productRepository.findById(1L)).willReturn(Optional.of(testProduct));
148+
given(productRepository.findByProductUuid(TEST_PRODUCT_UUID)).willReturn(Optional.of(testProduct));
145149
given(cartRepository.findByUserAndProductAndCartType(eq(testUser), any(Product.class), eq(Cart.CartType.NORMAL)))
146150
.willReturn(Optional.empty());
147151
given(cartRepository.save(any(Cart.class))).willReturn(testNormalCart);
@@ -155,7 +159,7 @@ void addToCart_NewProduct_Success() {
155159
assertThat(result.cartType()).isEqualTo("NORMAL");
156160
assertThat(result.optionInfo()).isEqualTo("일반 상품 옵션");
157161

158-
verify(productRepository).findById(1L);
162+
verify(productRepository).findByProductUuid(TEST_PRODUCT_UUID);
159163
verify(cartRepository).findByUserAndProductAndCartType(eq(testUser), any(Product.class), eq(Cart.CartType.NORMAL));
160164
verify(cartRepository).save(any(Cart.class));
161165
}
@@ -173,7 +177,7 @@ void addToCart_ExistingProduct_QuantityIncrease() {
173177
.optionInfo("기존 옵션")
174178
.build();
175179

176-
given(productRepository.findById(1L)).willReturn(Optional.of(testProduct));
180+
given(productRepository.findByProductUuid(TEST_PRODUCT_UUID)).willReturn(Optional.of(testProduct));
177181
given(cartRepository.findByUserAndProductAndCartType(eq(testUser), any(Product.class), eq(Cart.CartType.NORMAL)))
178182
.willReturn(Optional.of(existingCart));
179183
given(cartRepository.save(existingCart)).willReturn(existingCart);
@@ -191,7 +195,7 @@ void addToCart_ExistingProduct_QuantityIncrease() {
191195
@DisplayName("존재하지 않는 상품 추가 실패")
192196
void addToCart_ProductNotFound_ThrowException() {
193197
// Given
194-
given(productRepository.findById(1L)).willReturn(Optional.empty());
198+
given(productRepository.findByProductUuid(TEST_PRODUCT_UUID)).willReturn(Optional.empty());
195199

196200
// When & Then
197201
assertThatThrownBy(() -> cartService.addToCart(testUser, normalCartRequestDto))
@@ -206,16 +210,16 @@ void addToCart_ProductNotFound_ThrowException() {
206210
void addToCart_InvalidCartType_ThrowException() {
207211
// Given
208212
CartRequestDto invalidDto = new CartRequestDto(
209-
1L, // productId
210-
2, // quantity
211-
null, // optionInfo
212-
"INVALID", // cartType
213-
null, // fundingId
214-
null, // fundingPrice
215-
null // fundingStock
213+
TEST_PRODUCT_UUID, // productUuid
214+
2, // quantity
215+
null, // optionInfo
216+
"INVALID", // cartType
217+
null, // fundingId
218+
null, // fundingPrice
219+
null // fundingStock
216220
);
217221

218-
given(productRepository.findById(1L)).willReturn(Optional.of(testProduct));
222+
given(productRepository.findByProductUuid(TEST_PRODUCT_UUID)).willReturn(Optional.of(testProduct));
219223

220224
// When & Then
221225
assertThatThrownBy(() -> cartService.addToCart(testUser, invalidDto))

src/test/java/com/back/domain/order/order/controller/OrderControllerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.math.BigDecimal;
2020
import java.time.LocalDateTime;
2121
import java.util.List;
22+
import java.util.UUID;
2223

2324
import static org.assertj.core.api.Assertions.assertThat;
2425
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -38,6 +39,8 @@ class OrderControllerTest {
3839
private OrderRequestDto orderRequestDto;
3940
private OrderCancelRequestDto orderCancelRequestDto;
4041
private OrderResponseDto orderResponseDto;
42+
43+
private static final UUID TEST_PRODUCT_UUID = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
4144

4245
@BeforeEach
4346
void setUp() throws Exception {
@@ -56,7 +59,7 @@ void setUp() throws Exception {
5659
orderRequestDto = new OrderRequestDto(
5760
List.of( // orderItems
5861
new OrderRequestDto.OrderItemRequestDto(
59-
java.util.UUID.randomUUID(), // productUuid
62+
TEST_PRODUCT_UUID, // productUuid
6063
2, // quantity
6164
"빨강, L" // optionInfo
6265
)
@@ -96,7 +99,7 @@ void setUp() throws Exception {
9699
List.of( // orderItems
97100
new OrderResponseDto.OrderItemResponseDto(
98101
1L, // orderItemId
99-
1L, // productId
102+
TEST_PRODUCT_UUID, // productUuid
100103
"테스트 상품", // productName
101104
"http://example.com/image.jpg", // productThumbnailUrl
102105
2, // quantity

0 commit comments

Comments
 (0)