Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/discovery-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BedReservationResponseDTO> 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<ResponseEntity<BedReservationResponseDTO>>} 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<ResponseEntity<BedReservationResponseDTO>> createBedReservation(@Valid @RequestBody BedReservationDTO bedReservationRequest) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
*/
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<String, Object>> handleWebExchangeBindException(WebExchangeBindException ex, ServerWebExchange exchange) {
Expand All @@ -48,6 +59,16 @@ public ResponseEntity<Map<String, Object>> 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<Object> handleBedUnavailableException(BedUnavailableException exception) {
Expand Down
7 changes: 6 additions & 1 deletion backend/gateway-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions backend/hospital-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<artifactId>preliquibase-spring-boot-starter</artifactId>
<version>1.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,19 @@ public ResponseEntity<HospitalDTO> 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<NearestHospitalDTO> getNearestHospitals(@Valid @RequestBody EmergencyLocationDTO emergencyLocationDTO) {
Expand All @@ -75,5 +81,4 @@ public ResponseEntity<NearestHospitalDTO> getNearestHospitals(@Valid @RequestBod
return ResponseEntity.ok(nearestHospital);
}

}
// TODO : Virer tout ce qui ne sert à rien en endpoint
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading