diff --git a/src/main/java/com/podzilla/courier/controllers/CourierController.java b/src/main/java/com/podzilla/courier/controllers/CourierController.java index 7f22e02..5ebfa56 100644 --- a/src/main/java/com/podzilla/courier/controllers/CourierController.java +++ b/src/main/java/com/podzilla/courier/controllers/CourierController.java @@ -1,12 +1,23 @@ package com.podzilla.courier.controllers; -import com.podzilla.courier.dtos.couriers.*; -import com.podzilla.courier.models.Courier; +import com.podzilla.courier.dtos.couriers.CourierResponseDto; +import com.podzilla.courier.dtos.couriers.CreateCourierRequestDto; +import com.podzilla.courier.dtos.couriers.UpdateCourierRequestDto; import com.podzilla.courier.services.CourierService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.PathVariable; import java.util.List; @@ -14,39 +25,84 @@ @RequestMapping("/couriers") public class CourierController { private final CourierService courierService; - private static final Logger logger = LoggerFactory.getLogger(CourierController.class); + private static final Logger LOGGER = + LoggerFactory.getLogger(CourierController.class); - public CourierController(CourierService courierService) { + public CourierController(final CourierService courierService) { this.courierService = courierService; } @GetMapping + @Operation(summary = "Get all couriers", + description = "Retrieves a list of all couriers.") + @ApiResponse(responseCode = "200", + description = "Successfully retrieved list of couriers") public ResponseEntity> getAllCouriers() { - logger.info("Received request to get all couriers"); + LOGGER.info("Received request to get all couriers"); return ResponseEntity.ok(courierService.getAllCouriers()); } @GetMapping("/{id}") - public ResponseEntity getCourierById(@PathVariable String id) { - logger.info("Received request to get courier with id {}", id); - return courierService.getCourierById(id).map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()); + @Operation(summary = "Get courier by ID", + description = "Retrieves a specific courier by their unique ID.") + @ApiResponse(responseCode = "200", + description = "Courier found and returned") + @ApiResponse(responseCode = "404", + description = "Courier not found") + public ResponseEntity getCourierById( + @Parameter(description = "ID of the courier to retrieve") + @PathVariable final String id) { + LOGGER.info("Received request to get courier with id {}", id); + return courierService.getCourierById(id) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } @PostMapping - public ResponseEntity createCourier(@RequestBody CreateCourierRequestDto courier) { - logger.info("Received request to add courier"); + @Operation(summary = "Create a new courier", + description = "Adds a new courier to the system.") + @ApiResponse(responseCode = "200", + description = "Courier successfully created") + public ResponseEntity createCourier( + @RequestBody(description = "Details of the courier to create") + @org.springframework.web.bind.annotation.RequestBody + final CreateCourierRequestDto courier) { + LOGGER.info("Received request to add courier"); return ResponseEntity.ok(courierService.createCourier(courier)); } @PutMapping("/{id}") - public ResponseEntity updateCourier(@PathVariable String id, @RequestBody UpdateCourierRequestDto courier) { - logger.info("Received request to update courier with id {}", id); - return courierService.updateCourier(id, courier).map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()); + @Operation(summary = "Update a courier", + description = "Updates details of an existing courier.") + @ApiResponse(responseCode = "200", + description = "Courier updated successfully") + @ApiResponse(responseCode = "404", + description = "Courier not found") + public ResponseEntity updateCourier( + @Parameter(description = "ID of the courier to update") + @PathVariable final String id, + @RequestBody(description = "Updated courier details") + @org.springframework.web.bind.annotation.RequestBody + final UpdateCourierRequestDto courier) { + LOGGER.info("Received request to update courier with id {}", id); + return courierService.updateCourier(id, courier) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } @DeleteMapping("/{id}") - public ResponseEntity deleteCourier(@PathVariable String id) { - logger.info("Received request to delete courier with id {}", id); - return courierService.deleteCourier(id).map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()); + @Operation(summary = "Delete a courier", + description = "Removes a courier from the system.") + @ApiResponse(responseCode = "200", + description = "Courier deleted successfully") + @ApiResponse(responseCode = "404", + description = "Courier not found") + public ResponseEntity deleteCourier( + @Parameter(description = "ID of the courier to delete") + @PathVariable final String id) { + LOGGER.info("Received request to delete courier with id {}", id); + return courierService.deleteCourier(id) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java b/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java index 176f4b3..27997b8 100644 --- a/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java +++ b/src/main/java/com/podzilla/courier/controllers/DeliveryTaskController.java @@ -1,109 +1,204 @@ package com.podzilla.courier.controllers; -import com.podzilla.courier.dtos.delivery_tasks.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.util.Pair; +import com.podzilla.courier.dtos.delivery_tasks.SubmitCourierRatingResponseDto; +import com.podzilla.courier.dtos.delivery_tasks.SubmitCourierRatingRequestDto; +import com.podzilla.courier.dtos.delivery_tasks.CancelDeliveryTaskRequestDto; +import com.podzilla.courier.dtos.delivery_tasks.LocationUpdateDto; +import com.podzilla.courier.dtos.delivery_tasks.CancelDeliveryTaskResponseDto; +import com.podzilla.courier.dtos.delivery_tasks.CreateDeliveryTaskRequestDto; +import com.podzilla.courier.dtos.delivery_tasks.DeliveryTaskResponseDto; +import com.podzilla.courier.dtos.delivery_tasks.UpdateDeliveryStatusRequestDto; import com.podzilla.courier.models.DeliveryStatus; import com.podzilla.courier.services.DeliveryTaskService; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.util.List; import java.util.Optional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.util.Pair; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/delivery-tasks") public class DeliveryTaskController { + private static final Logger LOGGER = LoggerFactory.getLogger(DeliveryTaskController.class); + private final DeliveryTaskService deliveryTaskService; - private static final Logger logger = LoggerFactory.getLogger(DeliveryTaskController.class); - public DeliveryTaskController(DeliveryTaskService deliveryTaskService) { + public DeliveryTaskController(final DeliveryTaskService deliveryTaskService) { this.deliveryTaskService = deliveryTaskService; } @PostMapping - public ResponseEntity createDeliveryTask(@RequestBody CreateDeliveryTaskRequestDto deliveryTaskRequestDto) { - logger.info("Received request to create delivery task"); - return ResponseEntity.ok(deliveryTaskService.createDeliveryTask(deliveryTaskRequestDto)); + @Operation(summary = "Create delivery task", description = "Creates a new delivery task") + @ApiResponse(responseCode = "200", description = "Delivery task created successfully") + public ResponseEntity createDeliveryTask( + @RequestBody(description = "Delivery task creation details") + @org.springframework.web.bind.annotation.RequestBody final CreateDeliveryTaskRequestDto requestDto) { + LOGGER.info("Received request to create delivery task"); + return ResponseEntity.ok(deliveryTaskService.createDeliveryTask(requestDto)); } @PatchMapping("/{id}") - public ResponseEntity> updateDeliveryTaskStatus(@PathVariable String id, @RequestBody UpdateDeliveryStatusRequestDto statusDto) { - logger.info("Received request to update delivery task with id {}", id); + @Operation(summary = "Update delivery task status", description = "Updates the status of a delivery task") + @ApiResponse(responseCode = "200", description = "Status updated successfully") + @ApiResponse(responseCode = "404", description = "Delivery task not found") + public ResponseEntity> updateDeliveryTaskStatus( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id, + @RequestBody(description = "New status details") + @org.springframework.web.bind.annotation.RequestBody final UpdateDeliveryStatusRequestDto statusDto) { + LOGGER.info("Received request to update delivery task with id {}", id); return ResponseEntity.ok(deliveryTaskService.updateDeliveryTaskStatus(id, statusDto.getStatus())); } @GetMapping + @Operation(summary = "Get all delivery tasks", description = "Retrieves all delivery tasks") + @ApiResponse(responseCode = "200", description = "Successfully retrieved all tasks") public ResponseEntity> getAllDeliveryTasks() { - logger.info("Received request to get all delivery tasks"); + LOGGER.info("Received request to get all delivery tasks"); return ResponseEntity.ok(deliveryTaskService.getAllDeliveryTasks()); } @GetMapping("/{id}") - public ResponseEntity getDeliveryTaskById(@PathVariable String id) { - logger.info("Received request to get delivery task with id {}", id); + @Operation(summary = "Get delivery task by ID", description = "Retrieves a specific delivery task") + @ApiResponse(responseCode = "200", description = "Delivery task found") + @ApiResponse(responseCode = "404", description = "Delivery task not found") + public ResponseEntity getDeliveryTaskById( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id) { + LOGGER.info("Received request to get delivery task with id {}", id); return deliveryTaskService.getDeliveryTaskById(id) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } @GetMapping("/courier/{courierId}") - public ResponseEntity> getDeliveryTasksByCourierId(@PathVariable String courierId) { - logger.info("Received request to get delivery task with courier id {}", courierId); + @Operation(summary = "Get tasks by courier ID", description = "Retrieves delivery tasks for a specific courier") + @ApiResponse(responseCode = "200", description = "Tasks retrieved successfully") + public ResponseEntity> getDeliveryTasksByCourierId( + @Parameter(description = "ID of the courier") + @PathVariable final String courierId) { + LOGGER.info("Received request to get delivery task with courier id {}", courierId); return ResponseEntity.ok(deliveryTaskService.getDeliveryTasksByCourierId(courierId)); } @GetMapping("/status/{status}") - public ResponseEntity> getDeliveryTasksByStatus(@PathVariable DeliveryStatus status) { - logger.info("Received request to get delivery task with status {}", status); + @Operation(summary = "Get tasks by status", description = "Retrieves delivery tasks filtered by status") + @ApiResponse(responseCode = "200", description = "Tasks retrieved successfully") + public ResponseEntity> getDeliveryTasksByStatus( + @Parameter(description = "Delivery status filter") + @PathVariable final DeliveryStatus status) { + LOGGER.info("Received request to get delivery task with status {}", status); return ResponseEntity.ok(deliveryTaskService.getDeliveryTasksByStatus(status)); } @GetMapping("/order/{orderId}") - public ResponseEntity> getDeliveryTasksByOrderId(@PathVariable String orderId) { - logger.info("Received request to get delivery task with order id {}", orderId); + @Operation(summary = "Get tasks by order ID", description = "Retrieves delivery tasks for a specific order") + @ApiResponse(responseCode = "200", description = "Tasks retrieved successfully") + public ResponseEntity> getDeliveryTasksByOrderId( + @Parameter(description = "ID of the order") + @PathVariable final String orderId) { + LOGGER.info("Received request to get delivery task with order id {}", orderId); return ResponseEntity.ok(deliveryTaskService.getDeliveryTasksByOrderId(orderId)); } @GetMapping("/{id}/location") - public ResponseEntity> getDeliveryTaskLocation(@PathVariable String id) { - logger.info("Received request to get the location of delivery task with id {}", id); + @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)); } @PatchMapping("/{id}/location") - public ResponseEntity updateDeliveryTaskLocation(@PathVariable String id, @RequestBody LocationUpdateDto locationUpdateDto) { - logger.info("Received request to update the location if delivery task with id {}", id); - return ResponseEntity.ok(deliveryTaskService.updateDeliveryTaskLocation(id, locationUpdateDto.getLatitude(), locationUpdateDto.getLongitude())); + @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, + @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); + return ResponseEntity.ok(deliveryTaskService.updateDeliveryTaskLocation( + id, + locationUpdateDto.getLatitude(), + locationUpdateDto.getLongitude())); } @PatchMapping("/{id}/cancel") - public ResponseEntity cancelDeliveryTask(@PathVariable String id, @RequestBody CancelDeliveryTaskRequestDto cancelTaskDto) { - logger.info("Received request to cancel delivery task with id {}", id); + @Operation(summary = "Cancel delivery task", description = "Cancels a delivery task with a reason") + @ApiResponse(responseCode = "200", description = "Task cancelled successfully") + public ResponseEntity cancelDeliveryTask( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id, + @RequestBody(description = "Cancellation details") + @org.springframework.web.bind.annotation.RequestBody final CancelDeliveryTaskRequestDto cancelTaskDto) { + LOGGER.info("Received request to cancel delivery task with id {}", id); return ResponseEntity.ok(deliveryTaskService.cancelDeliveryTask(id, cancelTaskDto.cancellationReason())); } @PatchMapping("/{id}/rate") - public ResponseEntity submitCourierRating(@PathVariable String id, @RequestBody SubmitCourierRatingRequestDto ratingDto) { + @Operation(summary = "Submit courier rating", description = "Submits a rating for the courier's performance") + @ApiResponse(responseCode = "200", description = "Rating submitted successfully") + public ResponseEntity submitCourierRating( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id, + @RequestBody(description = "Rating details") + @org.springframework.web.bind.annotation.RequestBody final SubmitCourierRatingRequestDto ratingDto) { return ResponseEntity.ok(deliveryTaskService.submitCourierRating(id, ratingDto.getRating())); } @DeleteMapping("/{id}") - public ResponseEntity deleteDeliveryTask(@PathVariable String id) { - logger.info("Received request to delete delivery task with id {}", id); + @Operation(summary = "Delete delivery task", description = "Permanently removes a delivery task") + @ApiResponse(responseCode = "200", description = "Task deleted successfully") + public ResponseEntity deleteDeliveryTask( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id) { + LOGGER.info("Received request to delete delivery task with id {}", id); return ResponseEntity.ok(deliveryTaskService.deleteDeliveryTask(id)); } - + @PutMapping("/{id}/otp") - public ResponseEntity updateOtp(@PathVariable String id, @RequestBody String otp) { - return deliveryTaskService.updateOtp(id, otp).map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()); + @Operation(summary = "Update OTP", description = "Updates the One-Time Password for a delivery task") + @ApiResponse(responseCode = "200", description = "OTP updated successfully") + @ApiResponse(responseCode = "404", description = "Task not found") + public ResponseEntity updateOtp( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id, + @RequestBody(description = "New OTP value") + @org.springframework.web.bind.annotation.RequestBody final String otp) { + return deliveryTaskService.updateOtp(id, otp) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } @PutMapping("/{id}/otp-confirmation") - public ResponseEntity confirmOTP(@PathVariable String id, @RequestBody String otp) { - return deliveryTaskService.confirmOTP(id, otp).map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()); + @Operation(summary = "Confirm OTP", description = "Validates the One-Time Password for a delivery task") + @ApiResponse(responseCode = "200", description = "OTP confirmed successfully") + @ApiResponse(responseCode = "404", description = "Invalid OTP or task not found") + public ResponseEntity confirmOTP( + @Parameter(description = "ID of the delivery task") + @PathVariable final String id, + @RequestBody(description = "OTP to validate") + @org.springframework.web.bind.annotation.RequestBody final String otp) { + return deliveryTaskService.confirmOTP(id, otp) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); } - }