Skip to content

Commit 1819300

Browse files
committed
doc(backend): document hospital-service with javadoc
1 parent f797282 commit 1819300

24 files changed

+13881
-1470
lines changed

backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalBedAvailabilityController.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,61 @@
88
import org.springframework.stereotype.Controller;
99
import org.springframework.web.bind.annotation.*;
1010

11+
/**
12+
* Controller class for managing hospital bed availability.
13+
*
14+
* This class defines endpoints for checking the availability of hospital beds for
15+
* a specific medical specialization in a given hospital. It interacts with the
16+
* {@code HospitalBedAvailabilityService} to perform the required operations.
17+
*
18+
* Features:
19+
* - Defines RESTful endpoint for checking bed availability.
20+
* - Handles required request parameters and delegates processing to the service layer.
21+
*
22+
* Endpoint Mapping:
23+
* - Base URL: /v1/bed-availabilities
24+
*
25+
* Functionalities:
26+
* - Verifies hospital bed availability for the given medical specialization and hospital ID.
27+
* - Throws appropriate exceptions when no beds are available.
28+
*
29+
* Annotations:
30+
* - {@code @Controller}: Identifies this class as a Spring Controller.
31+
* - {@code @ResponseBody}: Indicates that the return value of the methods will be serialized
32+
* directly into the HTTP response body.
33+
* - {@code @RequestMapping}: Maps incoming web requests to specific controller methods.
34+
*
35+
* Constructor:
36+
* - Accepts a {@code HospitalBedAvailabilityService} for managing bed availability data.
37+
*
38+
* Exceptions:
39+
* - Throws {@code BedUnavailableException} if no beds are available for the specified
40+
* inputs.
41+
*/
1142
@Controller
1243
@ResponseBody
1344
@RequestMapping("/v1/bed-availabilities")
14-
//@CrossOrigin(origins = "*", allowedHeaders = "*") //TODO: don't let it like that in Production env
1545
public class HospitalBedAvailabilityController {
1646
private final HospitalBedAvailabilityService hospitalBedAvailabilityService;
1747

1848
public HospitalBedAvailabilityController(HospitalBedAvailabilityService hospitalBedAvailabilityService) {
1949
this.hospitalBedAvailabilityService = hospitalBedAvailabilityService;
2050
}
2151

52+
/**
53+
* Checks the availability of hospital beds for a specified medical specialization
54+
* in a given hospital.
55+
*
56+
* This endpoint queries the hospital bed availability service to determine if there are
57+
* available beds for the provided medical specialization and hospital ID. If no beds
58+
* are available, a {@code BedUnavailableException} is thrown.
59+
*
60+
* @param medicalSpecializationId the unique identifier of the medical specialization
61+
* @param hospitalId the unique identifier of the hospital
62+
* @return a {@code ResponseEntity} containing a boolean value indicating whether at least
63+
* one bed is available
64+
* @throws BedUnavailableException if no beds are available for the specified medical specialization and hospital
65+
*/
2266
@PostMapping("/check")
2367
public ResponseEntity<Boolean> checkBedAvailability(
2468
@NotNull @RequestParam("medicalSpecializationId") Long medicalSpecializationId,

backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/HospitalController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,26 @@
1313

1414
import java.util.List;
1515

16+
/**
17+
* Controller for managing hospital-related endpoints.
18+
*
19+
* This controller serves as the entry point for hospital-related API requests,
20+
* such as fetching details about all hospitals, retrieving a specific hospital by ID,
21+
* and finding the nearest hospital based on a given location and medical specialization.
22+
* It interacts with the service layer {@link HospitalService} to fetch and process hospital data.
23+
*
24+
* Endpoints:
25+
* - GET /v1/hospitals: Retrieves a list of all hospitals.
26+
* - GET /v1/hospitals/{id}: Fetches details of a specific hospital by its ID.
27+
* - POST /v1/hospitals/nearest: Finds the nearest hospital based on location and specialization.
28+
*
29+
* Annotations:
30+
* - {@code @Controller} and {@code @RestController}: Indicates this is a Spring controller for REST APIs.
31+
* - {@code @RequestMapping("/v1/hospitals")}: Maps all endpoints to the base path.
32+
*/
1633
@Controller
1734
@RestController
1835
@RequestMapping("/v1/hospitals")
19-
//@CrossOrigin(origins = "*", allowedHeaders = "*") //TODO: don't let it like that in Production env
2036
public class HospitalController {
2137
private final HospitalService hospitalService;
2238

backend/hospital-service/src/main/java/com/swyth/hospitalservice/controller/MedicalSpecializationController.java

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,56 @@
99

1010
import java.util.List;
1111

12+
/**
13+
* Controller for managing medical specializations.
14+
*
15+
* This controller provides RESTful endpoints for retrieving information about
16+
* medical specializations. It acts as an entry point for client requests related
17+
* to medical specialization data. The controller delegates business logic
18+
* operations to the {@code MedicalSpecializationService}.
19+
*
20+
* Mappings and Responsibilities:
21+
* - Handles HTTP GET requests for retrieving all medical specializations.
22+
* - Handles HTTP GET requests for retrieving a specific medical specialization by ID.
23+
*
24+
* Exceptions:
25+
* - Throws {@code ResourceNotFoundException} when no specializations are found or
26+
* the requested specialization ID does not exist.
27+
*
28+
* Dependencies:
29+
* - {@code MedicalSpecializationService}: Used to perform business logic and
30+
* interact with the underlying data repository.
31+
*
32+
* Typical Use Cases:
33+
* - Listing all available medical specializations.
34+
* - Fetching details of a specific medical specialization identified by its ID.
35+
*
36+
* Annotations:
37+
* - {@code @Controller}: Indicates that this class serves as a web controller.
38+
* - {@code @RestController}: Combines {@code @Controller} and {@code @ResponseBody},
39+
* providing convenient configuration for REST APIs.
40+
* - {@code @RequestMapping}: Maps HTTP requests to methods within this controller.
41+
*/
1242
@Controller
1343
@RestController
1444
@RequestMapping("/v1/specializations")
15-
//@CrossOrigin(origins = "*", allowedHeaders = "*") //TODO: don't let it like that in Production env
1645
public class MedicalSpecializationController {
1746
private final MedicalSpecializationService medicalSpecializationService;
1847

1948
public MedicalSpecializationController(MedicalSpecializationService medicalSpecializationService) {
2049
this.medicalSpecializationService = medicalSpecializationService;
2150
}
2251

23-
/*
24-
- Get all specializations
25-
- Get nearest hospital (param : spec id & son adresse) -> Hopital le plus proche
26-
- Check if bed availabe for specialization and hospital id
27-
- Reserver le lit (param : spec id & hospital id) -> Reservation (id reservation, info hopital, info specialization)
28-
29-
Endpoints en plus :
30-
52+
/**
53+
* Retrieves a list of all available medical specializations.
54+
*
55+
* This method handles HTTP GET requests to fetch all medical specializations
56+
* from the system. It uses the {@code MedicalSpecializationService} to retrieve the data.
57+
* If no specializations are found, a {@code ResourceNotFoundException} is thrown.
58+
*
59+
* @return A {@code ResponseEntity} containing a list of {@code MedicalSpecializationDTO} objects,
60+
* representing the details of all medical specializations available in the system.
61+
* If no data is found, it throws a {@code ResourceNotFoundException}.
3162
*/
3263
@GetMapping("")
3364
public ResponseEntity<List<MedicalSpecializationDTO>> getMedicalSpecializations() {

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/BedReservationDTO.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
import lombok.Data;
44

5+
/**
6+
* Represents a Data Transfer Object (DTO) for reserving hospital beds.
7+
*
8+
* This class encapsulates the details required for reserving a hospital bed
9+
* associated with a specific hospital and medical specialization. It serves
10+
* as an intermediary object for transferring data between layers, such as
11+
* between a client and service, or a service and repository.
12+
*
13+
* Attributes:
14+
* - id: The unique identifier for the bed reservation.
15+
* - hospitalId: The unique identifier of the hospital where the bed reservation is being made.
16+
* - medicalSpecializationId: The unique identifier of the medical specialization related to the bed reservation.
17+
*
18+
* Usage Context:
19+
* - This DTO is used primarily in operations that involve updating or querying
20+
* hospital bed availability for specific medical specializations and hospitals.
21+
* - It facilitates the transfer of the required data without exposing the complete
22+
* internal details of the entities involved, such as hospital or specialization objects.
23+
*
24+
* Features:
25+
* - Encapsulates the key details required for reserving a hospital bed.
26+
* - Works with service methods that update or check hospital bed availability.
27+
* - Simplifies service method inputs by wrapping necessary identifiers into a single object.
28+
*/
529
@Data
630
public class BedReservationDTO {
731
private Long id;

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/EmergencyLocationDTO.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
import jakarta.validation.constraints.NotNull;
44
import lombok.Data;
55

6+
/**
7+
* The EmergencyLocationDTO class is a data transfer object used to encapsulate the location
8+
* and medical specialization information required for identifying the nearest hospital.
9+
*
10+
* It contains the following fields:
11+
* - medicalSpecializationId: Represents the unique identifier for a specific medical specialization.
12+
* - latitude: Specifies the latitude coordinate of the location.
13+
* - longitude: Specifies the longitude coordinate of the location.
14+
*
15+
* This class provides the necessary data for operations such as calculating proximity to
16+
* hospitals based on geographical coordinates and filtering by medical specialization.
17+
*
18+
* Validation annotations are applied to ensure that the fields are not null when the object
19+
* is used in service or controller layers. This helps prevent invalid or incomplete data
20+
* from being processed.
21+
*
22+
* The class is typically utilized as an input parameter in API endpoints that deal with
23+
* location-based querying, such as finding the nearest hospital with available beds for
24+
* a specified medical specialty.
25+
*/
626
@Data
727
public class EmergencyLocationDTO {
828
@NotNull(message = "Medical specialization ID must not be null")

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/HospitalDTO.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77

88
import java.util.List;
99

10+
/**
11+
* Data Transfer Object (DTO) for representing hospital information.
12+
*
13+
* This class is used to encapsulate and transfer hospital data between layers of the
14+
* application, typically from the service layer to the presentation layer. The DTO includes
15+
* details about the hospital such as its name, location, and available specializations with
16+
* their corresponding bed counts.
17+
*
18+
* Attributes:
19+
* - id: Unique identifier for the hospital.
20+
* - name: Name of the hospital.
21+
* - address: Address of the hospital.
22+
* - postCode: Postal code of the hospital's location.
23+
* - city: City where the hospital is located.
24+
* - latitude: Geographical latitude coordinate of the hospital.
25+
* - longitude: Geographical longitude coordinate of the hospital.
26+
* - specializations: List of medical specializations available in the hospital along with
27+
* the number of beds available for each specialization.
28+
*
29+
* Annotations:
30+
* - The class is annotated with Lombok annotations (@Data, @NoArgsConstructor, @AllArgsConstructor)
31+
* to auto-generate getters, setters, equals, hashCode, and constructors.
32+
*/
1033
@Data
1134
@NoArgsConstructor
1235
@AllArgsConstructor

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/HospitalDtoMapper.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@
77
import java.util.Set;
88
import java.util.stream.Collectors;
99

10+
/**
11+
* Utility class for mapping Hospital entities to their corresponding HospitalDTO representations.
12+
*
13+
* This class provides static methods for converting Hospital entities and collections of Hospital
14+
* entities to data transfer objects (DTOs), making it easier to transfer data between application
15+
* layers while decoupling the internal entity model from external representations.
16+
*
17+
* Features:
18+
* - Converts a single Hospital entity to a HospitalDTO.
19+
* - Converts a collection of Hospital entities (Set) to a list of HospitalDTOs, sorted by hospital ID.
20+
*
21+
* Methods:
22+
* - The conversion process includes mapping hospital attributes (ID, name, address, etc.) and
23+
* available bed information for each medical specialization into the DTO.
24+
* - Ensures the output DTOs are sorted by unique identifiers for consistency in representation.
25+
*
26+
* Annotations:
27+
* - The class is utilitarian in purpose and is marked with a private constructor to prevent
28+
* instantiation.
29+
*
30+
* Usage:
31+
* - The methods are designed to be used statically in services or business logic handling hospital
32+
* data transformation.
33+
*
34+
* Purpose:
35+
* - Centralizes and standardizes the entity-to-DTO conversion logic, reducing code duplication
36+
* and ensuring consistency across the application.
37+
*/
1038
public class HospitalDtoMapper {
1139

1240
private HospitalDtoMapper() {

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDTO.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77

88
import java.util.List;
99

10+
/**
11+
* Data Transfer Object (DTO) for representing information about a medical specialization.
12+
*
13+
* This class is designed to facilitate the transfer of data between layers in the application by encapsulating
14+
* information about a medical specialization. It includes details about the specialization itself and
15+
* a list of associated hospital availability details.
16+
*
17+
* Attributes:
18+
* - id: The unique identifier of the medical specialization.
19+
* - name: The name of the medical specialization (e.g., Cardiology, Neurology).
20+
* - group: The category or group to which the specialization belongs.
21+
* - hospitals: A list of hospital availability information associated with this specialization. This includes
22+
* details about hospitals, such as name, address, geographic location, and bed availability.
23+
*
24+
* Annotations:
25+
* - Lombok annotations are used to simplify the code:
26+
* - @Data: Generates getters, setters, and other utility methods.
27+
* - @NoArgsConstructor: Generates a no-argument constructor.
28+
* - @AllArgsConstructor: Generates an all-argument constructor.
29+
*/
1030
@Data
1131
@NoArgsConstructor
1232
@AllArgsConstructor

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/MedicalSpecializationDtoMapper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public class MedicalSpecializationDtoMapper {
1212
private MedicalSpecializationDtoMapper() {
1313
}
1414

15+
/**
16+
* Converts a {@link MedicalSpecialization} entity to a {@link MedicalSpecializationDTO}.
17+
*
18+
* This method transforms a {@link MedicalSpecialization} object into its corresponding
19+
* Data Transfer Object (DTO), encapsulating details such as the specialization's ID,
20+
* name, group, and associated hospital availability information.
21+
*
22+
* @param specialization the {@link MedicalSpecialization} entity to be converted
23+
* @return the corresponding {@link MedicalSpecializationDTO} containing the transformed data
24+
*/
1525
public static MedicalSpecializationDTO convertToDTO(MedicalSpecialization specialization) {
1626
return new MedicalSpecializationDTO(
1727
specialization.getId(),

backend/hospital-service/src/main/java/com/swyth/hospitalservice/dto/NearestHospitalDTO.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44
import lombok.Data;
55
import lombok.NoArgsConstructor;
66

7+
/**
8+
* Data Transfer Object (DTO) representing the nearest hospital.
9+
* This class is used for encapsulating details of the nearest hospital such as its
10+
* identification, name, address, location, and geographic coordinates.
11+
*
12+
* Fields:
13+
* - id: Unique identifier of the hospital.
14+
* - name: Name of the hospital.
15+
* - address: Complete address of the hospital.
16+
* - postCode: Postal code of the hospital location.
17+
* - city: City where the hospital is located.
18+
* - latitude: Geographical latitude coordinate of the hospital.
19+
* - longitude: Geographical longitude coordinate of the hospital.
20+
*
21+
* Commonly used for transferring data related to the nearest hospital, especially in
22+
* scenarios involving hospital search functionalities.
23+
*
24+
* Includes default no-argument constructor, all-arguments constructor, as well as
25+
* getter and setter methods for all fields, enabled by the Lombok annotations.
26+
*/
727
@Data
828
@NoArgsConstructor
929
@AllArgsConstructor

0 commit comments

Comments
 (0)