use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method searchProductsSuccess.
@Test
public void searchProductsSuccess() {
Pageable pageable = PageRequest.of(0, 2);
Page<Product> productPage = ProductUtils.createPageWithMilkProducts(pageable);
String requestSearchPhrase = "Milk taste";
String perfectPhrase = "Milk:* & taste:*";
Long warehouseId = 4L;
Point geo = makeGeo();
WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
when(productRepoMock.searchProducts(perfectPhrase, warehouseId, pageable)).thenReturn(productPage);
SearchProductDTO searchDTO = createSearchProductDTO(requestSearchPhrase);
List<ProductDTO> resultList = productService.searchProducts(searchDTO, pageable);
List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productPage);
verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
verify(productRepoMock, times(1)).searchProducts(perfectPhrase, warehouseId, pageable);
assertEquals(resultList, perfectList);
}
use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductDTOByIDSuccess.
@Test
public void getProductDTOByIDSuccess() {
Long productId = 1L;
Product product = ProductUtils.createMilkInShowcase(productId);
when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
ProductDTO resultDTO = productService.getProductDTOById(productId);
ProductDTO perfectDTO = createProductDTO(product);
verify(productRepoMock, times(1)).findById(productId);
assertEquals(perfectDTO, resultDTO);
}
use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.
the class ProductUtils method createProductCreateDTO.
public static ProductCreateDTO createProductCreateDTO(Product p) {
ProductCreateDTO productDTO = new ProductCreateDTO();
productDTO.setDescription(p.getDescription());
productDTO.setPrice(p.getPrice());
productDTO.setName(p.getName());
productDTO.setInShowcase(p.getInShowcase());
productDTO.setWeight(p.getWeight());
productDTO.setExpirationDays(p.getExpirationDays());
return productDTO;
}
use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.
the class ProductUtils method createProductDTOListFromPage.
public static List<ProductDTO> createProductDTOListFromPage(Page<Product> page) {
List<Product> products = page.getContent();
List<ProductDTO> productsDTO = new ArrayList<>();
for (Product p : products) {
productsDTO.add(createProductDTO(p));
}
return productsDTO;
}
use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceImpl1 method convertToOrderInfoDTO.
public OrderInfoDTO convertToOrderInfoDTO(Order order) {
List<OrderProductPosition> orderProductPositions = orderProductPositionRepo.findAllByOrder(order);
List<OrderInfoDTO.ProductAmountPair> products = new ArrayList<>();
for (OrderProductPosition orderProductPosition : orderProductPositions) {
ProductDTO p = productMapper.mapToDTO(orderProductPosition.getProductPosition().getProduct());
Integer amount = orderProductPosition.getAmount();
products.add(new OrderInfoDTO.ProductAmountPair(p, amount));
}
return new OrderInfoDTO(order.getId(), order.getClient(), order.getAddress(), order.getCoordinates(), order.getWarehouse(), order.getCourier(), order.getStatus(), order.getDateStart(), order.getDateEnd(), order.getOverallCost(), order.getHighDemandCoeff(), order.getDiscount(), order.getPromoCodeId(), order.getClientRating(), order.getDeliveryRating(), products);
}
Aggregations