Skip to content

Commit 42b78ee

Browse files
authored
Documentation: microservices (#39) from doc(backend)/add-javadoc
2 parents e57fbc7 + 1819300 commit 42b78ee

File tree

46 files changed

+14207
-1497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+14207
-1497
lines changed

backend/discovery-service/src/main/java/com/swyth/discoveryservice/DiscoveryServiceApplication.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
66

7+
/**
8+
* DiscoveryServiceApplication is the entry point for the Discovery Service application.
9+
* This application acts as a Eureka Server for service discovery, allowing microservices
10+
* to register themselves and discover other registered services.
11+
*
12+
* This class is annotated with:
13+
* - @SpringBootApplication: Indicates a Spring Boot application.
14+
* - @EnableEurekaServer: Activates the Netflix Eureka Server for service discovery capabilities.
15+
*
16+
* The main method initializes and runs the Spring Boot application.
17+
*/
718
@SpringBootApplication
819
@EnableEurekaServer
920
public class DiscoveryServiceApplication {

backend/emergency-service/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
3434
</properties>
3535
<dependencies>
36+
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
37+
<dependency>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-javadoc-plugin</artifactId>
40+
<version>3.11.2</version>
41+
</dependency>
3642
<dependency>
3743
<groupId>org.springframework.boot</groupId>
3844
<artifactId>spring-boot-starter-data-jpa</artifactId>

backend/emergency-service/src/main/java/com/swyth/emergencyservice/EmergencyServiceApplication.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
66
import org.springframework.cloud.openfeign.EnableFeignClients;
77

8+
/**
9+
* The EmergencyServiceApplication class serves as the entry point for the Emergency Service
10+
* application. It configures the Spring Boot application as a discovery client
11+
* and enables Feign clients for declarative REST client functionality.
12+
*
13+
* Annotations:
14+
* - @SpringBootApplication: Marks this as a Spring Boot application.
15+
* - @EnableFeignClients: Enables the detection of Feign clients in the application.
16+
* - @EnableDiscoveryClient: Configures the application to register itself as a discovery client
17+
* in a service registry, allowing it to interact with other services.
18+
*
19+
* The main method initializes and runs the Spring Boot application.
20+
*/
821
@SpringBootApplication
922
@EnableFeignClients
1023
@EnableDiscoveryClient

backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/CustomErrorDecoder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
import java.io.InputStream;
1111
import java.util.Map;
1212

13+
/**
14+
* CustomErrorDecoder is an implementation of the ErrorDecoder interface
15+
* used to decode and handle HTTP error responses in a Feign client.
16+
* It parses the error details from the response body and maps specific
17+
* HTTP status codes to custom exceptions.
18+
*/
1319
public class CustomErrorDecoder implements ErrorDecoder {
1420

1521
// Jackson ObjectMapper to parse JSON

backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
1111

12+
/**
13+
* FeignConfig class provides the configuration for Feign clients in the application.
14+
*
15+
* This class customizes the Feign client by registering beans for request and response
16+
* encoding/decoding and error handling. The configurations ensure that Feign clients
17+
* can seamlessly integrate with the application's data format and handle errors
18+
* appropriately.
19+
*/
1220
@Configuration
1321
public class FeignConfig {
1422

backend/emergency-service/src/main/java/com/swyth/emergencyservice/config/FeignReactiveConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import reactor.core.scheduler.Schedulers;
77
import java.util.concurrent.Executors;
88

9+
/**
10+
* Configuration class for setting up reactive Feign components.
11+
*
12+
* This class defines custom configurations required for reactive Feign,
13+
* including a scheduler for managing blocking operations in a reactive context, that fixed
14+
* a blocking single thread operation error.
15+
*/
916
@Configuration
1017
public class FeignReactiveConfig {
1118

backend/emergency-service/src/main/java/com/swyth/emergencyservice/controller/BedReservationController.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,40 @@
1010
import org.springframework.web.bind.annotation.*;
1111
import reactor.core.publisher.Mono;
1212

13+
/**
14+
* Rest Controller handling bed reservation-related operations.
15+
*
16+
* The BedReservationController manages endpoints for creating bed reservations
17+
* and retrieving information about existing reservations. It interacts with
18+
* the {@link BedReservationService} to perform the necessary business logic and
19+
* return results as HTTP responses.
20+
*
21+
* Endpoints:
22+
* - GET /v1/bed-reservations/{id}: Retrieves details of a bed reservation by its unique ID.
23+
* - POST /v1/bed-reservations: Creates a new bed reservation with the provided details.
24+
*
25+
* Dependencies:
26+
* - {@link BedReservationService}: The service layer responsible for bed reservation operations.
27+
*
28+
* Validation and Exceptions:
29+
* - Handles input validation for creating bed reservations using {@link BedReservationDTO}.
30+
* - Throws {@link BedUnavailableException} if no bed is available for the requested criteria.
31+
*/
1332
@Controller
1433
@RestController
1534
@RequestMapping("/v1/bed-reservations")
16-
//@CrossOrigin(origins = "*", allowedHeaders = "*") //TODO: don't let it like that in Production env
1735
public class BedReservationController {
1836
private final BedReservationService bedReservationService;
1937

38+
/**
39+
* Constructs the BedReservationController with a BedReservationService dependency.
40+
*
41+
* This constructor initializes the controller with the specified service, which provides
42+
* the business logic for handling bed reservation-related operations such as creation
43+
* and retrieval of bed reservations.
44+
*
45+
* @param bedReservationService the service responsible for managing bed reservation logic
46+
*/
2047
public BedReservationController(BedReservationService bedReservationService) {
2148
this.bedReservationService = bedReservationService;
2249
}

backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationDTO.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
import jakarta.validation.constraints.Pattern;
66
import lombok.Data;
77

8-
// TODO: refactor to bed reservation Request/Payload
8+
/**
9+
* Data Transfer Object for handling bed reservation requests.
10+
*
11+
* This class encapsulates the details required to create a bed reservation for a specific hospital
12+
* and medical specialization. It includes information about the hospital, medical specialization,
13+
* and the personal details of the individual making the reservation.
14+
*
15+
* Validation annotations are included for ensuring the integrity and correctness
16+
* of the data provided in the request.
17+
*/
918
@Data
1019
public class BedReservationDTO {
1120

backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDTO.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@
66
import lombok.AllArgsConstructor;
77
import lombok.Data;
88

9-
// TODO : Refactor to BedReservation
9+
/**
10+
* Data Transfer Object representing a response for a bed reservation.
11+
*
12+
* This class is used to encapsulate the response details of a bed reservation,
13+
* including the reservation's ID, the associated hospital and medical specialization IDs,
14+
* as well as the personal and contact details of the individual for whom the reservation is made.
15+
* This DTO is intended for use in response payloads within applications, enabling
16+
* a clear separation between internal domain models and API responses.
17+
*
18+
* Fields:
19+
* - id: The unique identifier for the bed reservation.
20+
* - hospitalId: The identifier of the hospital where the reservation is made.
21+
* - medicalSpecializationId: The identifier of the medical specialization associated with the reservation.
22+
* - reservationFirstName: The first name of the person for whom the reservation is made.
23+
* - reservationLastName: The last name of the person for whom the reservation is made.
24+
* - reservationEmail: The email address of the person for whom the reservation is made.
25+
* - reservationPhoneNumber: The phone number of the person for whom the reservation is made.
26+
*/
1027
@Data
1128
@AllArgsConstructor
1229
public class BedReservationResponseDTO {

backend/emergency-service/src/main/java/com/swyth/emergencyservice/dto/BedReservationResponseDtoMapper.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
import com.swyth.emergencyservice.entity.BedReservation;
44

5+
/**
6+
* This class provides mapping functionality to convert a {@code BedReservation} entity
7+
* into a {@code BedReservationResponseDTO}.
8+
*
9+
* The purpose of the {@code BedReservationResponseDtoMapper} is to extract
10+
* relevant fields from the {@code BedReservation} entity and package them
11+
* into a data transfer object ({@code BedReservationResponseDTO})
12+
* for use in external layers such as APIs or client responses.
13+
*
14+
* The mapper ensures consistency and reduces the complexity of
15+
* transforming domain objects into DTOs by providing a dedicated method
16+
* for the transformation process.
17+
*/
518
public class BedReservationResponseDtoMapper {
619

7-
public BedReservationResponseDtoMapper() {
8-
}
9-
1020
public static BedReservationResponseDTO convertToDTO(BedReservation reservation) {
1121
return new BedReservationResponseDTO(
1222
reservation.getId(),

0 commit comments

Comments
 (0)