From 2c359a06e09c1171a5a82d5adcb5f227a0612dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Ga=C3=ABl?= <61506484+Alwil17@users.noreply.github.com> Date: Tue, 13 May 2025 08:38:30 +0000 Subject: [PATCH 1/3] Dev (#20) * Fixed Lombox leaks * Added readme * Added dotenv * Changed static links to dotenv related * Added docker support * Added CI/CD * Edited workflow to enable Dockerization --- .env.example | 5 + .github/workflows/rdv_manager_api.yml | 59 ++++++++ .gitignore | 4 +- Dockerfile | 12 ++ README.md | 142 ++++++++++++++++++ docker-compose.yml | 17 +++ pom.xml | 21 +-- .../controller/AuditLogController.java | 6 +- .../controller/ClientController.java | 6 +- .../controller/ReminderController.java | 6 +- .../controller/ReservationController.java | 6 +- .../ServiceAvailabilityController.java | 6 +- .../controller/ServiceController.java | 6 +- .../controller/SlotController.java | 6 +- .../controller/StructureController.java | 6 +- .../domain/model/AuditLog.java | 54 ++++++- .../rdv_manager_api/domain/model/Client.java | 79 +++++++++- .../domain/model/Reminder.java | 53 ++++++- .../domain/model/Reservation.java | 48 +++++- .../domain/model/ServiceAvailability.java | 53 ++++++- .../domain/model/ServiceEntity.java | 53 ++++++- .../rdv_manager_api/domain/model/Slot.java | 67 ++++++++- .../domain/model/Structure.java | 65 +++++++- .../service/impl/AuditLogServiceImpl.java | 7 +- .../service/impl/ClientServiceImpl.java | 8 +- .../service/impl/ReminderServiceImpl.java | 7 +- .../service/impl/ReservationServiceImpl.java | 7 +- .../impl/ServiceAvailabilityServiceImpl.java | 7 +- .../impl/ServiceEntityServiceImpl.java | 7 +- .../service/impl/SlotServiceImpl.java | 7 +- .../service/impl/StructureServiceImpl.java | 7 +- .../{applicaltion.yml => application.yml} | 13 +- 32 files changed, 786 insertions(+), 64 deletions(-) create mode 100644 .env.example create mode 100644 .github/workflows/rdv_manager_api.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml rename src/main/resources/{applicaltion.yml => application.yml} (57%) diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d01cfe0 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +SERVER_PORT=8080 + +SPRING_MONGO_URL=[YOUR_DB_URL] +SPRING_MONGO_USERNAME=[YOUR_DB_USER] +SPRING_MONGO_PASSWORD=[YOUR_DB_PASSWORD] \ No newline at end of file diff --git a/.github/workflows/rdv_manager_api.yml b/.github/workflows/rdv_manager_api.yml new file mode 100644 index 0000000..47da46f --- /dev/null +++ b/.github/workflows/rdv_manager_api.yml @@ -0,0 +1,59 @@ +name: Spring Boot CI/CD + +on: + push: + branches: + - dev + pull_request: + branches: + - dev + +jobs: + build-and-test: + name: Build & Test + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build with Maven + run: mvn clean install -DskipTests=false + + - name: Run tests + run: mvn test + + dockerize: + name: Docker Build & Push + needs: build-and-test + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/dev' + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & Push Docker Image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/rdv_manager_api:latest . + docker push ${{ secrets.DOCKER_USERNAME }}/rdv_manager_api:latest diff --git a/.gitignore b/.gitignore index e8857c0..14a9a8c 100644 --- a/.gitignore +++ b/.gitignore @@ -87,4 +87,6 @@ nb-configuration.xml ############################## ## Miscellaneous ############################## -*.log \ No newline at end of file +*.log + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3e6ff9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# Étape 1 : Build de l'application +FROM maven:3.9.5-eclipse-temurin-17 AS build +WORKDIR /app +COPY . . +RUN mvn clean package -DskipTests + +# Étape 2 : Image exécutable +FROM eclipse-temurin:17-jdk-alpine +VOLUME /tmp +COPY --from=build /app/target/rdv_manager_api-0.0.1-SNAPSHOT.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..bd7c7a9 --- /dev/null +++ b/README.md @@ -0,0 +1,142 @@ +# RDV Manager API + +The **RDV Manager API** is a Spring Boot-based RESTful API designed to manage appointments, clients, reminders, and related entities. It leverages MongoDB for data persistence and integrates with MapStruct and Lombok for efficient development. + +## Features + +- **CRUD Operations**: Manage clients, services, slots, reservations, and reminders. +- **MongoDB Integration**: Uses MongoDB as the database for storing entities. +- **MapStruct**: Simplifies object mapping between DTOs and entities. +- **Lombok**: Reduces boilerplate code with annotations for getters, setters, constructors, etc. +- **Spring Boot**: Provides a robust and scalable framework for building RESTful APIs. + +## Prerequisites + +Before running the project, ensure you have the following installed: + +- **Java 17** or higher +- **Maven** (for building the project) +- **MongoDB** (running locally or remotely) + +## Getting Started + +### 1. Clone the Repository +```bash +git clone https://github.com/Alwil17/rdv_manager_api.git +cd rdv_manager_api +``` + +### 2. Configure MongoDB +Update the MongoDB connection details in `application.yml`: +```bash +spring.data.mongodb.uri=mongodb://localhost:27017/rdv_manager_db +``` + +### 3. Build the Project +Run the following command to build the project: +```bash +mvn clean install +``` + +### 4. Run the Application +Start the application using: +```bash +mvn spring-boot:run +``` +The API will be available at `http://localhost:PORT`. + +## API Endpoints + +### Clients +- `POST /api/clients`: Create a new client. +- `GET /api/clients/{id}`: Retrieve a client by ID. +- `GET /api/clients`: Retrieve all clients. +- `PUT /api/clients/{id}`: Update a client. +- `DELETE /api/clients/{id}`: Delete a client. + +### Services +- `POST /api/services`: Create a new service. +- `GET /api/services/{id}`: Retrieve a service by ID. +- `GET /api/services`: Retrieve all services. +- `PUT /api/services/{id}`: Update a service. +- `DELETE /api/services/{id}`: Delete a service. + +### Services availability +- `POST /api/services/{serviceId}/availability`: Add availability to a service. +- `GET /api/services/{serviceId}/availability`: Retrieve a service availabilities. + +### Slots +- `POST /api/slots`: Create a new slot. +- `GET /api/slots/{id}`: Retrieve a slot by ID. +- `GET /api/slots`: Retrieve all slots. +- `PUT /api/slots/{id}`: Update a slot. +- `DELETE /api/slots/{id}`: Delete a slot. + +### Reservations +- `POST /api/reservations`: Create a new reservation. +- `GET /api/reservations/{id}`: Retrieve a reservation by ID. +- `GET /api/reservations`: Retrieve all reservations. +- `PUT /api/reservations/{id}`: Update a reservation. +- `DELETE /api/reservations/{id}`: Delete a reservation. + +### Reminders +- `POST /api/reminders`: Create a new reminder. +- `GET /api/reminders/{id}`: Retrieve a reminder by ID. +- `GET /api/reminders`: Retrieve all reminders. +- `PUT /api/reminders/{id}`: Update a reminder. +- `DELETE /api/reminders/{id}`: Delete a reminder. + +### Audit Logs +- `GET /api/audit-logs/{id}`: Retrieve an audit log by ID. +- `GET /api/audit-logs`: Retrieve all audit logs. +- `GET /api/audit-logs/entity`: Retrieve audit logs by entity name and ID. + +--- + +## Technologies Used + +- **Spring Boot**: Framework for building the API. +- **MongoDB**: NoSQL database for data persistence. +- **MapStruct**: For mapping between DTOs and entities. +- **Lombok**: For reducing boilerplate code. +- **Maven**: For dependency management and build automation. + +--- + +## Project Structure + +``` +src/main/java/com/grey/rdv_manager_api +├── controller # REST controllers for handling API requests +├── domain # Domain models representing database entities +├── mapper # MapStruct mappers for DTO-to-entity conversion +├── payload # Request and response DTOs +├── repository # MongoDB repositories +├── service # Service interfaces +├── service/impl # Service implementations +└── RdvManagerApi.java # Main application class +``` + +--- + +## Contributing + +Contributions are welcome! Please follow these steps: + +1. Fork the repository. +2. Create a new branch for your feature or bug fix. +3. Commit your changes and push the branch. +4. Submit a pull request. + +--- + +## License + +This project is licensed under the MIT License. See the `LICENSE` file for details. + +--- + +## Contact + +For questions or support, please contact [your-email@example.com]. + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..823177b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "${SERVER_PORT}:${SERVER_PORT}" + environment: + - SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL} + - SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME} + - SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD} + - SPRING_DATASOURCE_DRIVER-CLASS-NAME=${SPRING_DATASOURCE_DRIVER-CLASS-NAME} + - SERVER_PORT=${SERVER_PORT} + env_file: + - .env diff --git a/pom.xml b/pom.xml index e213290..b65d81e 100644 --- a/pom.xml +++ b/pom.xml @@ -33,11 +33,11 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-data-mongodb org.springframework.boot - spring-boot-starter-data-mongodb + spring-boot-starter-web org.springframework.boot @@ -47,15 +47,16 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - - org.projectlombok - lombok - true - org.springframework.boot spring-boot-devtools runtime + true + + + org.projectlombok + lombok + true org.springframework.boot @@ -63,9 +64,9 @@ test - org.springframework.security - spring-security-test - test + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.2.0 diff --git a/src/main/java/com/grey/rdv_manager_api/controller/AuditLogController.java b/src/main/java/com/grey/rdv_manager_api/controller/AuditLogController.java index 41119af..110d818 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/AuditLogController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/AuditLogController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -12,11 +11,14 @@ @RestController @RequestMapping("/api/audit-logs") -@RequiredArgsConstructor public class AuditLogController { private final AuditLogService auditLogService; + public AuditLogController(AuditLogService auditLogService) { + this.auditLogService = auditLogService; + } + @GetMapping("/{id}") public ResponseEntity getAuditLog(@PathVariable UUID id) { AuditLogResponse response = auditLogService.getById(id); diff --git a/src/main/java/com/grey/rdv_manager_api/controller/ClientController.java b/src/main/java/com/grey/rdv_manager_api/controller/ClientController.java index f0fca43..32d1c8f 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/ClientController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/ClientController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -16,11 +15,14 @@ @RestController @RequestMapping("/api/clients") -@RequiredArgsConstructor public class ClientController { private final ClientService clientService; + public ClientController(ClientService clientService) { + this.clientService = clientService; + } + @PostMapping public ResponseEntity createClient( @Validated @RequestBody CreateClientRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/controller/ReminderController.java b/src/main/java/com/grey/rdv_manager_api/controller/ReminderController.java index f04284c..742f61d 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/ReminderController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/ReminderController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -16,11 +15,14 @@ @RestController @RequestMapping("/api/reminders") -@RequiredArgsConstructor public class ReminderController { private final ReminderService reminderService; + public ReminderController(ReminderService reminderService) { + this.reminderService = reminderService; + } + @PostMapping public ResponseEntity createReminder( @Validated @RequestBody CreateReminderRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/controller/ReservationController.java b/src/main/java/com/grey/rdv_manager_api/controller/ReservationController.java index d3aaaa3..3c23070 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/ReservationController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/ReservationController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -16,11 +15,14 @@ @RestController @RequestMapping("/api/reservations") -@RequiredArgsConstructor public class ReservationController { private final ReservationService reservationService; + public ReservationController(ReservationService reservationService) { + this.reservationService = reservationService; + } + @PostMapping public ResponseEntity createReservation( @Validated @RequestBody CreateReservationRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/controller/ServiceAvailabilityController.java b/src/main/java/com/grey/rdv_manager_api/controller/ServiceAvailabilityController.java index 00071cf..e6ef0c5 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/ServiceAvailabilityController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/ServiceAvailabilityController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -15,11 +14,14 @@ import java.util.UUID; @RestController -@RequiredArgsConstructor public class ServiceAvailabilityController { private final ServiceAvailabilityService serviceAvailabilityService; + public ServiceAvailabilityController(ServiceAvailabilityService serviceAvailabilityService) { + this.serviceAvailabilityService = serviceAvailabilityService; + } + /** * Create a new availability slot for a service */ diff --git a/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java b/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java index c0e9218..f15d9da 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -16,11 +15,14 @@ @RestController @RequestMapping("/api/services") -@RequiredArgsConstructor public class ServiceController { private final ServiceEntityService serviceService; + public ServiceController(ServiceEntityService serviceService) { + this.serviceService = serviceService; + } + @PostMapping public ResponseEntity createService( @Validated @RequestBody CreateServiceRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/controller/SlotController.java b/src/main/java/com/grey/rdv_manager_api/controller/SlotController.java index afdb589..d107de2 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/SlotController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/SlotController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -16,11 +15,14 @@ @RestController @RequestMapping("/api/slots") -@RequiredArgsConstructor public class SlotController { private final SlotService slotService; + public SlotController(SlotService slotService) { + this.slotService = slotService; + } + @PostMapping public ResponseEntity createSlot( @Validated @RequestBody CreateSlotRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/controller/StructureController.java b/src/main/java/com/grey/rdv_manager_api/controller/StructureController.java index 03f80c8..1c4eb63 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/StructureController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/StructureController.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.controller; -import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -16,11 +15,14 @@ @RestController @RequestMapping("/api/structures") -@RequiredArgsConstructor public class StructureController { private final StructureService structureService; + public StructureController(StructureService structureService) { + this.structureService = structureService; + } + @PostMapping public ResponseEntity createStructure( @Validated @RequestBody CreateStructureRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/AuditLog.java b/src/main/java/com/grey/rdv_manager_api/domain/model/AuditLog.java index 1458d94..bddbe06 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/AuditLog.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/AuditLog.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -14,7 +16,8 @@ * Audit log for tracking create/update/delete actions on entities. */ @Document(collection = "audit_logs") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -28,4 +31,51 @@ public class AuditLog { private String performedBy; private LocalDateTime timestamp; private String details; + + // Getters + public UUID getId() { + return id; + } + public String getEntityName() { + return entityName; + } + public UUID getEntityId() { + return entityId; + } + public String getAction() { + return action; + } + public String getPerformedBy() { + return performedBy; + } + public LocalDateTime getTimestamp() { + return timestamp; + } + public String getDetails() { + return details; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setEntityName(String entityName) { + this.entityName = entityName; + } + public void setEntityId(UUID entityId) { + this.entityId = entityId; + } + + public void setAction(String action) { + this.action = action; + } + public void setPerformedBy(String performedBy) { + this.performedBy = performedBy; + } + public void setTimestamp(LocalDateTime timestamp) { + this.timestamp = timestamp; + } + public void setDetails(String details) { + this.details = details; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/Client.java b/src/main/java/com/grey/rdv_manager_api/domain/model/Client.java index 15b75fd..274b8f7 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/Client.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/Client.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -16,7 +18,8 @@ import java.util.UUID; @Document(collection = "clients") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -37,5 +40,77 @@ public class Client { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + // passwordHash Getter and Setter + public String getPasswordHash() { + return passwordHash; + } + public void setPasswordHash(String passwordHash) { + this.passwordHash = passwordHash; + } + + // roles Getter and Setter + public List getRoles() { + return roles; + } + public void setRoles(List roles) { + this.roles = roles; + } + // structureId Getter and Setter + public UUID getStructureId() { + return structureId; + } + public void setStructureId(UUID structureId) { + this.structureId = structureId; + } + // createdAt Getter and Setter + public LocalDateTime getCreatedAt() { + return createdAt; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + // updatedAt Getter and Setter + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + // firstName Getter and Setter + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + // lastName Getter and Setter + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + // email Getter and Setter + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + // phone Getter and Setter + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + // id Getter and Setter + public UUID getId() { + return id; + } + public void setId(UUID id) { + this.id = id; + } } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/Reminder.java b/src/main/java/com/grey/rdv_manager_api/domain/model/Reminder.java index ec47f21..41e93cc 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/Reminder.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/Reminder.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -18,7 +20,8 @@ * Reminder entity for reservation notifications. */ @Document(collection = "reminders") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -37,4 +40,50 @@ public class Reminder { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + // Getters + public UUID getId() { + return id; + } + public UUID getReservationId() { + return reservationId; + } + public LocalDateTime getReminderTime() { + return reminderTime; + } + public ReminderMethod getMethod() { + return method; + } + public boolean isSent() { + return sent; + } + public LocalDateTime getCreatedAt() { + return createdAt; + } + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setReservationId(UUID reservationId) { + this.reservationId = reservationId; + } + public void setReminderTime(LocalDateTime reminderTime) { + this.reminderTime = reminderTime; + } + public void setMethod(ReminderMethod method) { + this.method = method; + } + public void setSent(boolean sent) { + this.sent = sent; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/Reservation.java b/src/main/java/com/grey/rdv_manager_api/domain/model/Reservation.java index 6423c19..e457355 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/Reservation.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/Reservation.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -18,7 +20,8 @@ * Reservation entity representing a client's booking of a slot. */ @Document(collection = "reservations") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -38,5 +41,46 @@ public class Reservation { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + // Getters + public UUID getId() { + return id; + } + + public UUID getClientId() { + return clientId; + } + public UUID getSlotId() { + return slotId; + } + public ReservationStatus getStatus() { + return status; + } + public LocalDateTime getCreatedAt() { + return createdAt; + } + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setClientId(UUID clientId) { + this.clientId = clientId; + } + public void setSlotId(UUID slotId) { + this.slotId = slotId; + } + public void setStatus(ReservationStatus status) { + this.status = status; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceAvailability.java b/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceAvailability.java index d5a101f..e4e469f 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceAvailability.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceAvailability.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -19,7 +21,8 @@ * Weekly availability schedule for a Service on a specific day of week. */ @Document(collection = "service_availability") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -38,5 +41,51 @@ public class ServiceAvailability { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + // Getters + public UUID getId() { + return id; + } + public UUID getServiceId() { + return serviceId; + } + public Weekday getDayOfWeek() { + return dayOfWeek; + } + public LocalTime getStartTime() { + return startTime; + } + public LocalTime getEndTime() { + return endTime; + } + public LocalDateTime getCreatedAt() { + return createdAt; + } + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setServiceId(UUID serviceId) { + this.serviceId = serviceId; + } + public void setDayOfWeek(Weekday dayOfWeek) { + this.dayOfWeek = dayOfWeek; + } + public void setStartTime(LocalTime startTime) { + this.startTime = startTime; + } + public void setEndTime(LocalTime endTime) { + this.endTime = endTime; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceEntity.java b/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceEntity.java index d2d0aac..1532196 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceEntity.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/ServiceEntity.java @@ -4,8 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -17,7 +19,8 @@ * Service entity offered by a Structure. */ @Document(collection = "services") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -36,4 +39,50 @@ public class ServiceEntity { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + // Getters + public UUID getId() { + return id; + } + public UUID getStructureId() { + return structureId; + } + public String getName() { + return name; + } + public String getDescription() { + return description; + } + public String getTimezone() { + return timezone; + } + public LocalDateTime getCreatedAt() { + return createdAt; + } + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setStructureId(UUID structureId) { + this.structureId = structureId; + } + public void setName(String name) { + this.name = name; + } + public void setDescription(String description) { + this.description = description; + } + public void setTimezone(String timezone) { + this.timezone = timezone; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/Slot.java b/src/main/java/com/grey/rdv_manager_api/domain/model/Slot.java index 1d88fe3..5da44c2 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/Slot.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/Slot.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -18,7 +20,8 @@ * Slot entity representing a bookable time slot on a specific date. */ @Document(collection = "slots") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -39,4 +42,64 @@ public class Slot { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + public int getAvailable() { + return available; + } + + public void setAvailable(int available) { + this.available = available; + } + + // Getters + public UUID getId() { + return id; + } + public LocalDate getDate() { + return date; + } + public LocalTime getStartTime() { + return startTime; + } + public LocalTime getEndTime() { + return endTime; + } + public int getCapacity() { + return capacity; + } + public UUID getServiceId() { + return serviceId; + } + public LocalDateTime getCreatedAt() { + return createdAt; + } + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setDate(LocalDate date) { + this.date = date; + } + public void setStartTime(LocalTime startTime) { + this.startTime = startTime; + } + public void setEndTime(LocalTime endTime) { + this.endTime = endTime; + } + public void setCapacity(int capacity) { + this.capacity = capacity; + } + public void setServiceId(UUID serviceId) { + this.serviceId = serviceId; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/domain/model/Structure.java b/src/main/java/com/grey/rdv_manager_api/domain/model/Structure.java index a0cdcc1..34c5c25 100644 --- a/src/main/java/com/grey/rdv_manager_api/domain/model/Structure.java +++ b/src/main/java/com/grey/rdv_manager_api/domain/model/Structure.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.LastModifiedDate; @@ -13,7 +15,8 @@ import java.util.UUID; @Document(collection = "structures") -@Data +@Getter +@Setter @Builder @NoArgsConstructor @AllArgsConstructor @@ -32,4 +35,62 @@ public class Structure { private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; + + // Getters + public UUID getId() { + return id; + } + public String getName() { + return name; + } + public String getDescription() { + return description; + } + public String getAddress() { + return address; + } + public String getPhone() { + return phone; + } + public String getEmail() { + return email; + } + public String getTimezone() { + return timezone; + } + public LocalDateTime getCreatedAt() { + return createdAt; + } + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + // Setters + public void setId(UUID id) { + this.id = id; + } + public void setName(String name) { + this.name = name; + } + public void setDescription(String description) { + this.description = description; + } + public void setAddress(String address) { + this.address = address; + } + public void setPhone(String phone) { + this.phone = phone; + } + public void setEmail(String email) { + this.email = email; + } + public void setTimezone(String timezone) { + this.timezone = timezone; + } + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + } diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/AuditLogServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/AuditLogServiceImpl.java index c3c7531..bf329f6 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/AuditLogServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/AuditLogServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import com.grey.rdv_manager_api.domain.model.AuditLog; @@ -13,12 +12,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class AuditLogServiceImpl implements AuditLogService { private final AuditLogRepository repository; private final AuditLogMapper mapper; + public AuditLogServiceImpl(AuditLogRepository repository, AuditLogMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override public AuditLogResponse getById(UUID id) { AuditLog entity = repository.findById(id) diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ClientServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ClientServiceImpl.java index 182e948..fc908b4 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ClientServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ClientServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,17 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class ClientServiceImpl implements ClientService { private final ClientRepository repository; private final ClientMapper mapper; + + public ClientServiceImpl(ClientRepository repository, ClientMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public ClientResponse create(CreateClientRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ReminderServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ReminderServiceImpl.java index 0d7a5e9..ed5f38c 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ReminderServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ReminderServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class ReminderServiceImpl implements ReminderService { private final ReminderRepository repository; private final ReminderMapper mapper; + public ReminderServiceImpl(ReminderRepository repository, ReminderMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public ReminderResponse create(CreateReminderRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java index 4deb23f..77919cf 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class ReservationServiceImpl implements ReservationService { private final ReservationRepository repository; private final ReservationMapper mapper; + public ReservationServiceImpl(ReservationRepository repository, ReservationMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public ReservationResponse create(CreateReservationRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceAvailabilityServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceAvailabilityServiceImpl.java index 9a982e8..290efdc 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceAvailabilityServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceAvailabilityServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class ServiceAvailabilityServiceImpl implements ServiceAvailabilityService { private final ServiceAvailabilityRepository repository; private final ServiceAvailabilityMapper mapper; + public ServiceAvailabilityServiceImpl(ServiceAvailabilityRepository repository, ServiceAvailabilityMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public ServiceAvailabilityResponse create(UUID serviceId, CreateServiceAvailabilityRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java index 8166260..3752068 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class ServiceEntityServiceImpl implements ServiceEntityService { private final ServiceRepository repository; private final ServiceEntityMapper mapper; + public ServiceEntityServiceImpl(ServiceRepository repository, ServiceEntityMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public ServiceResponse create(CreateServiceRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java index 2e4d03d..464ff3b 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class SlotServiceImpl implements SlotService { private final SlotRepository repository; private final SlotMapper mapper; + public SlotServiceImpl(SlotRepository repository, SlotMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public SlotResponse create(CreateSlotRequest request) { diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/StructureServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/StructureServiceImpl.java index 88f46e1..700dfee 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/StructureServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/StructureServiceImpl.java @@ -1,6 +1,5 @@ package com.grey.rdv_manager_api.service.impl; -import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,12 +15,16 @@ import java.util.UUID; @Service -@RequiredArgsConstructor public class StructureServiceImpl implements StructureService { private final StructureRepository repository; private final StructureMapper mapper; + public StructureServiceImpl(StructureRepository repository, StructureMapper mapper) { + this.repository = repository; + this.mapper = mapper; + } + @Override @Transactional public StructureResponse create(CreateStructureRequest request) { diff --git a/src/main/resources/applicaltion.yml b/src/main/resources/application.yml similarity index 57% rename from src/main/resources/applicaltion.yml rename to src/main/resources/application.yml index 965e387..aec45c4 100644 --- a/src/main/resources/applicaltion.yml +++ b/src/main/resources/application.yml @@ -1,15 +1,18 @@ server: - port: 8383 + port: ${SERVER_PORT:8080} springdoc: swagger-ui: path: /swagger-ui.html spring: data: mongodb: - uri: mongodb+srv://bvrjnhl:IxSi1MduzkPqvvhx@cluster0.erw7h.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0 + uri: ${SPRING_MONGO_URL} + username: ${SPRING_MONGO_USERNAME} + password: ${SPRING_MONGO_PASSWORD} database: rdv_manager_db - profiles: - active: debug + hikari: + minimum-idle: 3 + maximum-pool-size: 5 servlet: multipart: enabled: true @@ -21,4 +24,4 @@ logging: level: root: INFO org.springframework.web: DEBUG - com.grey.sytsas: DEBUG \ No newline at end of file + com.grey.rdv_manager_api: DEBUG \ No newline at end of file From 2984fff2747669d6906ec84ac753e46f270aba62 Mon Sep 17 00:00:00 2001 From: alwil17 Date: Tue, 13 May 2025 07:51:20 +0000 Subject: [PATCH 2/3] Added dotenv --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index d01cfe0..c6322e0 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,4 @@ SERVER_PORT=8080 SPRING_MONGO_URL=[YOUR_DB_URL] SPRING_MONGO_USERNAME=[YOUR_DB_USER] -SPRING_MONGO_PASSWORD=[YOUR_DB_PASSWORD] \ No newline at end of file +SPRING_MONGO_PASSWORD=[YOUR_DB_PASSWORD] From 57c98d2b4f443cde895984a9c73eaaa5e724bc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Ga=C3=ABl?= <61506484+Alwil17@users.noreply.github.com> Date: Tue, 20 May 2025 17:07:49 +0000 Subject: [PATCH 3/3] Feat/reservation (#21) * Enhance reservation creation by adding slot availability check and updating slot status * Set slot availability during creation * Add endpoint to retrieve services by structure ID * Add .dockerignore file to exclude unnecessary files from Docker context --- .dockerignore | 14 +++++++++++++ .../controller/ServiceController.java | 6 ++++++ .../service/ServiceEntityService.java | 1 + .../service/impl/ReservationServiceImpl.java | 21 ++++++++++++++++++- .../impl/ServiceEntityServiceImpl.java | 5 +++++ .../service/impl/SlotServiceImpl.java | 1 + 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..276e3ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +*.db +*.sqlite3 +.git +.gitignore +resources/ +venv/ +.venv/ +.idea/ +.vscode/ +target/ \ No newline at end of file diff --git a/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java b/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java index f15d9da..0ab83b1 100644 --- a/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java +++ b/src/main/java/com/grey/rdv_manager_api/controller/ServiceController.java @@ -55,4 +55,10 @@ public ResponseEntity updateService( public void deleteService(@PathVariable UUID id) { serviceService.delete(id); } + + @GetMapping("/structure/{structureId}") + public ResponseEntity> getServicesByStructure(@PathVariable UUID structureId) { + List list = serviceService.getByStructureId(structureId); + return ResponseEntity.ok(list); + } } \ No newline at end of file diff --git a/src/main/java/com/grey/rdv_manager_api/service/ServiceEntityService.java b/src/main/java/com/grey/rdv_manager_api/service/ServiceEntityService.java index 6a6b737..ed9f1f9 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/ServiceEntityService.java +++ b/src/main/java/com/grey/rdv_manager_api/service/ServiceEntityService.java @@ -13,4 +13,5 @@ public interface ServiceEntityService { List getAll(); ServiceResponse update(UUID id, UpdateServiceRequest request); void delete(UUID id); + List getByStructureId(UUID structureId); } diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java index 77919cf..68d602c 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ReservationServiceImpl.java @@ -3,12 +3,15 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.grey.rdv_manager_api.domain.enums.ReservationStatus; import com.grey.rdv_manager_api.domain.model.Reservation; +import com.grey.rdv_manager_api.domain.model.Slot; import com.grey.rdv_manager_api.mapper.ReservationMapper; import com.grey.rdv_manager_api.payload.request.CreateReservationRequest; import com.grey.rdv_manager_api.payload.request.UpdateReservationRequest; import com.grey.rdv_manager_api.payload.response.ReservationResponse; import com.grey.rdv_manager_api.repository.ReservationRepository; +import com.grey.rdv_manager_api.repository.SlotRepository; import com.grey.rdv_manager_api.service.ReservationService; import java.util.List; @@ -18,18 +21,34 @@ public class ReservationServiceImpl implements ReservationService { private final ReservationRepository repository; + private final SlotRepository slotRepository; private final ReservationMapper mapper; - public ReservationServiceImpl(ReservationRepository repository, ReservationMapper mapper) { + public ReservationServiceImpl(ReservationRepository repository, ReservationMapper mapper, SlotRepository slotRepository) { this.repository = repository; this.mapper = mapper; + this.slotRepository = slotRepository; } @Override @Transactional public ReservationResponse create(CreateReservationRequest request) { + // Check slot availability + Slot slot = slotRepository.findById(request.slotId()) + .orElseThrow(() -> new RuntimeException("Slot not found: " + request.slotId())); + if (slot.getAvailable() <= 0) { + throw new RuntimeException("No available places for this slot."); + } + + // Proceed with reservation Reservation entity = mapper.toEntity(request); entity.setId(UUID.randomUUID()); + entity.setStatus(ReservationStatus.PENDING); + + // Decrement slot availability + slot.setAvailable(slot.getAvailable() - 1); + slotRepository.save(slot); + Reservation saved = repository.save(entity); return mapper.toResponse(saved); } diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java index 3752068..d846635 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/ServiceEntityServiceImpl.java @@ -61,4 +61,9 @@ public ServiceResponse update(UUID id, UpdateServiceRequest request) { public void delete(UUID id) { repository.deleteById(id); } + + @Override + public List getByStructureId(UUID structureId) { + return mapper.toResponseList(repository.findByStructureId(structureId)); + } } \ No newline at end of file diff --git a/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java b/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java index 464ff3b..96bb2e1 100644 --- a/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java +++ b/src/main/java/com/grey/rdv_manager_api/service/impl/SlotServiceImpl.java @@ -30,6 +30,7 @@ public SlotServiceImpl(SlotRepository repository, SlotMapper mapper) { public SlotResponse create(CreateSlotRequest request) { Slot entity = mapper.toEntity(request); entity.setId(UUID.randomUUID()); + entity.setAvailable(request.capacity()); Slot saved = repository.save(entity); return mapper.toResponse(saved); }