Search in sources :

Example 16 with Order

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());
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) OrderProductPositionRepo(com.ncedu.fooddelivery.api.v1.repos.orderProductPosition.OrderProductPositionRepo) java.util(java.util) CoordsDTO(com.ncedu.fooddelivery.api.v1.dto.CoordsDTO) com.ncedu.fooddelivery.api.v1.entities(com.ncedu.fooddelivery.api.v1.entities) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) PrecisionModel(com.vividsolutions.jts.geom.PrecisionModel) com.ncedu.fooddelivery.api.v1.dto.order(com.ncedu.fooddelivery.api.v1.dto.order) OrderCostChangedEx(com.ncedu.fooddelivery.api.v1.errors.orderRegistration.OrderCostChangedEx) OrderSpecifications(com.ncedu.fooddelivery.api.v1.specifications.OrderSpecifications) NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Service(org.springframework.stereotype.Service) com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO(com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO) Geometry(com.vividsolutions.jts.geom.Geometry) Pageable(org.springframework.data.domain.Pageable) OrderProductPosition(com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition) ProductRepo(com.ncedu.fooddelivery.api.v1.repos.ProductRepo) Coordinate(com.vividsolutions.jts.geom.Coordinate) ProductMapper(com.ncedu.fooddelivery.api.v1.mappers.ProductMapper) Predicate(java.util.function.Predicate) OrderRepo(com.ncedu.fooddelivery.api.v1.repos.order.OrderRepo) WarehouseService(com.ncedu.fooddelivery.api.v1.services.WarehouseService) WarehouseInfoDTO(com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO) CourierRepo(com.ncedu.fooddelivery.api.v1.repos.CourierRepo) ProductPositionRepo(com.ncedu.fooddelivery.api.v1.repos.productPosition.ProductPositionRepo) CourierAvailabilityEx(com.ncedu.fooddelivery.api.v1.errors.orderRegistration.CourierAvailabilityEx) OrderService(com.ncedu.fooddelivery.api.v1.services.OrderService) Collectors(java.util.stream.Collectors) Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ProductAvailabilityEx(com.ncedu.fooddelivery.api.v1.errors.orderRegistration.ProductAvailabilityEx) ProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO) Specification(org.springframework.data.jpa.domain.Specification) WarehouseCoordsBindingEx(com.ncedu.fooddelivery.api.v1.errors.orderRegistration.WarehouseCoordsBindingEx) ProductPosition(com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition) CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) com.ncedu.fooddelivery.api.v1.errors.badrequest(com.ncedu.fooddelivery.api.v1.errors.badrequest) CourierService(com.ncedu.fooddelivery.api.v1.services.CourierService) Transactional(org.springframework.transaction.annotation.Transactional) CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)

Example 17 with Order

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);
}
Also used : CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)

Example 18 with 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;
}
Also used : OrderProductPosition(com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition) ProductPositionsFromOrderDTO(com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsFromOrderDTO)

Example 19 with Order

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);
        }
    });
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Executable(org.junit.jupiter.api.function.Executable) ChangeOrderStatusDTO(com.ncedu.fooddelivery.api.v1.dto.order.ChangeOrderStatusDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with Order

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);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)19 Test (org.junit.jupiter.api.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)7 Executable (org.junit.jupiter.api.function.Executable)7 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)6 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)4 ProductPositionsShipmentDTO (com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsShipmentDTO)2 com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO)2 ChangeOrderStatusDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeOrderStatusDTO)2 ChangeRatingDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO)2 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)2 Warehouse (com.ncedu.fooddelivery.api.v1.entities.Warehouse)2 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)2 CourierAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.CourierAvailabilityEx)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)1 ProductPositionsFromOrderDTO (com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsFromOrderDTO)1 com.ncedu.fooddelivery.api.v1.dto.order (com.ncedu.fooddelivery.api.v1.dto.order)1