From 895f28520b4448c6c78a7d33bd816ea11ee01486 Mon Sep 17 00:00:00 2001 From: swyth_ Date: Thu, 10 Apr 2025 20:57:30 +0200 Subject: [PATCH 1/4] refacto: add javadoc dependency --- backend/discovery-service/pom.xml | 6 ++++++ backend/gateway-service/pom.xml | 7 ++++++- backend/hospital-service/pom.xml | 6 ++++++ backend/pom.xml | 8 +++++--- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/backend/discovery-service/pom.xml b/backend/discovery-service/pom.xml index e082834..e9f7a5b 100644 --- a/backend/discovery-service/pom.xml +++ b/backend/discovery-service/pom.xml @@ -43,6 +43,12 @@ spring-boot-starter-test test + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.11.2 + diff --git a/backend/gateway-service/pom.xml b/backend/gateway-service/pom.xml index 8c5075f..e79ae03 100644 --- a/backend/gateway-service/pom.xml +++ b/backend/gateway-service/pom.xml @@ -39,7 +39,12 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-client - + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.11.2 + org.springframework.boot spring-boot-starter-test diff --git a/backend/hospital-service/pom.xml b/backend/hospital-service/pom.xml index 435017e..8506a7b 100644 --- a/backend/hospital-service/pom.xml +++ b/backend/hospital-service/pom.xml @@ -47,6 +47,12 @@ preliquibase-spring-boot-starter 1.6.0 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.11.2 + org.postgresql postgresql diff --git a/backend/pom.xml b/backend/pom.xml index 80a1bbe..95c7924 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -44,13 +44,15 @@ spring-boot-starter-test test + - org.postgresql - postgresql - runtime + org.apache.maven.plugins + maven-javadoc-plugin + 3.11.2 + From 743be6069d0b5db3e02ca5188d26cee31faefe8e Mon Sep 17 00:00:00 2001 From: swyth_ Date: Thu, 10 Apr 2025 21:07:13 +0200 Subject: [PATCH 2/4] doc: add missing javadoc --- .../dto/MedicalSpecializationDtoMapper.java | 21 ++++++ .../hospitalservice/entity/Hospital.java | 30 ++++++++ .../entity/HospitalBedAvailability.java | 73 ++++++++++++++++++- .../entity/MedicalSpecialization.java | 42 +++++++++++ .../service/HospitalService.java | 18 ++++- 5 files changed, 181 insertions(+), 3 deletions(-) diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java index 004a198..a1734d6 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java @@ -7,6 +7,27 @@ import java.util.Set; import java.util.stream.Collectors; +/** + * Utility class responsible for mapping {@link MedicalSpecialization} entities + * to their corresponding {@link MedicalSpecializationDTO} representations. + * + * This mapper provides static methods to facilitate the transformation of entity objects + * into DTOs, making them suitable for use in the application's service or presentation layers. + * It handles conversions for both single entities and collections of entities. + * + * Functionalities: + * - Convert a single {@link MedicalSpecialization} entity to a {@link MedicalSpecializationDTO}. + * - Convert a collection (set) of {@link MedicalSpecialization} entities into a list of {@link MedicalSpecializationDTOs}. + * + * Characteristics: + * - Ensures that hospital availability details are accurately mapped and sorted by the hospital ID + * for consistent and predictable results. + * - Implements transformations in a way that adheres to immutability principles, using streams and collectors. + * + * Usage: + * - This class is designed for use as a utility and therefore has a private constructor to prevent instantiation. + * - Methods are static and intended to be called directly on the class. + */ public class MedicalSpecializationDtoMapper { private MedicalSpecializationDtoMapper() { diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/Hospital.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/Hospital.java index 1d1811a..34fb5fa 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/Hospital.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/Hospital.java @@ -60,6 +60,36 @@ public class Hospital { @OneToMany(mappedBy = "hospital", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) private Set hospitalBedAvailabilities = new HashSet<>(); + /** + * Represents the availability of a specific medical specialization within a hospital. + * + * The {@code SpecializationAvailability} class encapsulates the details of a medical + * specialization and the number of beds available for that specialization. It is + * typically used as a simplified view of the detailed hospital bed availability + * data for external communication or DTO transformations. + * + * Attributes: + * - id: Unique identifier of the medical specialization. + * - name: Name of the medical specialization. + * - bedsAvailable: Number of beds currently available for this specialization within the hospital. + * + * Annotations: + * - {@code @Data}: Automatically generates getters, setters, equals, hashCode, + * and toString methods. + * - {@code @NoArgsConstructor}: Generates a no-argument constructor. + * - {@code @AllArgsConstructor}: Generates a constructor with all fields. + * + * Purpose: + * - Provides a concise representation of medical specialization and its bed + * availability in the context of a hospital. + * - Used in DTOs like {@code HospitalDTO} to facilitate the transfer of + * specialization availability data between layers of the application. + * + * Typical Use Cases: + * - Incorporated in data transfer objects (DTOs) to transfer specialization + * and bed availability details. + * - Used in mapping hospital bed data to a simplified view for external consumers. + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailability.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailability.java index 37bdc09..b518326 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailability.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailability.java @@ -44,19 +44,90 @@ @EqualsAndHashCode(of = {"id"}) public class HospitalBedAvailability { + /** + * Represents the composite primary key for the {@code HospitalBedAvailability} entity. + * + * The {@code id} field is marked with the {@code @EmbeddedId} annotation, indicating + * that it serves as the composite key for the entity. It combines details about the + * hospital and medical specialization to uniquely identify a hospital's bed availability + * record. + * + * Attributes: + * - Contains the {@code HospitalBedAvailabilityId} object which defines the composite + * key structure. + * + * Purpose: + * - Facilitates the identification of bed availability records by combining hospital + * and medical specialization identifiers. + * + * Key Usage: + * - Essential for mapping and querying hospital bed availability details in a relational + * database. + */ @EmbeddedId private HospitalBedAvailabilityId id; + /** + * Represents the associated hospital entity in the context of hospital bed availability. + * + * This field establishes a many-to-one relationship between the `HospitalBedAvailability` + * entity and the `Hospital` entity. Each bed availability record is linked to a specific + * hospital, enabling the identification and tracking of bed availability based on the hospital. + * + * Features: + * - The relationship is eagerly fetched to ensure that the associated `Hospital` entity + * is available whenever the `HospitalBedAvailability` entity is retrieved. + * - The mapping is identified by the `hospitalId` attribute in the composite key + * `HospitalBedAvailabilityId` using the `@MapsId` annotation. + * - The `@JoinColumn` annotation specifies the foreign key column (`hospital_id`) in the + * `HospitalBedAvailability` table that references the primary key of the `Hospital` entity. + */ @ManyToOne(fetch = FetchType.EAGER) @MapsId("hospitalId") @JoinColumn(name = "hospital_id") private Hospital hospital; + /** + * Represents the medical specialization associated with a specific hospital bed availability record. + * + * This field establishes a many-to-one relationship between the {@code HospitalBedAvailability} entity + * and the {@code MedicalSpecialization} entity. It links the hospital bed availability to a particular + * medical specialization. + * + * Key Features: + * - This relationship is mapped using the {@code medicalSpecializationId} field in the composite primary key + * {@code HospitalBedAvailabilityId}. + * - Eagerly fetched to ensure that the associated {@code MedicalSpecialization} entity is loaded + * together with the {@code HospitalBedAvailability} entity. + * - Configured with the {@code @JoinColumn} annotation to specify the foreign key column + * {@code medical_specialization_id} in the database table. + * + * Annotations: + * - {@code @ManyToOne}: Specifies a many-to-one relationship between this entity and the {@code MedicalSpecialization}. + * - {@code @MapsId}: Indicates that the primary key of the current entity includes + * the {@code medicalSpecializationId} from the composite primary key. + * - {@code @JoinColumn}: Maps the {@code medicalSpecializationId} field to its corresponding foreign key column. + */ @ManyToOne(fetch = FetchType.EAGER) @MapsId("medicalSpecializationId") @JoinColumn(name = "medical_specialization_id") private MedicalSpecialization specialization; - // Additional field + + /** + * Stores the number of beds currently available in the hospital for a specific medical specialization. + * + * This field represents the dynamic count of beds that are ready to accommodate patients + * in the context of a specific `HospitalBedAvailability` record. It provides critical + * information for hospital management and patient allocation systems. + * + * Purpose: + * - Tracks the availability of hospital beds associated with a particular specialization. + * - Facilitates real-time monitoring and reporting of bed capacity. + * + * Typical Use Cases: + * - Used in applications that require hospital capacity and bed allocation details. + * - Serves as a key attribute for operational decisions in healthcare systems. + */ private int availableBeds; } diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/MedicalSpecialization.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/MedicalSpecialization.java index 7a1ac50..b99a53e 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/MedicalSpecialization.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/MedicalSpecialization.java @@ -60,9 +60,51 @@ public class MedicalSpecialization { @Column(nullable = false, name = "specialization_group") private String group; + /** + * Represents the set of hospital bed availability records associated with a specific medical specialization. + * + * This field establishes a one-to-many relationship between the {@code MedicalSpecialization} entity + * and the {@code HospitalBedAvailability} entity. Each record in the set corresponds to the current + * bed availability for the specialization in a particular hospital. + * + * Key Features: + * - Mapped by the {@code specialization} field in the {@code HospitalBedAvailability} entity. + * - Uses cascading operations with {@code CascadeType.ALL}, allowing automatic persistence and removal + * of associated entities. + * - Configured with {@code orphanRemoval = true} to automatically remove child entities that are no longer + * associated with the parent {@code MedicalSpecialization}. + * - Fetched eagerly, ensuring all {@code HospitalBedAvailability} records are loaded alongside the parent + * {@code MedicalSpecialization}. + * + * Purpose: + * - Tracks the availability of beds for this medical specialization across multiple hospitals. + * - Provides a means to navigate the relationship between medical specializations and hospital bed availability. + */ @OneToMany(mappedBy = "specialization", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) private Set hospitalBedAvailabilities = new HashSet<>(); + /** + * Represents the availability details of a hospital. + * + * This class encapsulates the essential information of a hospital, including its identification, + * name, location, geographic coordinates, and the current number of available beds. + * + * Key Attributes: + * - id: Unique identifier of the hospital. + * - name: Name of the hospital. + * - address: Complete address of the hospital. + * - postCode: Postal code of the hospital's location. + * - city: City where the hospital is located. + * - latitude: Geographic latitude of the hospital's location. + * - longitude: Geographic longitude of the hospital's location. + * - bedsAvailable: Number of beds currently available in the hospital. + * + * Annotations: + * - Lombok annotations are used to automate boilerplate code generation: + * - @Data: Generates getters, setters, equals, hashCode, and toString methods. + * - @NoArgsConstructor: Generates a no-argument constructor. + * - @AllArgsConstructor: Generates an all-argument constructor. + */ @Data @NoArgsConstructor @AllArgsConstructor diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java index 0e36ac2..77d0cb3 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java @@ -3,7 +3,6 @@ import com.swyth.hospitalservice.dto.*; import com.swyth.hospitalservice.entity.Hospital; import com.swyth.hospitalservice.entity.HospitalBedAvailability; -import com.swyth.hospitalservice.entity.MedicalSpecialization; import com.swyth.hospitalservice.exception.ResourceNotFoundException; import com.swyth.hospitalservice.repository.HospitalBedAvailabilityRepository; import com.swyth.hospitalservice.repository.HospitalRepository; @@ -12,8 +11,23 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; +/** + * Service class for managing hospital-related operations. + * + * This service provides methods to perform various operations such as + * retrieving all hospitals, finding hospitals by their ID, and locating + * the nearest hospital with available beds for a specific medical specialization. + * The service acts as a bridge between controllers and repositories, handling + * business logic and data transformations. + * + * Dependencies: + * - {@code HospitalBedAvailabilityRepository}: Manages data related to hospital bed availability. + * - {@code HospitalRepository}: Manages CRUD and query operations for hospital entities. + * + * Features: + * - Fetch all hospitals and return their details as DTOs. + * - Retrieve hospital details by their unique*/ @Service public class HospitalService { /** From 026ab895bfb5100ebac40fa667c44d53246c42fc Mon Sep 17 00:00:00 2001 From: swyth_ Date: Fri, 11 Apr 2025 11:43:20 +0200 Subject: [PATCH 3/4] doc: add missing javadoc --- .../DiscoveryServiceApplication.java | 6 ++++ .../emergencyservice/config/FeignConfig.java | 32 +++++++++++++++++++ .../config/FeignReactiveConfig.java | 9 ++++++ .../controller/BedReservationController.java | 28 +++++++++++++++- .../dto/BedReservationDTO.java | 4 +++ .../dto/BedReservationResponseDTO.java | 2 ++ .../dto/BedReservationResponseDtoMapper.java | 14 ++++++++ .../exception/BedUnavailableException.java | 9 ++++++ .../exception/GlobalExceptionHandler.java | 21 ++++++++++++ .../GatewayServiceApplication.java | 8 +++++ .../config/GatewayRouteConfig.java | 9 ++++++ .../HospitalBedAvailabilityController.java | 8 +++++ .../controller/HospitalController.java | 23 +++++++------ .../dto/BedReservationDTO.java | 4 +++ .../dto/HospitalDtoMapper.java | 11 +++++++ .../dto/MedicalSpecializationDtoMapper.java | 11 ++++++- .../entity/HospitalBedAvailabilityId.java | 15 +++++++++ .../exception/BedUnavailableException.java | 9 ++++++ .../exception/ResourceNotFoundException.java | 9 ++++++ .../service/HospitalService.java | 31 ++++++++++++++++++ .../service/MedicalSpecializationService.java | 23 +++++++++++++ 21 files changed, 275 insertions(+), 11 deletions(-) diff --git a/backend/discovery-service/src/main/java/com/swyth/discoveryservice/DiscoveryServiceApplication.java b/backend/discovery-service/src/main/java/com/swyth/discoveryservice/DiscoveryServiceApplication.java index 841bfe4..f953ac3 100644 --- a/backend/discovery-service/src/main/java/com/swyth/discoveryservice/DiscoveryServiceApplication.java +++ b/backend/discovery-service/src/main/java/com/swyth/discoveryservice/DiscoveryServiceApplication.java @@ -19,6 +19,12 @@ @EnableEurekaServer public class DiscoveryServiceApplication { + /** + * The entry point of the Discovery Service application. + * This method initializes and runs the Spring Boot application which acts as a Eureka Server for service discovery. + * + * @param args command-line arguments passed to the application. + */ public static void main(String[] args) { SpringApplication.run(DiscoveryServiceApplication.class, args); } diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignConfig.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignConfig.java index f127691..905c038 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignConfig.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignConfig.java @@ -20,16 +20,48 @@ @Configuration public class FeignConfig { + /** + * Configures and provides a custom Feign decoder bean. + * + * The decoder leverages the Spring framework's message converters + * to handle the deserialization of HTTP response bodies into Java + * objects. This allows Feign clients to seamlessly work with various + * data formats (e.g., JSON, XML) used in HTTP responses. + * + * @return a {@link Decoder} implementation that uses Spring's {@link HttpMessageConverters} + * for converting response data. + */ @Bean public Decoder feignDecoder() { return new SpringDecoder(HttpMessageConverters::new); } + /** + * Configures and provides a custom Feign encoder bean. + * + * This encoder leverages the Spring framework's message converters + * to handle the serialization of Java objects into HTTP request body + * representations. This allows Feign clients to seamlessly send data + * in various formats (e.g., JSON, XML) required by the endpoint. + * + * @return an {@link Encoder} implementation that uses Spring's {@link HttpMessageConverters} + * for converting request data. + */ @Bean public Encoder feignEncoder() { return new SpringEncoder(HttpMessageConverters::new); } + /** + * Registers a custom Feign {@link ErrorDecoder} bean to handle error responses. + * + * This method provides a custom error decoder implementation that parses + * HTTP error responses and maps specific status codes to appropriate exceptions. + * It enhances error handling for Feign clients by enabling the application to + * interpret and respond to errors in a controlled manner. + * + * @return an instance of {@link CustomErrorDecoder} for decoding Feign client errors + */ @Bean public ErrorDecoder customErrorDecoder() { return new CustomErrorDecoder(); diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignReactiveConfig.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignReactiveConfig.java index 32e0cf2..498a2df 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignReactiveConfig.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignReactiveConfig.java @@ -16,6 +16,15 @@ @Configuration public class FeignReactiveConfig { + /** + * Defines a scheduler for managing Feign client operations in a non-blocking + * reactive context. The scheduler uses a fixed thread pool with a capacity of 10 + * threads to handle blocking operations more efficiently, reducing the risk of + * thread starvation in reactive pipelines. + * + * @return a {@link Scheduler} instance backed by a fixed thread pool for executing + * blocking tasks within Feign clients. + */ @Bean public Scheduler feignScheduler() { // Créer un thread pool dédié aux opérations bloquantes diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/controller/BedReservationController.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/controller/BedReservationController.java index ecbc04b..aa9e1bd 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/controller/BedReservationController.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/controller/BedReservationController.java @@ -48,13 +48,39 @@ public BedReservationController(BedReservationService bedReservationService) { this.bedReservationService = bedReservationService; } - // TODO: Handle resource not Found + + /** + * Retrieves a bed reservation by its unique ID. + * + * This method fetches the bed reservation details using the provided ID and + * returns a response encapsulating the reservation details. + * + * @param id the unique identifier of the bed reservation to be retrieved + * @return a ResponseEntity containing the bed reservation details in the form of {@link BedReservationResponseDTO} + */ + // FIXME: Handle resource not Found @GetMapping("{id}") public ResponseEntity getBedReservationById(@PathVariable Long id) { BedReservationResponseDTO bedReservation = bedReservationService.findById(id); return ResponseEntity.ok(bedReservation); } + /** + * Handles the creation of a new bed reservation. + * + * This method processes the bed reservation request by validating the input data, + * checking bed availability in the specified hospital and medical specialization, + * and ultimately creating a new reservation if possible. It delegates the business + * logic to the service layer and returns the result encapsulated in a response entity. + * + * @param bedReservationRequest the details of the bed reservation request, including + * hospital ID, medical specialization ID, and reservation + * personal/contact information + * @return a {@code Mono>} containing the bed + * reservation details if successfully created + * @throws BedUnavailableException if no beds are available for the specified hospital + * and medical specialization + */ @PostMapping("") public Mono> createBedReservation(@Valid @RequestBody BedReservationDTO bedReservationRequest) { try { diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationDTO.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationDTO.java index 6a57e62..93d3e12 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationDTO.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationDTO.java @@ -3,7 +3,9 @@ import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * Data Transfer Object for handling bed reservation requests. @@ -16,6 +18,8 @@ * of the data provided in the request. */ @Data +@NoArgsConstructor +@AllArgsConstructor public class BedReservationDTO { @NotNull(message = "Hospital ID must not be null") diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDTO.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDTO.java index c2149b8..5c6e644 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDTO.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDTO.java @@ -5,6 +5,7 @@ import jakarta.validation.constraints.Pattern; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * Data Transfer Object representing a response for a bed reservation. @@ -25,6 +26,7 @@ * - reservationPhoneNumber: The phone number of the person for whom the reservation is made. */ @Data +@NoArgsConstructor @AllArgsConstructor public class BedReservationResponseDTO { private Long id; diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java index 3159663..eda0c9d 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java @@ -1,6 +1,8 @@ package com.swyth.emergencyservice.dto; import com.swyth.emergencyservice.entity.BedReservation; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; /** * This class provides mapping functionality to convert a {@code BedReservation} entity @@ -15,8 +17,20 @@ * transforming domain objects into DTOs by providing a dedicated method * for the transformation process. */ +@NoArgsConstructor +@AllArgsConstructor public class BedReservationResponseDtoMapper { + /** + * Converts a {@code BedReservation} entity into a {@code BedReservationResponseDTO}. + * + * This method extracts the relevant fields from the {@code BedReservation} entity + * and constructs a corresponding {@code BedReservationResponseDTO} to provide + * a simplified data transfer representation of the reservation. + * + * @param reservation the {@code BedReservation} entity to be converted + * @return a {@code BedReservationResponseDTO} containing the reservation details + */ public static BedReservationResponseDTO convertToDTO(BedReservation reservation) { return new BedReservationResponseDTO( reservation.getId(), diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/BedUnavailableException.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/BedUnavailableException.java index c18fd8d..f972798 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/BedUnavailableException.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/BedUnavailableException.java @@ -17,6 +17,15 @@ * specific detail message about the unavailability of resources. */ public class BedUnavailableException extends RuntimeException { + /** + * Constructs a new BedUnavailableException with a specific detail message. + * + * This exception is thrown when no beds are available in the specified hospital + * for the requested medical specialization. The message provides additional context + * about the unavailability of resources. + * + * @param message the detailed message explaining the reason for the exception + */ public BedUnavailableException(String message) { super(message); } diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/GlobalExceptionHandler.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/GlobalExceptionHandler.java index 85ad57f..c5a94f7 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/GlobalExceptionHandler.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/exception/GlobalExceptionHandler.java @@ -27,6 +27,17 @@ public class GlobalExceptionHandler { + /** + * Handles WebExchangeBindException to provide detailed error responses for bad formatted requests. + * + * This method constructs a standardized error response containing a timestamp, HTTP status code, + * error type, request path, and validation errors. The validation errors include details about + * fields that failed validation along with their corresponding error messages. + * + * @param ex the WebExchangeBindException that occurred, containing details of the validation errors + * @param exchange the ServerWebExchange object representing the current web exchange, used to retrieve the request path + * @return a ResponseEntity containing the error response with validation error details and an HTTP status code of 400 (Bad Request) + */ // Handle bad formatted requests @ExceptionHandler(WebExchangeBindException.class) public ResponseEntity> handleWebExchangeBindException(WebExchangeBindException ex, ServerWebExchange exchange) { @@ -48,6 +59,16 @@ public ResponseEntity> handleWebExchangeBindException(WebExc return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); } + /** + * Handles the BedUnavailableException and constructs a custom error response. + * + * This method is triggered whenever a BedUnavailableException is thrown in the + * application. It returns a standardized error response with relevant details such as + * timestamp, HTTP status code, error type, and a descriptive message. + * + * @param exception the BedUnavailableException that occurred + * @return a ResponseEntity containing the error response with details and an HTTP status code of 404 (Not Found) + */ // Handle BedUnavailableException @ExceptionHandler(BedUnavailableException.class) public ResponseEntity handleBedUnavailableException(BedUnavailableException exception) { diff --git a/backend/gateway-service/src/main/java/com/swyth/gatewayservice/GatewayServiceApplication.java b/backend/gateway-service/src/main/java/com/swyth/gatewayservice/GatewayServiceApplication.java index 24f0068..a5e480a 100644 --- a/backend/gateway-service/src/main/java/com/swyth/gatewayservice/GatewayServiceApplication.java +++ b/backend/gateway-service/src/main/java/com/swyth/gatewayservice/GatewayServiceApplication.java @@ -16,6 +16,14 @@ public static void main(String[] args) { SpringApplication.run(GatewayServiceApplication.class, args); } + /** + * Creates a {@link DiscoveryClientRouteDefinitionLocator} bean to dynamically define routes + * based on services registered with a discovery client. + * + * @param rdc the reactive discovery client used to interact with the service registry + * @param dlp the properties to customize the discovery locator's behavior + * @return a {@link DiscoveryClientRouteDefinitionLocator} instance that defines routes based on discovered services + */ @Bean DiscoveryClientRouteDefinitionLocator locator( ReactiveDiscoveryClient rdc, DiscoveryLocatorProperties dlp){ diff --git a/backend/gateway-service/src/main/java/com/swyth/gatewayservice/config/GatewayRouteConfig.java b/backend/gateway-service/src/main/java/com/swyth/gatewayservice/config/GatewayRouteConfig.java index 4add63e..78366d2 100644 --- a/backend/gateway-service/src/main/java/com/swyth/gatewayservice/config/GatewayRouteConfig.java +++ b/backend/gateway-service/src/main/java/com/swyth/gatewayservice/config/GatewayRouteConfig.java @@ -24,6 +24,15 @@ @Configuration public class GatewayRouteConfig { + /** + * Configures custom routes for services using Spring Cloud Gateway's RouteLocator. + * + * This method defines routes that map specific paths to their corresponding services + * through load balancers, enabling communication between the API Gateway and backend services. + * + * @param builder the RouteLocatorBuilder used to build and configure the routes + * @return a RouteLocator containing the defined service routes + */ @Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { return builder.routes() diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalBedAvailabilityController.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalBedAvailabilityController.java index b4e3568..473a55d 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalBedAvailabilityController.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalBedAvailabilityController.java @@ -45,6 +45,14 @@ public class HospitalBedAvailabilityController { private final HospitalBedAvailabilityService hospitalBedAvailabilityService; + /** + * Constructor for the HospitalBedAvailabilityController class. + * + * Initializes the controller with the provided HospitalBedAvailabilityService. + * This service is used to handle operations related to hospital bed availability. + * + * @param hospitalBedAvailabilityService the service for managing hospital bed availability + */ public HospitalBedAvailabilityController(HospitalBedAvailabilityService hospitalBedAvailabilityService) { this.hospitalBedAvailabilityService = hospitalBedAvailabilityService; } diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalController.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalController.java index 5b49dd6..438b2c7 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalController.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalController.java @@ -57,13 +57,19 @@ public ResponseEntity getHospitalById(@PathVariable Long id) { } /** - * POST endpoint to retrieve the nearest hospital based on latitude and longitude. - * Rationale for POST: - * - Sensitive data (latitude, longitude) is sent in the request body for better security. - * - Avoids exposing data in query parameters, which can be logged or cached. - * - Suitable for operations involving calculations, such as identifying the nearest hospital. -* * @param locationDTO contains latitude, longitude, and specialization ID. -* * @return nearest hospital details. + * Finds the nearest hospital based on the given location and medical specialization. + * + * This method accepts an emergency location request containing latitude, longitude, + * and a medical specialization ID, and returns information about the nearest hospital + * that matches the criteria. + * + * @param emergencyLocationDTO DTO containing the required details for finding the nearest hospital: + * - medicalSpecializationId: The ID of the desired medical specialization. + * - latitude: The latitude of the given location. + * - longitude: The longitude of the given location. + * @return A ResponseEntity containing a NearestHospitalDTO that represents the nearest hospital + * matching the given criteria, including details such as the hospital's name, address, + * and geographic coordinates. */ @PostMapping("/nearest") public ResponseEntity getNearestHospitals(@Valid @RequestBody EmergencyLocationDTO emergencyLocationDTO) { @@ -75,5 +81,4 @@ public ResponseEntity getNearestHospitals(@Valid @RequestBod return ResponseEntity.ok(nearestHospital); } -} -// TODO : Virer tout ce qui ne sert à rien en endpoint \ No newline at end of file +} \ No newline at end of file diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/BedReservationDTO.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/BedReservationDTO.java index 64ba203..6db3ed1 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/BedReservationDTO.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/BedReservationDTO.java @@ -1,6 +1,8 @@ package com.swyth.hospitalservice.dto; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * Represents a Data Transfer Object (DTO) for reserving hospital beds. @@ -27,6 +29,8 @@ * - Simplifies service method inputs by wrapping necessary identifiers into a single object. */ @Data +@NoArgsConstructor +@AllArgsConstructor public class BedReservationDTO { private Long id; private Long hospitalId; diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/HospitalDtoMapper.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/HospitalDtoMapper.java index fe1f10e..e51b3e8 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/HospitalDtoMapper.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/HospitalDtoMapper.java @@ -40,6 +40,17 @@ public class HospitalDtoMapper { private HospitalDtoMapper() { } + /** + * Converts a {@link Hospital} entity to its corresponding {@link HospitalDTO}. + * + * The conversion involves mapping the hospital's attributes, including basic details + * such as ID, name, address, and location (latitude and longitude), as well as + * available beds for each specialization, into a data transfer object (DTO). + * Specializations are sorted by their IDs, with nulls handled appropriately. + * + * @param hospital the {@link Hospital} entity to be converted + * @return a {@link HospitalDTO} containing the mapped attributes from the given hospital entity + */ public static HospitalDTO convertToDTO(Hospital hospital) { return new HospitalDTO( hospital.getId(), diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java index a1734d6..3eacf35 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java @@ -17,7 +17,7 @@ * * Functionalities: * - Convert a single {@link MedicalSpecialization} entity to a {@link MedicalSpecializationDTO}. - * - Convert a collection (set) of {@link MedicalSpecialization} entities into a list of {@link MedicalSpecializationDTOs}. + * - Convert a collection (set) of {@link MedicalSpecialization} entities into a list of {@link MedicalSpecializationDTO}. * * Characteristics: * - Ensures that hospital availability details are accurately mapped and sorted by the hospital ID @@ -64,6 +64,15 @@ public static MedicalSpecializationDTO convertToDTO(MedicalSpecialization specia ); } + /** + * Converts a set of {@link MedicalSpecialization} entities to a list of {@link MedicalSpecializationDTO} objects. + * + * This method processes a given set of {@link MedicalSpecialization}, sorting them by their IDs in ascending order + * (with nulls appearing last), and maps each entity to its corresponding {@link MedicalSpecializationDTO}. + * + * @param specializations the set of {@link MedicalSpecialization} entities to be converted + * @return a list of {@link MedicalSpecializationDTO} objects corresponding to the provided entities + */ public static List convertToDTO(Set specializations) { return specializations.stream() .sorted(Comparator.comparing(MedicalSpecialization::getId, Comparator.nullsLast(Comparator.naturalOrder()))) diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailabilityId.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailabilityId.java index 56bae6d..9412652 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailabilityId.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/entity/HospitalBedAvailabilityId.java @@ -26,6 +26,21 @@ @AllArgsConstructor @EqualsAndHashCode public class HospitalBedAvailabilityId implements Serializable { + /** + * Represents the unique identifier of a hospital. + * + * This field is part of a composite primary key in the HospitalBedAvailability entity, + * linking a hospital with a specific medical specialization. It is used to uniquely + * identify a hospital associated with bed availability data. + */ private Long hospitalId; + + /** + * Represents the unique identifier for a medical specialization. + * + * This field is part of the composite primary key in the HospitalBedAvailability entity. + * It links a hospital with a specific medical specialization to manage and track + * bed availability data associated with that specialization. + */ private Long medicalSpecializationId; } diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/BedUnavailableException.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/BedUnavailableException.java index 371deec..0680940 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/BedUnavailableException.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/BedUnavailableException.java @@ -15,6 +15,15 @@ * meaningful response to the client. */ public class BedUnavailableException extends RuntimeException { + /** + * Constructs a new BedUnavailableException with a specified message. + * + * This exception is used to indicate that no beds are available for a given + * medical specialization or hospital. The message provides additional details + * about the specific circumstance in which the exception is thrown. + * + * @param message the detail message explaining the reason for the exception + */ public BedUnavailableException(String message) { super(message); } diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/ResourceNotFoundException.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/ResourceNotFoundException.java index 3f2d39f..2f5d2a5 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/ResourceNotFoundException.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/exception/ResourceNotFoundException.java @@ -19,6 +19,15 @@ @Getter public class ResourceNotFoundException extends RuntimeException { + /** + * Constructs a new {@code ResourceNotFoundException} with the specified detail message. + * + * This exception is typically thrown when a requested resource cannot be found, + * such as when querying for entities in a database or searching for a specific + * item that does not exist. + * + * @param message the detail message describing the reason for the exception + */ public ResourceNotFoundException(String message) { super(message); // Pass the message to parent RuntimeException } diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java index 77d0cb3..d7d5a67 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/HospitalService.java @@ -47,11 +47,31 @@ public class HospitalService { private final HospitalBedAvailabilityRepository hospitalBedAvailabilityRepository; private final HospitalRepository hospitalRepository; + /** + * Constructs a new HospitalService with the specified repositories. + * + * This constructor initializes the service with the necessary dependencies + * to interact with hospital and hospital bed availability data. The dependencies + * are injected via constructor injection. + * + * @param hospitalBedAvailabilityRepository the repository for managing hospital bed availability data + * @param hospitalRepository the repository for managing hospital entity data + */ public HospitalService(HospitalBedAvailabilityRepository hospitalBedAvailabilityRepository, HospitalRepository hospitalRepository) { this.hospitalBedAvailabilityRepository = hospitalBedAvailabilityRepository; this.hospitalRepository = hospitalRepository; } + /** + * Retrieves a list of all hospitals and converts them to DTOs. + * + * This method fetches all hospital records from the repository, ensures there are + * no duplicates, and maps the resulting entities to data transfer objects (DTOs). + * If no hospitals are found, a {@code ResourceNotFoundException} is thrown. + * + * @return a list of {@code HospitalDTO} objects representing all hospitals in the system. + * @throws ResourceNotFoundException if no hospitals are found in the repository. + */ public List findAll() { Set hospitals = new HashSet<>(hospitalRepository.findAll()); @@ -62,6 +82,17 @@ public List findAll() { return HospitalDtoMapper.convertToDTO(hospitals); } + /** + * Finds a hospital by its unique identifier and converts it into a DTO. + * + * This method retrieves a hospital entity from the repository using the provided + * ID. If no hospital is found, a {@code ResourceNotFoundException} is thrown. The + * retrieved hospital entity is then mapped to a {@code HospitalDTO}. + * + * @param id the unique identifier of the hospital to be retrieved + * @return a {@code HospitalDTO} representing the hospital with the specified ID + * @throws ResourceNotFoundException if no hospital is found with the given ID + */ public HospitalDTO findById(Long id) { Hospital hospital = hospitalRepository.findById(id). orElseThrow(() -> new ResourceNotFoundException("Hospital not found with id: " + id)); diff --git a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/MedicalSpecializationService.java b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/MedicalSpecializationService.java index cfff2bf..aa4ec37 100644 --- a/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/MedicalSpecializationService.java +++ b/backend/hospital-service/src/main/java/com/swyth/hospitalservice/service/MedicalSpecializationService.java @@ -53,6 +53,17 @@ public MedicalSpecializationService(MedicalSpecializationRepository medicalSpeci this.medicalSpecializationRepository = medicalSpecializationRepository; } + /** + * Retrieves all medical specializations available in the system. + * + * This method fetches all instances of medical specializations from the repository. + * It converts these entities into their corresponding DTO representations for use + * in higher application layers. If no specializations are found, an exception is thrown. + * + * @return a list of {@code MedicalSpecializationDTO} objects representing all + * medical specializations available in the system. + * @throws ResourceNotFoundException if no medical specializations are found in the repository. + */ public List findAll() { Set specializations = new HashSet<>(medicalSpecializationRepository.findAll()); @@ -64,6 +75,18 @@ public List findAll() { return MedicalSpecializationDtoMapper.convertToDTO(specializations); } + /** + * Finds a medical specialization by its unique identifier (ID). + * + * This method retrieves a {@code MedicalSpecialization} entity from the repository using + * the provided ID. If the specialization is found, it is converted into a + * {@code MedicalSpecializationDTO} for further use. If no such specialization exists, + * a {@code ResourceNotFoundException} is thrown. + * + * @param id the unique identifier of the medical specialization to find + * @return a {@code MedicalSpecializationDTO} containing the details of the requested specialization + * @throws ResourceNotFoundException if no medical specialization is found with the given ID + */ public MedicalSpecializationDTO findById(Long id) { MedicalSpecialization specialization = medicalSpecializationRepository.findById(id). orElseThrow(() -> new ResourceNotFoundException("Medical Specialization not found for id: " + id)); From ac912cf5666a388c7d8755afd9be64e445023687 Mon Sep 17 00:00:00 2001 From: Yoann Talon <84589845+swyth-dev@users.noreply.github.com> Date: Fri, 11 Apr 2025 11:55:18 +0200 Subject: [PATCH 4/4] Update BedReservationResponseDtoMapper.java fix compilation error --- .../emergencyservice/dto/BedReservationResponseDtoMapper.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java index eda0c9d..b08e489 100644 --- a/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java +++ b/backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java @@ -1,8 +1,6 @@ package com.swyth.emergencyservice.dto; import com.swyth.emergencyservice.entity.BedReservation; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; /** * This class provides mapping functionality to convert a {@code BedReservation} entity @@ -17,8 +15,6 @@ * transforming domain objects into DTOs by providing a dedicated method * for the transformation process. */ -@NoArgsConstructor -@AllArgsConstructor public class BedReservationResponseDtoMapper { /**