Skip to content

Commit

Permalink
fix: 필드 이름 order->productOrder로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
parkcoldroad committed Nov 27, 2023
1 parent 03d4648 commit 98f6c68
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static CustomProduct getCustomProduct() {

public void init() {
try {
Product product = Product.create(LIBERTY, ProductState.ON_SALE, 100L, true);
Product product = Product.create(LIBERTY, ProductState.ON_SALE, 100L, true, 1);
Field id = product.getClass().getDeclaredField("id");
id.setAccessible(true);
id.set(product, "LIB-001");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.liberty52.main.service.applicationservice;

public interface ProductOrderModifyService {
void modifyProductOrder(String[] productIdList);
void modifyProductOrder(String[] productIdList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Product createProductByAdmin(String role, ProductCreateRequestDto product
.price(productRequestDto.getPrice())
.isCustom(productRequestDto.getIsCustom())
.pictureUrl(imageUrl)
.order(productRequestDto.getOrder())
.productOrder(productRequestDto.getProductOrder())
.build();

return productRepository.save(newProduct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<ProductInfoRetrieveResponseDto> retrieveProductListByAdmin(String ro
for (Product product : productList) {
List<Review> productReviewList = reviewList.stream().filter(r -> r.getCustomProduct().getProduct().equals(product)).collect(Collectors.toList());
float meanRate = product.getRate(productReviewList);
dto.add(ProductInfoRetrieveResponseDto.of(product.getId(), product.getPictureUrl(), product.getName(), product.getPrice(), meanRate, productReviewList.size(), product.isCustom(), product.getContent(), product.getProductState(), product.getOrder()));
dto.add(ProductInfoRetrieveResponseDto.of(product.getId(), product.getPictureUrl(), product.getName(), product.getPrice(), meanRate, productReviewList.size(), product.isCustom(), product.getContent(), product.getProductState(), product.getProductOrder()));
}
return dto;
}
Expand All @@ -80,7 +80,7 @@ public ProductInfoRetrieveResponseDto retrieveProductByAdmin(String role, String
Product product = productRepository.findById(productId).orElseThrow(() -> new ResourceNotFoundException("product", "id", productId));
List<Review> productReviewList = reviewRepository.findByCustomProduct_Product(product);
float meanRate = product.getRate(productReviewList);
return ProductInfoRetrieveResponseDto.of(product.getId(), product.getPictureUrl(), product.getName(), product.getPrice(), meanRate, productReviewList.size(), product.isCustom(), product.getContent(), product.getProductState(), product.getOrder());
return ProductInfoRetrieveResponseDto.of(product.getId(), product.getPictureUrl(), product.getName(), product.getPrice(), meanRate, productReviewList.size(), product.isCustom(), product.getContent(), product.getProductState(), product.getProductOrder());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
@RequiredArgsConstructor
public class ProductOrderModifyServiceImpl implements ProductOrderModifyService {

private final ProductRepository productRepository;
private final ProductRepository productRepository;

@Override
public void modifyProductOrder(String[] productIdList) {
for (int i = 0; i < productIdList.length; i++) {
String productId = productIdList[i];
Product product = productRepository.findById(productId)
.orElseThrow(() -> new ResourceNotFoundException("Product", "ID", productId));
product.updateOrder(i + 1);
}
}
@Override
public void modifyProductOrder(String[] productIdList) {
for (int i = 0; i < productIdList.length; i++) {
String productId = productIdList[i];
Product product = productRepository.findById(productId)
.orElseThrow(() -> new ResourceNotFoundException("Product", "ID", productId));
product.updateProductOrder(i + 1);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public class ProductCreateRequestDto {
private Boolean isCustom;

@Min(1)
private Integer order;
private Integer productOrder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
@NoArgsConstructor
public class ProductInfoRetrieveResponseDto {

String id;
String pictureUrl;
String name;
long price;
float meanRating;
int ratingCount;
boolean isCustom;
String content;
private ProductState state;
private int order;
String id;
String pictureUrl;
String name;
long price;
float meanRating;
int ratingCount;
boolean isCustom;
String content;
private ProductState state;
private int order;

public static ProductInfoRetrieveResponseDto of(String id, String pictureUrl, String name, long price,
float meanRating, int ratingCount, boolean isCustom, String content, ProductState state, int order) {
return new ProductInfoRetrieveResponseDto(id, pictureUrl, name, price, meanRating, ratingCount, isCustom,
content, state, order);
}
public static ProductInfoRetrieveResponseDto of(String id, String pictureUrl, String name, long price,
float meanRating, int ratingCount, boolean isCustom, String content, ProductState state, int order) {
return new ProductInfoRetrieveResponseDto(id, pictureUrl, name, price, meanRating, ratingCount, isCustom,
content, state, order);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,27 @@ public class Product {
@Column(length = 10000)
private String content = "";
@Column(nullable = false)
private Integer order;
private Integer productOrder;

@OneToOne(cascade = CascadeType.ALL, mappedBy = "product")
private ProductDeliveryOption deliveryOption;

@Builder
private Product(String name, ProductState productState, Long price, boolean isCustom, String pictureUrl, Integer order) {
private Product(String name, ProductState productState, Long price, boolean isCustom, String pictureUrl, Integer productOrder) {
this.name = name;
this.productState = productState;
this.price = price;
this.isCustom = isCustom;
this.pictureUrl = pictureUrl;
this.order = order;
this.productOrder = productOrder;
}

public static Product create(String name, ProductState state, Long price, boolean isCustom) {
public static Product create(String name, ProductState state, Long price, boolean isCustom, Integer productOrder) {
return builder().name(name)
.productState(state)
.price(price)
.isCustom(isCustom)
.productOrder(productOrder)
.build();
}

Expand Down Expand Up @@ -97,7 +98,7 @@ public float getRate(List<Review> productReviewList) {
}
}

public void updateOrder(int order) {
this.order = order;
public void updateProductOrder(int productOrder) {
this.productOrder = productOrder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CartItemRemoveServiceImplTest extends MockS3Test {

@BeforeEach
void beforeEach() {
Product product = MockFactory.createProduct("Liberty 52_Frame", ProductState.ON_SALE, 10_000_000L, true);
Product product = MockFactory.createProduct("Liberty 52_Frame", ProductState.ON_SALE, 10_000_000L, true, 1);
product = productRepository.save(product);

ProductOption displayOption = MockFactory.createProductOption("거치 방식", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void setMockCustomProductData() throws IOException, NoSuchFieldException, Illega
new FileInputStream(mockImageUrl));

Product product = MockFactory.createProduct("Liberty 52_Frame", ProductState.ON_SALE,
10_000_000L, true);
10_000_000L, true,1);
productRepository.save(product);

order = MockFactory.createOrder(MOCK_AUTH_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ void init() {
CartItemRequest dto3 = new CartItemRequest().builder().productId("LIB-001").quantity(4).optionDetailIds(optionErr).build();

MockMultipartFile imageFile = new MockMultipartFile("image", "test.png", "image/jpeg", new FileInputStream("src/test/resources/static/test.jpg"));
given(productRepository.findById("LIB-001")).willReturn(Optional.ofNullable(Product.create("Liberty 52_Frame",ProductState.ON_SALE,100L,true)));
given(productRepository.findById("LIB-001")).willReturn(Optional.ofNullable(Product.create("Liberty 52_Frame",ProductState.ON_SALE,100L,true,1)));
given(optionDetailRepository.findById("OPT-002")).willReturn(Optional.ofNullable(OptionDetail.create("벽걸이형", 100, true, 100)));

given(cartRepository.save(any())).willReturn(Cart.create("testId"));

given(productRepository.findById("LIB-001")).willReturn(Optional.ofNullable(Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true)));
given(productRepository.findById("LIB-001")).willReturn(Optional.ofNullable(Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true,1)));

given(customProductRepository.save(any())).willReturn(null);
given(customProductOptionRepository.save(any())).willReturn(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CartItemRetrieveServiceMockTest extends MockS3Test {

@BeforeEach
void init() {
Product product = Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true);
Product product = Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true,1);

ProductOption option1 = ProductOption.create("거치 방식", true, true);
option1.associate(product);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class CartItemSchedulerServiceMockTest extends MockS3Test {

@BeforeEach
void init() {
Product product = Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true);
Product product = Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true,1);

ProductOption option1 = ProductOption.create("거치 방식", true, true);
option1.associate(product);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void init() {

given(cartRepository.save(any())).willReturn(Cart.create("testId"));

given(productRepository.findById("LIB-002")).willReturn(Optional.ofNullable(Product.create("Liberty 52_Frame", ProductState.ON_SALE,100L,false)));
given(productRepository.findById("LIB-002")).willReturn(Optional.ofNullable(Product.create("Liberty 52_Frame", ProductState.ON_SALE,100L,false,1)));

given(customLicenseOptionRepository.save(any())).willReturn(null);
given(licenseOptionDetailRepository.findById("licenseOption")).willReturn(Optional.ofNullable(LicenseOptionDetail.create("그림명", "작가", 100, true, "url", 100, LocalDate.now(), LocalDate.now())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void retrieveLicenseProductOptionInfoTest() {
LocalDate startDate = LocalDate.of(2023, 1, 1);
LocalDate endDate = startDate.plusDays(10);

Product product = Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true);
Product product = Product.create("Liberty 52_Frame", ProductState.ON_SALE, 100L, true, 1);

ProductOption option1 = ProductOption.create("거치 방식", true, true);
option1.associate(product);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@

@ExtendWith(MockitoExtension.class)
class ProductOrderModifyMockTest {
@InjectMocks
ProductOrderModifyServiceImpl productOrderModifyService;

@Mock
ProductRepository productRepository;

@Test
void 상품순서변경() {
//given
Product product1 = MockFactory.createProduct("Liberty52", ProductState.ON_SALE, 100L, true, 1);
Product product2 = MockFactory.createProduct("Liberty53", ProductState.ON_SALE, 100L, true, 2);
Product product3 = MockFactory.createProduct("Liberty54", ProductState.ON_SALE, 100L, true, 3);

given(productRepository.findById(product1.getId())).willReturn(Optional.of(product1));
given(productRepository.findById(product2.getId())).willReturn(Optional.of(product2));
given(productRepository.findById(product3.getId())).willReturn(Optional.of(product3));

String[] productIdList = {product2.getId(), product3.getId(), product1.getId()};
//when
productOrderModifyService.modifyProductOrder(productIdList);
//then
Assertions.assertEquals(1, product2.getOrder());
Assertions.assertEquals(2, product3.getOrder());
Assertions.assertEquals(3, product1.getOrder());
}
@InjectMocks
ProductOrderModifyServiceImpl productOrderModifyService;

@Mock
ProductRepository productRepository;

@Test
void 상품순서변경() {
//given
Product product1 = MockFactory.createProduct("Liberty52", ProductState.ON_SALE, 100L, true, 1);
Product product2 = MockFactory.createProduct("Liberty53", ProductState.ON_SALE, 100L, true, 2);
Product product3 = MockFactory.createProduct("Liberty54", ProductState.ON_SALE, 100L, true, 3);

given(productRepository.findById(product1.getId())).willReturn(Optional.of(product1));
given(productRepository.findById(product2.getId())).willReturn(Optional.of(product2));
given(productRepository.findById(product3.getId())).willReturn(Optional.of(product3));

String[] productIdList = {product2.getId(), product3.getId(), product1.getId()};
//when
productOrderModifyService.modifyProductOrder(productIdList);
//then
Assertions.assertEquals(1, product2.getProductOrder());
Assertions.assertEquals(2, product3.getProductOrder());
Assertions.assertEquals(3, product1.getProductOrder());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.liberty52.main.service.applicationservice.ProductCreateService;
import com.liberty52.main.service.applicationservice.ProductModifyService;
import com.liberty52.main.service.applicationservice.ProductOrderModifyService;
import com.liberty52.main.service.applicationservice.ProductRemoveService;
import com.liberty52.main.service.controller.dto.ProductCreateRequestDto;
import com.liberty52.main.service.entity.ProductState;
Expand All @@ -26,7 +27,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(ProductAdminController.class)
public class ProductAdminControllerTest {
class ProductAdminControllerTest {
final String testProductId = "LIB-001";
@Autowired
private MockMvc mockMvc;
Expand All @@ -40,6 +41,8 @@ public class ProductAdminControllerTest {
private ProductModifyService productModifyService;
@MockBean
private ProductRemoveService productRemoveService;
@MockBean
private ProductOrderModifyService productOrderModifyService;

@Test
void 상품추가_성공() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,22 @@ public static CustomProductOption createCustomProductOption(CustomProduct cp, Op
return cpo;
}

public static Product createProduct(String name, ProductState state, Long price, boolean isPremium) {
return Product.create(name, state, price, isPremium);
}

public static Product createProduct(String name, ProductState state, Long price, boolean isPremium, int order) {
return Product.builder()
.name(name)
.productState(state)
.price(price)
.isCustom(isPremium)
.order(order)
.productOrder(order)
.build();
}

public static Product createProduct(String name) {
return createProduct(name, ProductState.ON_SALE, 10_000_000L, true);
return createProduct(name, ProductState.ON_SALE, 10_000_000L, true, 1);
}

public static Product createProduct(String name, Long price) {
return createProduct(name, ProductState.ON_SALE, price, true);
return createProduct(name, ProductState.ON_SALE, price, true, 1);
}

public static ProductOption createProductOption(String name, boolean require) {
Expand Down

0 comments on commit 98f6c68

Please sign in to comment.