From 1f5a6493933829033096f75365823b22f449cc90 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Sat, 17 May 2025 16:36:09 +0300 Subject: [PATCH 1/6] feat: add courier assignment event consumer (not working yet) --- pom.xml | 2 +- .../podzilla/courier/CourierApplication.java | 2 ++ .../controllers/DeliveryTaskController.java | 20 +++++------ .../CourierAssignmentEventConsumer.java | 26 +++++++++++++++ .../delivery_task/DeliveryTaskService.java | 33 ++++++++++--------- 5 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java diff --git a/pom.xml b/pom.xml index a16c4fb..9c12dc2 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ com.github.Podzilla podzilla-utils-lib - v1.1.6 + v1.1.7 diff --git a/src/main/java/com/podzilla/courier/CourierApplication.java b/src/main/java/com/podzilla/courier/CourierApplication.java index 8f346c2..8ed5d3f 100644 --- a/src/main/java/com/podzilla/courier/CourierApplication.java +++ b/src/main/java/com/podzilla/courier/CourierApplication.java @@ -2,10 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; @EnableMongoRepositories(basePackages = "com.podzilla.courier.repositories") @SpringBootApplication +@ComponentScan(basePackages = {"com.podzilla.courier", "com.podzilla.mq"}) public class CourierApplication { public static void main(String[] args) { diff --git a/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java b/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java index f8e6851..56dcec7 100644 --- a/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java +++ b/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java @@ -115,28 +115,28 @@ public ResponseEntity> getDeliveryTasksByOrderId( return ResponseEntity.ok(deliveryTaskService.getDeliveryTasksByOrderId(orderId)); } - @GetMapping("/{id}/location") + @GetMapping("/{orderId}/location") @Operation(summary = "Get task location", description = "Retrieves coordinates of a delivery task") @ApiResponse(responseCode = "200", description = "Location retrieved successfully") @ApiResponse(responseCode = "404", description = "Task not found") public ResponseEntity> getDeliveryTaskLocation( - @Parameter(description = "ID of the delivery task") - @PathVariable final String id) { - LOGGER.info("Received request to get the location of delivery task with id {}", id); - return ResponseEntity.ok(deliveryTaskService.getDeliveryTaskLocation(id)); + @Parameter(description = "ID of the order") + @PathVariable final String orderId) { + LOGGER.info("Received request to get the location of delivery task with order id {}", orderId); + return ResponseEntity.ok(deliveryTaskService.getDeliveryTaskLocation(orderId)); } - @PatchMapping("/{id}/location") + @PatchMapping("/{orderId}/location") @Operation(summary = "Update task location", description = "Updates coordinates of a delivery task") @ApiResponse(responseCode = "200", description = "Location updated successfully") public ResponseEntity updateDeliveryTaskLocation( - @Parameter(description = "ID of the delivery task") - @PathVariable final String id, + @Parameter(description = "ID of the order") + @PathVariable final String orderId, @RequestBody(description = "New coordinates data") @org.springframework.web.bind.annotation.RequestBody final LocationUpdateDto locationUpdateDto) { - LOGGER.info("Received request to update the location of delivery task with id {}", id); + LOGGER.info("Received request to update the location of delivery task with order id {}", orderId); return ResponseEntity.ok(deliveryTaskService.updateDeliveryTaskLocation( - id, + orderId, locationUpdateDto.getLatitude(), locationUpdateDto.getLongitude())); } diff --git a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java new file mode 100644 index 0000000..6412748 --- /dev/null +++ b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java @@ -0,0 +1,26 @@ +package com.podzilla.courier.events; + +import com.podzilla.courier.services.delivery_task.DeliveryTaskService; +import com.podzilla.mq.EventsConstants; +import com.podzilla.mq.events.BaseEvent; +import com.podzilla.mq.events.OrderAssignedToCourierEvent; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +@Component +public class CourierAssignmentEventConsumer { + final DeliveryTaskService deliveryTaskService; + + public CourierAssignmentEventConsumer(DeliveryTaskService deliveryTaskService) { + this.deliveryTaskService = deliveryTaskService; + } + + @RabbitListener(queues = EventsConstants.COURIER_ORDER_EVENT_QUEUE) + public void handleEvent(BaseEvent event) { + if(event instanceof OrderAssignedToCourierEvent) { + OrderAssignedToCourierEvent courierEvent = (OrderAssignedToCourierEvent) event; +// deliveryTaskService.createDeliveryTask(courierEvent.getOrderId(), courierEvent.getCourierId(), +// courierEvent.getPrice(), courierEvent.getOrderLatitude(), courierEvent.getOrderLongitude()); + } + } +} diff --git a/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java b/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java index 7be93de..c117ab4 100644 --- a/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java +++ b/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java @@ -10,6 +10,9 @@ import com.podzilla.courier.models.DeliveryTask; import com.podzilla.courier.repositories.delivery_task.IDeliveryTaskRepository; import com.podzilla.courier.services.delivery_task.confirmation_strategy.DeliveryConfirmationStrategy; +import com.podzilla.courier.services.delivery_task.confirmation_strategy.OtpConfirmationStrategy; +import com.podzilla.courier.services.delivery_task.confirmation_strategy.QrCodeConfirmationStrategy; +import com.podzilla.courier.services.delivery_task.confirmation_strategy.SignatureConfirmationStrategy; import com.podzilla.courier.services.delivery_task.poll_command.Command; import com.podzilla.courier.services.delivery_task.poll_command.StopPollingCommand; import com.podzilla.courier.services.delivery_task.poll_command.StartPollingCommand; @@ -24,7 +27,6 @@ import java.time.LocalDateTime; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -34,17 +36,14 @@ public class DeliveryTaskService { private final IDeliveryTaskRepository deliveryTaskRepository; private final EventPublisher eventPublisher; - private final Map confirmationStrategies; private static final Logger LOGGER = LoggerFactory.getLogger(DeliveryTaskService.class); @Value("${otp.length}") private int otpLength; public DeliveryTaskService(final IDeliveryTaskRepository deliveryTaskRepository, - final EventPublisher eventPublisher, - final Map confirmationStrategies) { + final EventPublisher eventPublisher) { this.deliveryTaskRepository = deliveryTaskRepository; this.eventPublisher = eventPublisher; - this.confirmationStrategies = confirmationStrategies; } public DeliveryTaskResponseDto createDeliveryTask(final CreateDeliveryTaskRequestDto deliveryTaskRequestDto) { @@ -140,32 +139,32 @@ public Optional updateDeliveryTaskStatus(final String i return Optional.empty(); } - public Pair getDeliveryTaskLocation(final String id) { - LOGGER.info("Fetching location for delivery task with ID: {}", id); - Optional deliveryTask = deliveryTaskRepository.findById(id); + public Pair getDeliveryTaskLocation(final String orderId) { + LOGGER.info("Fetching location for delivery task with order id: {}", orderId); + Optional deliveryTask = deliveryTaskRepository.findByOrderId(orderId).stream().findFirst(); if (deliveryTask.isPresent()) { Double latitude = deliveryTask.get().getCourierLatitude(); Double longitude = deliveryTask.get().getCourierLongitude(); - LOGGER.debug("Location for delivery task ID: {} is ({}, {})", id, latitude, longitude); + LOGGER.debug("Location for delivery task with order id: {} is ({}, {})", orderId, latitude, longitude); return Pair.of(latitude, longitude); } - LOGGER.warn("Delivery task not found with ID for location: {}", id); + LOGGER.warn("Delivery task not found with order id: {} for location", orderId); return Pair.of(0.0, 0.0); } - public DeliveryTaskResponseDto updateDeliveryTaskLocation(final String id, final Double latitude, + public DeliveryTaskResponseDto updateDeliveryTaskLocation(final String orderId, final Double latitude, final Double longitude) { - LOGGER.info("Updating location for delivery task with ID: {} to ({}, {})", id, latitude, longitude); - Optional updatedDeliveryTask = deliveryTaskRepository.findById(id); + LOGGER.info("Updating location for delivery task with order id: {} to ({}, {})", orderId, latitude, longitude); + Optional updatedDeliveryTask = deliveryTaskRepository.findByOrderId(orderId).stream().findFirst(); if (updatedDeliveryTask.isPresent()) { DeliveryTask deliveryTask = updatedDeliveryTask.get(); deliveryTask.setCourierLongitude(latitude); deliveryTask.setCourierLongitude(longitude); deliveryTaskRepository.save(deliveryTask); - LOGGER.debug("Location updated for delivery task ID: {}", id); + LOGGER.debug("Location updated for delivery task with order id: {}", orderId); return DeliveryTaskMapper.toCreateResponseDto(deliveryTask); } - LOGGER.warn("Delivery task not found with ID: {} for location update", id); + LOGGER.warn("Delivery task not found with order id: {} for location update", orderId); return null; } @@ -217,7 +216,9 @@ public Optional confirmDelivery(final String id, final String confirmati } ConfirmationType confirmationType = task.getConfirmationType(); - DeliveryConfirmationStrategy strategy = confirmationStrategies.get(confirmationType); + DeliveryConfirmationStrategy strategy = confirmationType.equals(ConfirmationType.OTP)? new OtpConfirmationStrategy(eventPublisher): + confirmationType.equals(ConfirmationType.QR_CODE)? new QrCodeConfirmationStrategy(eventPublisher): + confirmationType.equals(ConfirmationType.SIGNATURE)? new SignatureConfirmationStrategy(eventPublisher): null; if (strategy == null) { LOGGER.error("No confirmation strategy found for type: {}", confirmationType); return Optional.of("Invalid confirmation type"); From 89ae901c2a5016a844ee87f9afae05ff27fa18b0 Mon Sep 17 00:00:00 2001 From: amir-awad Date: Sat, 17 May 2025 17:03:32 +0300 Subject: [PATCH 2/6] fix: changed type of price to be BigDecimal --- .../dtos/delivery_tasks/CreateDeliveryTaskRequestDto.java | 4 +++- .../dtos/delivery_tasks/DeliveryTaskResponseDto.java | 4 +++- .../courier/events/CourierAssignmentEventConsumer.java | 6 ++++-- src/main/java/com/podzilla/courier/models/DeliveryTask.java | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/CreateDeliveryTaskRequestDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/CreateDeliveryTaskRequestDto.java index 59ffb9d..1c89841 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/CreateDeliveryTaskRequestDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/CreateDeliveryTaskRequestDto.java @@ -4,6 +4,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import java.math.BigDecimal; + @Getter @AllArgsConstructor public class CreateDeliveryTaskRequestDto { @@ -14,7 +16,7 @@ public class CreateDeliveryTaskRequestDto { private String courierId; @NotNull(message = "Price is required") - private double price; + private BigDecimal price; @NotNull(message = "Order latitude is required") private double orderLatitude; diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java index 769c005..7ee8699 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java @@ -3,7 +3,9 @@ import com.podzilla.courier.models.DeliveryStatus; -public record DeliveryTaskResponseDto(String id, String orderId, String courierId, Double price, DeliveryStatus status, +import java.math.BigDecimal; + +public record DeliveryTaskResponseDto(String id, String orderId, String courierId, BigDecimal price, DeliveryStatus status, Double orderLatitude, Double orderLongitude, Double courierLatitude, Double courierLongitude) { } \ No newline at end of file diff --git a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java index 6412748..9336f21 100644 --- a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java +++ b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java @@ -1,5 +1,6 @@ package com.podzilla.courier.events; +import com.podzilla.courier.dtos.delivery_tasks.CreateDeliveryTaskRequestDto; import com.podzilla.courier.services.delivery_task.DeliveryTaskService; import com.podzilla.mq.EventsConstants; import com.podzilla.mq.events.BaseEvent; @@ -19,8 +20,9 @@ public CourierAssignmentEventConsumer(DeliveryTaskService deliveryTaskService) { public void handleEvent(BaseEvent event) { if(event instanceof OrderAssignedToCourierEvent) { OrderAssignedToCourierEvent courierEvent = (OrderAssignedToCourierEvent) event; -// deliveryTaskService.createDeliveryTask(courierEvent.getOrderId(), courierEvent.getCourierId(), -// courierEvent.getPrice(), courierEvent.getOrderLatitude(), courierEvent.getOrderLongitude()); + CreateDeliveryTaskRequestDto deliveryTask = new CreateDeliveryTaskRequestDto(courierEvent.getOrderId(), courierEvent.getCourierId(), + courierEvent.getPrice(), courierEvent.getOrderLatitude(), courierEvent.getOrderLongitude()); + deliveryTaskService.createDeliveryTask(deliveryTask); } } } diff --git a/src/main/java/com/podzilla/courier/models/DeliveryTask.java b/src/main/java/com/podzilla/courier/models/DeliveryTask.java index a4a6835..448a848 100644 --- a/src/main/java/com/podzilla/courier/models/DeliveryTask.java +++ b/src/main/java/com/podzilla/courier/models/DeliveryTask.java @@ -4,6 +4,7 @@ import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; +import java.math.BigDecimal; import java.time.LocalDateTime; @Data @@ -13,7 +14,7 @@ public class DeliveryTask { private String id; private String orderId; private String courierId; - private Double price; + private BigDecimal price; private DeliveryStatus status; private Double orderLatitude; private Double orderLongitude; From ce8f09ac1a5fd7f05bb3e58babb0d4109249a96c Mon Sep 17 00:00:00 2001 From: amir-awad Date: Sat, 17 May 2025 17:25:14 +0300 Subject: [PATCH 3/6] fix: removed config folder --- .../courier/config/RabbitMQConfig.java | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/main/java/com/podzilla/courier/config/RabbitMQConfig.java diff --git a/src/main/java/com/podzilla/courier/config/RabbitMQConfig.java b/src/main/java/com/podzilla/courier/config/RabbitMQConfig.java deleted file mode 100644 index aee4187..0000000 --- a/src/main/java/com/podzilla/courier/config/RabbitMQConfig.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.podzilla.courier.config; - -import org.springframework.amqp.core.*; -import org.springframework.amqp.rabbit.connection.ConnectionFactory; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class RabbitMQConfig { - - public static final String ORDER_EXCHANGE = "order.exchange"; - public static final String ORDER_SHIPPED_QUEUE = "order.shipped.queue"; - public static final String ORDER_DELIVERED_QUEUE = "order.delivered.queue"; - public static final String ORDER_FAILED_QUEUE = "order.failed.queue"; - public static final String ORDER_SHIPPED_KEY = "order.shipped"; - public static final String ORDER_DELIVERED_KEY = "order.delivered"; - public static final String ORDER_FAILED_KEY = "order.failed"; - - @Bean - public TopicExchange orderExchange() { - return new TopicExchange(ORDER_EXCHANGE); - } - - @Bean - public Queue orderShippedQueue() { - return new Queue(ORDER_SHIPPED_QUEUE, true); - } - - @Bean - public Queue orderDeliveredQueue() { - return new Queue(ORDER_DELIVERED_QUEUE, true); - } - - @Bean - public Queue orderFailedQueue() { - return new Queue(ORDER_FAILED_QUEUE, true); - } - - @Bean - public Binding orderShippedBinding(Queue orderShippedQueue, TopicExchange orderExchange) { - return BindingBuilder.bind(orderShippedQueue).to(orderExchange).with(ORDER_SHIPPED_KEY); - } - - @Bean - public Binding orderDeliveredBinding(Queue orderDeliveredQueue, TopicExchange orderExchange) { - return BindingBuilder.bind(orderDeliveredQueue).to(orderExchange).with(ORDER_DELIVERED_KEY); - } - - @Bean - public Binding orderFailedBinding(Queue orderFailedQueue, TopicExchange orderExchange) { - return BindingBuilder.bind(orderFailedQueue).to(orderExchange).with(ORDER_FAILED_KEY); - } - - @Bean - public Jackson2JsonMessageConverter jsonMessageConverter() { - return new Jackson2JsonMessageConverter(); - } - - @Bean - public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, Jackson2JsonMessageConverter jsonMessageConverter) { - RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); - rabbitTemplate.setMessageConverter(jsonMessageConverter); - return rabbitTemplate; - } -} \ No newline at end of file From 4afa8ec30d9a73efefdf5270fd842720bdd678d6 Mon Sep 17 00:00:00 2001 From: omar mohammed Date: Sat, 17 May 2025 17:34:30 +0300 Subject: [PATCH 4/6] update files to pass check-style --- .../dtos/delivery_tasks/DeliveryTaskResponseDto.java | 5 +++-- .../dtos/delivery_tasks/LocationUpdateDto.java | 2 +- .../SubmitCourierRatingRequestDto.java | 3 ++- .../UpdateDeliveryStatusRequestDto.java | 2 +- .../events/CourierAssignmentEventConsumer.java | 12 ++++++------ .../services/delivery_task/DeliveryTaskService.java | 8 +++++--- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java index 7ee8699..b374345 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java @@ -5,7 +5,8 @@ import java.math.BigDecimal; -public record DeliveryTaskResponseDto(String id, String orderId, String courierId, BigDecimal price, DeliveryStatus status, +public record DeliveryTaskResponseDto(String id, String orderId, String courierId, BigDecimal price, + DeliveryStatus status, Double orderLatitude, Double orderLongitude, Double courierLatitude, Double courierLongitude) { -} \ No newline at end of file +} diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/LocationUpdateDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/LocationUpdateDto.java index 4b07a0a..5b88697 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/LocationUpdateDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/LocationUpdateDto.java @@ -12,4 +12,4 @@ public class LocationUpdateDto { @NotNull(message = "Longitude is required") private Double longitude; -} \ No newline at end of file +} diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/SubmitCourierRatingRequestDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/SubmitCourierRatingRequestDto.java index 3c0b118..76e40ea 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/SubmitCourierRatingRequestDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/SubmitCourierRatingRequestDto.java @@ -9,8 +9,9 @@ @Getter @AllArgsConstructor public class SubmitCourierRatingRequestDto { + @SuppressWarnings("checkstyle:MagicNumber") @NotNull(message = "Rating is required") @Min(value = 1, message = "Rating must be at least 1") @Max(value = 5, message = "Rating must be at most 5") private Double rating; -} \ No newline at end of file +} diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/UpdateDeliveryStatusRequestDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/UpdateDeliveryStatusRequestDto.java index 474c1ab..f72d370 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/UpdateDeliveryStatusRequestDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/UpdateDeliveryStatusRequestDto.java @@ -10,4 +10,4 @@ public class UpdateDeliveryStatusRequestDto { @NotNull(message = "Status is required") private DeliveryStatus status; -} \ No newline at end of file +} diff --git a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java index 9336f21..4c7bf59 100644 --- a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java +++ b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java @@ -10,17 +10,17 @@ @Component public class CourierAssignmentEventConsumer { - final DeliveryTaskService deliveryTaskService; + private final DeliveryTaskService deliveryTaskService; - public CourierAssignmentEventConsumer(DeliveryTaskService deliveryTaskService) { + public CourierAssignmentEventConsumer(final DeliveryTaskService deliveryTaskService) { this.deliveryTaskService = deliveryTaskService; } @RabbitListener(queues = EventsConstants.COURIER_ORDER_EVENT_QUEUE) - public void handleEvent(BaseEvent event) { - if(event instanceof OrderAssignedToCourierEvent) { - OrderAssignedToCourierEvent courierEvent = (OrderAssignedToCourierEvent) event; - CreateDeliveryTaskRequestDto deliveryTask = new CreateDeliveryTaskRequestDto(courierEvent.getOrderId(), courierEvent.getCourierId(), + public void handleEvent(final BaseEvent event) { + if (event instanceof OrderAssignedToCourierEvent courierEvent) { + CreateDeliveryTaskRequestDto deliveryTask = new CreateDeliveryTaskRequestDto(courierEvent.getOrderId(), + courierEvent.getCourierId(), courierEvent.getPrice(), courierEvent.getOrderLatitude(), courierEvent.getOrderLongitude()); deliveryTaskService.createDeliveryTask(deliveryTask); } diff --git a/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java b/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java index c117ab4..af246cd 100644 --- a/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java +++ b/src/main/java/com/podzilla/courier/services/delivery_task/DeliveryTaskService.java @@ -216,9 +216,11 @@ public Optional confirmDelivery(final String id, final String confirmati } ConfirmationType confirmationType = task.getConfirmationType(); - DeliveryConfirmationStrategy strategy = confirmationType.equals(ConfirmationType.OTP)? new OtpConfirmationStrategy(eventPublisher): - confirmationType.equals(ConfirmationType.QR_CODE)? new QrCodeConfirmationStrategy(eventPublisher): - confirmationType.equals(ConfirmationType.SIGNATURE)? new SignatureConfirmationStrategy(eventPublisher): null; + DeliveryConfirmationStrategy strategy = confirmationType.equals(ConfirmationType.OTP) + ? new OtpConfirmationStrategy(eventPublisher) + : confirmationType.equals(ConfirmationType.QR_CODE) + ? new QrCodeConfirmationStrategy(eventPublisher) : confirmationType.equals(ConfirmationType.SIGNATURE) + ? new SignatureConfirmationStrategy(eventPublisher) : null; if (strategy == null) { LOGGER.error("No confirmation strategy found for type: {}", confirmationType); return Optional.of("Invalid confirmation type"); From 740ab31eedfe6449235b5f7629963276b939c080 Mon Sep 17 00:00:00 2001 From: omar mohammed Date: Sat, 17 May 2025 17:45:11 +0300 Subject: [PATCH 5/6] update files to pass check-style --- src/main/java/com/podzilla/courier/CourierApplication.java | 6 +++--- .../courier/dtos/couriers/CreateCourierRequestDto.java | 1 - .../courier/dtos/couriers/UpdateCourierRequestDto.java | 2 ++ .../dtos/delivery_tasks/DeliveryTaskResponseDto.java | 5 ++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/podzilla/courier/CourierApplication.java b/src/main/java/com/podzilla/courier/CourierApplication.java index 8ed5d3f..cbfbe48 100644 --- a/src/main/java/com/podzilla/courier/CourierApplication.java +++ b/src/main/java/com/podzilla/courier/CourierApplication.java @@ -10,8 +10,8 @@ @ComponentScan(basePackages = {"com.podzilla.courier", "com.podzilla.mq"}) public class CourierApplication { - public static void main(String[] args) { - SpringApplication.run(CourierApplication.class, args); - } + public static void main(final String[] args) { + SpringApplication.run(CourierApplication.class, args); + } } diff --git a/src/main/java/com/podzilla/courier/dtos/couriers/CreateCourierRequestDto.java b/src/main/java/com/podzilla/courier/dtos/couriers/CreateCourierRequestDto.java index a378171..0a5fc54 100644 --- a/src/main/java/com/podzilla/courier/dtos/couriers/CreateCourierRequestDto.java +++ b/src/main/java/com/podzilla/courier/dtos/couriers/CreateCourierRequestDto.java @@ -3,7 +3,6 @@ import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NonNull; @Getter @AllArgsConstructor diff --git a/src/main/java/com/podzilla/courier/dtos/couriers/UpdateCourierRequestDto.java b/src/main/java/com/podzilla/courier/dtos/couriers/UpdateCourierRequestDto.java index 5ff5383..977365c 100644 --- a/src/main/java/com/podzilla/courier/dtos/couriers/UpdateCourierRequestDto.java +++ b/src/main/java/com/podzilla/courier/dtos/couriers/UpdateCourierRequestDto.java @@ -3,8 +3,10 @@ import com.podzilla.courier.models.CourierStatus; import jakarta.validation.constraints.NotNull; import lombok.Getter; +import lombok.Setter; @Getter +@Setter public class UpdateCourierRequestDto { @NotNull(message = "ID is required") private String id; diff --git a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java index b374345..25c6f16 100644 --- a/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java +++ b/src/main/java/com/podzilla/courier/dtos/delivery_tasks/DeliveryTaskResponseDto.java @@ -6,7 +6,6 @@ import java.math.BigDecimal; public record DeliveryTaskResponseDto(String id, String orderId, String courierId, BigDecimal price, - DeliveryStatus status, - Double orderLatitude, Double orderLongitude, Double courierLatitude, - Double courierLongitude) { + DeliveryStatus status, Double orderLatitude, Double orderLongitude, + Double courierLatitude, Double courierLongitude) { } From 9a027a73ee6e914a50b8b58c4373691c492390d5 Mon Sep 17 00:00:00 2001 From: omar mohammed Date: Sat, 17 May 2025 17:55:20 +0300 Subject: [PATCH 6/6] update files to pass check-style --- .../events/CourierAssignmentEventConsumer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java index 4c7bf59..e4f2a6b 100644 --- a/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java +++ b/src/main/java/com/podzilla/courier/events/CourierAssignmentEventConsumer.java @@ -16,12 +16,18 @@ public CourierAssignmentEventConsumer(final DeliveryTaskService deliveryTaskServ this.deliveryTaskService = deliveryTaskService; } + @RabbitListener(queues = EventsConstants.COURIER_ORDER_EVENT_QUEUE) @RabbitListener(queues = EventsConstants.COURIER_ORDER_EVENT_QUEUE) public void handleEvent(final BaseEvent event) { - if (event instanceof OrderAssignedToCourierEvent courierEvent) { - CreateDeliveryTaskRequestDto deliveryTask = new CreateDeliveryTaskRequestDto(courierEvent.getOrderId(), + if (event instanceof OrderAssignedToCourierEvent) { + OrderAssignedToCourierEvent courierEvent = (OrderAssignedToCourierEvent) event; + CreateDeliveryTaskRequestDto deliveryTask = new CreateDeliveryTaskRequestDto( + courierEvent.getOrderId(), courierEvent.getCourierId(), - courierEvent.getPrice(), courierEvent.getOrderLatitude(), courierEvent.getOrderLongitude()); + courierEvent.getPrice(), + courierEvent.getOrderLatitude(), + courierEvent.getOrderLongitude() + ); deliveryTaskService.createDeliveryTask(deliveryTask); } }