🏫 School Microservice
Conception et développement d'un microservice REST en utilisant Spring Boot 4.0.6 et Spring Data JPA, avec une base de données PostgreSQL.
school-microservice/
├── src/
│ └── main/
│ ├── java/
│ │ └── edu/isgb/school/
│ │ ├── entities/ # Entités JPA
│ │ │ ├── School.java
│ │ │ ├── Department.java
│ │ │ ├── Student.java
│ │ │ ├── Address.java
│ │ │ ├── Instructor.java
│ │ │ └── Course.java
│ │ ├── repositories/ # Interfaces Spring Data JPA
│ │ │ ├── SchoolRepository.java
│ │ │ ├── StudentRepository.java
│ │ │ ├── InstructorRepository.java
│ │ │ ├── CourseRepository.java
│ │ │ └── DepartmentRepository.java
│ │ ├── services/ # Logique métier
│ │ │ └── SchoolService.java
│ │ └── Controller/ # Contrôleur REST
│ │ └── TestSchoolController.java
│ └── resources/
│ └── application.properties
└── pom.xml
Le projet implémente le diagramme de classes complet avec les règles de navigabilité suivantes :
| Relation | Type de mapping |
|---|---|
Student → Address |
Unidirectionnel @OneToOne |
School ↔ Department |
Bidirectionnel @OneToMany / @ManyToOne |
School ↔ Student |
Bidirectionnel @OneToMany / @ManyToOne |
School ↔ Instructor |
Bidirectionnel @OneToMany / @ManyToOne |
Instructor ↔ Course |
Bidirectionnel @ManyToMany |
- Java 21
- PostgreSQL installé et démarré
- IntelliJ IDEA (ou autre IDE)
Créer la base de données PostgreSQL :
CREATE DATABASE schooldb;spring.datasource.url=jdbc:postgresql://localhost:5432/schooldb
spring.datasource.username=postgres
spring.datasource.password=votre_mot_de_passe
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true- Cloner le dépôt :
git clone https://github.com/votre-repo/school-microservice.git-
Ouvrir le projet dans IntelliJ IDEA
-
Recharger Maven : clic droit sur
pom.xml→ Maven → Reload Project -
Lancer la classe principale
SchoolMicroserviceApplication.java
| Méthode | URL | Description |
|---|---|---|
POST |
/api/schools |
Créer une nouvelle école |
GET |
/api/schools/{id} |
Récupérer une école par id |
POST |
/api/students?schoolId=1 |
Créer un étudiant avec adresse |
GET |
/api/students |
Lister tous les étudiants |
POST |
/api/instructors |
Créer un instructeur avec ses cours |
GET |
/api/instructors?name=... |
Chercher un instructeur par nom |
GET |
/api/instructors/{id} |
Récupérer un instructeur par id |
GET |
/api/instructors/{id}/courses |
Lister les cours d'un instructeur |
POST |
/api/instructors/{id}/courses |
Ajouter un cours à un instructeur |
GET |
/api/courses/{id} |
Récupérer un cours par id |
Controller → Service → Repository → Base de données (REST) (Métier) (Spring Data) (PostgreSQL)
Les endpoints ont été testés avec Postman.Voir compte rendu.
Compte Rendu : COMPTE RENDU Azzouz Malek 2LIG1 & Lahbib Malek 2LIG2.pdf