use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceImpl1 method findFiltered.
@Override
public List<OrderInfoDTO> findFiltered(User user, OrderFilterDTO dto, Pageable pageable) {
Specification<Order> spec;
if (user.getRole() == Role.MODERATOR) {
Long moderatorWarehouseId = user.getModerator().getWarehouseId();
if (dto.getWarehouseId() != null) {
if (!dto.getWarehouseId().equals(moderatorWarehouseId))
throw new CustomAccessDeniedException();
}
}
spec = OrderSpecifications.getFilterSpecification(dto);
return orderRepo.findAll(spec, pageable).stream().map(order -> convertToOrderInfoDTO(order)).collect(Collectors.toList());
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceImpl1 method changeClientRating.
@Override
public void changeClientRating(Order order, ChangeRatingDTO dto, User user) {
if (order.getCourier() == null || !user.getId().equals(order.getCourier().getId()))
throw new CustomAccessDeniedException();
order.setClientRating(dto.getRating());
orderRepo.save(order);
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class ProductPositionServiceImpl1 method getPositionsFromOrder.
@Override
public ProductPositionsFromOrderDTO getPositionsFromOrder(Order order) {
List<OrderProductPosition> ordersProductPositions = orderProductPositionRepo.findAllByOrder(order);
ProductPositionsFromOrderDTO dto = new ProductPositionsFromOrderDTO();
List<ProductPositionsFromOrderDTO.ProductPositionAmountPair> pairs = new ArrayList<>();
for (OrderProductPosition orderProductPosition : ordersProductPositions) {
pairs.add(new ProductPositionsFromOrderDTO.ProductPositionAmountPair(orderProductPosition.getProductPosition(), orderProductPosition.getAmount()));
}
dto.setProductPositions(pairs);
return dto;
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method changeOrderStatusAccessDeniedExTest.
@Test
public void changeOrderStatusAccessDeniedExTest() {
ChangeOrderStatusDTO dto = new ChangeOrderStatusDTO();
dto.setNewStatus(OrderStatus.DELIVERED);
Order fakeOrder = getFakeOrder();
Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(fakeOrder);
Assertions.assertThrows(CustomAccessDeniedException.class, new Executable() {
@Override
public void execute() throws Throwable {
orderService.changeOrderStatus(fakeOrder, getFakeCourier2().getUser(), dto);
}
});
}
use of com.ncedu.fooddelivery.api.v1.entities.order.Order in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method replaceCourierSuccessTest.
@Test
public void replaceCourierSuccessTest() {
User fakeUser = getFakeUserModerator();
Courier fakeCourier = getFakeCourier2();
Order fakeOrder = getFakeOrder();
Mockito.when(courierRepo.getWaitingCourierByWarehouse(1L)).thenReturn(fakeCourier);
orderService.replaceCourier(fakeOrder, fakeUser);
Assertions.assertEquals(fakeOrder.getCourier(), fakeCourier);
Mockito.verify(courierRepo, Mockito.times(1)).getWaitingCourierByWarehouse(1L);
}
Aggregations