use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method replaceCourierReplaceExTest.
@Test
public void replaceCourierReplaceExTest() {
User fakeUser = getFakeUserModerator();
Courier mockCourier = Mockito.mock(Courier.class);
Order fakeOrder = getFakeOrder();
fakeOrder.setStatus(OrderStatus.DELIVERED);
Assertions.assertThrows(CourierReplaceException.class, new Executable() {
@Override
public void execute() throws Throwable {
orderService.replaceCourier(fakeOrder, fakeUser);
}
});
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method changeCourierRatingCourierNotSetTest.
@Test
public void changeCourierRatingCourierNotSetTest() {
User fakeUser = getFakeUserClient();
ChangeRatingDTO fakeDto = new ChangeRatingDTO();
Order fakeOrder = getFakeOrder();
fakeOrder.setCourier(null);
Assertions.assertThrows(CourierNotSetException.class, new Executable() {
@Override
public void execute() throws Throwable {
orderService.changeDeliveryRating(fakeOrder, fakeDto, fakeUser);
}
});
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method changeCourierRatingSuccessTest.
@Test
public void changeCourierRatingSuccessTest() {
User fakeUser = getFakeUserClient();
ChangeRatingDTO fakeDto = new ChangeRatingDTO();
fakeDto.setRating(new BigDecimal(4.5));
Order fakeOrder = getFakeOrder();
Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(fakeOrder);
orderService.changeDeliveryRating(fakeOrder, fakeDto, fakeUser);
Assertions.assertTrue(fakeOrder.getDeliveryRating().equals(new BigDecimal(4.5)));
Mockito.verify(orderRepo, Mockito.times(1)).save(fakeOrder);
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceImpl1 method buildOrder.
private Order buildOrder(User user, Geometry coords, CreateOrderDTO dto, Map<Long, Double> productPosPriceMap, Map<Long, Integer> productPosAmountMap) {
Order order = new Order();
order.setDiscount(dto.getDiscount());
order.setHighDemandCoeff(dto.getHighDemandCoeff());
order.setOverallCost(dto.getOverallCost());
order.setClient(user.getClient());
order.setWarehouse(warehouseService.findById(dto.getWarehouseId()));
order.setAddress(dto.getAddress());
order.setCoordinates(coords);
order.setStatus(OrderStatus.CREATED);
order.setDateStart(LocalDateTime.now());
order = orderRepo.save(order);
// adding records in DB table 'orders_product_positions'
for (Long productPositionId : productPosAmountMap.keySet()) {
orderProductPositionRepo.save(new OrderProductPosition(order, productPositionRepo.findById(productPositionId).get(), productPosAmountMap.get(productPositionId), productPosPriceMap.get(productPositionId)));
}
return orderRepo.save(order);
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order 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