From 36e496739497a0dc9157fe4ec55e55b8d04e4fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Tue, 11 Feb 2025 00:08:53 +0100 Subject: [PATCH 01/97] Feat: first implementation of postgres db for backend --- MyINPulse-back/build.gradle | 4 + .../controller/AdministrateursController.java | 39 ++++++ .../controller/ComptesRendusController.java | 49 +++++++ .../controller/EntrepreneursController.java | 59 +++++++++ .../controller/ProjetsController.java | 61 +++++++++ .../controller/RendezVousController.java | 64 +++++++++ .../controller/SectionsController.java | 58 +++++++++ .../controller/UtilisateursController.java | 61 +++++++++ .../postgres_db/model/Administrateurs.java | 34 +++++ .../postgres_db/model/ComptesRendus.java | 48 +++++++ .../postgres_db/model/Entrepreneurs.java | 66 ++++++++++ .../myinpulse/postgres_db/model/Projets.java | 95 ++++++++++++++ .../postgres_db/model/RendezVous.java | 107 +++++++++++++++ .../myinpulse/postgres_db/model/Sections.java | 78 +++++++++++ .../postgres_db/model/Utilisateurs.java | 90 +++++++++++++ .../repository/AdministrateursRepository.java | 13 ++ .../repository/ComptesRendusRepository.java | 9 ++ .../repository/EntrepreneursRepository.java | 13 ++ .../repository/ProjetsRepository.java | 9 ++ .../repository/RendezVousRepository.java | 9 ++ .../repository/SectionsRepository.java | 9 ++ .../repository/UtilisateursRepository.java | 13 ++ .../src/main/resources/application.properties | 7 + MyINPulse-back/src/main/resources/data.sql | 63 +++++++++ MyINPulse-back/src/main/resources/schema.sql | 122 ++++++++++++++++++ config/backdev.docker-compose.yaml | 4 +- config/backdev.main.env | 6 +- .../src/components/temp-modal.vue | 18 +++ 28 files changed, 1205 insertions(+), 3 deletions(-) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java create mode 100644 MyINPulse-back/src/main/resources/data.sql create mode 100644 MyINPulse-back/src/main/resources/schema.sql create mode 100644 front/MyINPulse-front/src/components/temp-modal.vue diff --git a/MyINPulse-back/build.gradle b/MyINPulse-back/build.gradle index abdd6a9..5d1c2fd 100644 --- a/MyINPulse-back/build.gradle +++ b/MyINPulse-back/build.gradle @@ -20,6 +20,10 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation('org.springframework.boot:spring-boot-starter-validation') + implementation('org.springframework.boot:spring-boot-starter-data-rest') + implementation 'org.postgresql:postgresql' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java new file mode 100644 index 0000000..5f1a718 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java @@ -0,0 +1,39 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.AdministrateursRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.Administrateurs; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class AdministrateursController { + + @Autowired + AdministrateursRepository administrateursRepository; + + @GetMapping("/Administrateurs") + @ResponseBody + public Iterable allAdministrateurs() { + return this.administrateursRepository.findAll(); + } + + @GetMapping("/Administrateurs/{id}") + public Administrateurs getAdministrateursById(@PathVariable Long id) + { + Optional administrateur = this.administrateursRepository.findById(id); + if (administrateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + return administrateur.get(); + } + + @PostMapping("/Administrateurs") + public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { + return this.administrateursRepository.save(administrateurs); + } + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java new file mode 100644 index 0000000..9bcc862 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -0,0 +1,49 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.ComptesRendus; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class ComptesRendusController { + + @Autowired + ComptesRendusRepository comptesRendusRepository; + + @GetMapping("/ComptesRendus") + @ResponseBody + public Iterable allComptesRendus() { + return this.comptesRendusRepository.findAll(); + } + + @GetMapping("/ComptesRendus/{id}") + public ComptesRendus getComptesRendusById(@PathVariable Long id) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + return compteRendu.get(); + } + + @PostMapping("/ComptesRendus") + public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { + return this.comptesRendusRepository.save(comptesRendus); + } + + @PostMapping("/ComptesRendus/{id}") + public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + if (contenu_compte_rendu != null) { + compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); + } + return compteRendu.get(); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java new file mode 100644 index 0000000..2bbc653 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -0,0 +1,59 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.Entrepreneurs; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + + +@RestController +public class EntrepreneursController { + + @Autowired + EntrepreneursRepository entrepreneursRepository; + + @GetMapping("/Entrepreneurs") + @ResponseBody + public Iterable allEntrepreneurs() { + return this.entrepreneursRepository.findAll(); + } + + @GetMapping("/Entrepreneurs/{id}") + public Entrepreneurs getEntrepreneursById(@PathVariable Long id) + { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + return entrepreneur.get(); + } + + @PostMapping("/Entrepreneurs") + public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { + return this.entrepreneursRepository.save(entrepreneurs); + } + + @PostMapping("/Entrepreneurs/{id}") + public Entrepreneurs updateEntrepreneurs(@PathVariable Long id, String ecole, String filiere, Boolean status_snee) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + if (ecole != null) { + entrepreneur.get().setEcole(ecole); + } + if (filiere != null) { + entrepreneur.get().setFiliere(filiere); + } + if (status_snee != null) { + entrepreneur.get().setStatus_snee(status_snee); + } + return entrepreneur.get(); + } + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java new file mode 100644 index 0000000..92b5908 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -0,0 +1,61 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.ProjetsRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.Projets; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.util.Optional; + +@RestController +public class ProjetsController { + + @Autowired + ProjetsRepository projetsRepository; + + @GetMapping("/Projets") + @ResponseBody + public Iterable allProjets() { + return this.projetsRepository.findAll(); + } + + @GetMapping("/Projets/{id}") + public Projets getProjetsById(@PathVariable Long id) + { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + return projet.get(); + } + + @PostMapping("/Projets") + public Projets addProjets(@RequestBody Projets projet) { + return this.projetsRepository.save(projet); + } + + @PostMapping("/Projets/{id}") + public Projets updateProjets(@PathVariable Long id, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + if (nom_projet != null) { + projet.get().setNom_projet(nom_projet); + } + if (logo != null) { + projet.get().setLogo(logo); + } + if (date_creation != null) { + projet.get().setDate_creation(date_creation); + } + if (status_projet != null) { + projet.get().setStatus_projet(status_projet); + } + return projet.get(); + } + +} \ No newline at end of file diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java new file mode 100644 index 0000000..aa9e3ba --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -0,0 +1,64 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.RendezVousRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.RendezVous; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Optional; + +@RestController +public class RendezVousController { + + @Autowired + RendezVousRepository rendezVousRepository; + + @GetMapping("/RendezVous") + @ResponseBody + public Iterable allRendezVous() { + return this.rendezVousRepository.findAll(); + } + + @GetMapping("/RendezVous/{id}") + public RendezVous getRendezVousById(@PathVariable Long id) + { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + return rendezVous.get(); + } + + @PostMapping("/RendezVous") + public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { + return this.rendezVousRepository.save(rendezVous); + } + + @PostMapping("/RendezVous/{id}") + public RendezVous updateRendezVous(@PathVariable Long id, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + if (date_rdv != null) { + rendezVous.get().setDate_rdv(date_rdv); + } + if (heure_rdv != null) { + rendezVous.get().setHeure_rdv(heure_rdv); + } + if (duree_rdv != null) { + rendezVous.get().setDuree_rdv(duree_rdv); + } + if (lieu_rdv != null) { + rendezVous.get().setLieu_rdv(lieu_rdv); + } + if (sujet_rdv != null) { + rendezVous.get().setSujet_rdv(sujet_rdv); + } + return rendezVous.get(); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java new file mode 100644 index 0000000..49032fe --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -0,0 +1,58 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.SectionsRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.Sections; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDateTime; +import java.util.Optional; + +@RestController +public class SectionsController { + + @Autowired + SectionsRepository sectionsRepository; + + @GetMapping("/Sections") + @ResponseBody + public Iterable allSections() { + return this.sectionsRepository.findAll(); + } + + @GetMapping("/Sections/{id}") + public Sections getSectionsById(@PathVariable Long id) + { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + } + return section.get(); + } + + @PostMapping("/Sections") + public Sections addSections(@RequestBody Sections sections) { + return this.sectionsRepository.save(sections); + } + + @PostMapping("/Sections/{id}") + public Sections updateSections(@PathVariable Long id, String titre, String contenu_section, LocalDateTime date_modification) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + } + if (titre != null) { + section.get().setTitre(titre); + } + if (contenu_section != null) { + section.get().setContenu_section(contenu_section); + } + if (date_modification != null) { + section.get().setDate_modification(date_modification); + } + return section.get(); + } + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java new file mode 100644 index 0000000..059e2f0 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -0,0 +1,61 @@ +package enseirb.myinpulse.postgres_db.controller; + +import enseirb.myinpulse.postgres_db.repository.UtilisateursRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import enseirb.myinpulse.postgres_db.model.Utilisateurs; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class UtilisateursController { + + @Autowired + UtilisateursRepository utilisateursRepository; + + @GetMapping("/Utilisateurs") + @ResponseBody + public Iterable allUtilisateurs() { + return this.utilisateursRepository.findAll(); + } + + @GetMapping("/Utilisateurs/{id}") + public Utilisateurs getUtilisateursById(@PathVariable Long id) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + return utilisateur.get(); + } + + @PostMapping("/Utilisateurs") + public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { + return this.utilisateursRepository.save(utilisateurs); + } + + @PostMapping("/Utilisateurs/{id}") + public Utilisateurs updateUtilisateurs(@PathVariable Long id, String nom_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + }if (nom_utilisateur != null) { + utilisateur.get().setNom_utilisateur(nom_utilisateur); + } + if (prenom_utilisateur != null) { + utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); + } + if (mail_principal != null) { + utilisateur.get().setMail_principal(mail_principal); + } + if (mail_secondaire != null) { + utilisateur.get().setMail_secondaire(mail_secondaire); + } + if (numero_telephone != null) { + utilisateur.get().setNumero_telephone(numero_telephone); + } + return utilisateur.get(); + } + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java new file mode 100644 index 0000000..0255adf --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -0,0 +1,34 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.*; +import jakarta.persistence.PrimaryKeyJoinColumn; +import jakarta.persistence.Table; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "administrateurs") +@PrimaryKeyJoinColumn(name = "id_administrateur") + +public class Administrateurs extends Utilisateurs { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "Projets.id_projets") + private Projets projets; + + @OneToMany(mappedBy = "administrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RendezVous.id_rdv") + private RendezVous rendezVous; + + public Administrateurs() { + } + + public Administrateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); + } + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java new file mode 100644 index 0000000..cd7f283 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java @@ -0,0 +1,48 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.*; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "comptes_rendus") +public class ComptesRendus { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_compte_rendu; + + private String contenu_compte_rendu; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RendezVous.id_rdv") + private RendezVous rendezVous; + + + public ComptesRendus() { + } + + public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + this.contenu_compte_rendu = contenu_compte_rendu; + } + + public Long getId_compte_rendu() { + return id_compte_rendu; + } + + public void setId_compte_rendu(Long id_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + } + + public String getContenu_compte_rendu() { + return contenu_compte_rendu; + } + + public void setContenu_compte_rendu(String contenu_compte_rendu) { + this.contenu_compte_rendu = contenu_compte_rendu; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java new file mode 100644 index 0000000..b8f6964 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java @@ -0,0 +1,66 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.*; +import jakarta.persistence.Table; + +@Entity +@Table(name = "entrepreneurs") +@PrimaryKeyJoinColumn(name = "id_entrepreneur") +public class Entrepreneurs extends Utilisateurs { + + @Column(length=255) + private String ecole; + + @Column(length=255) + private String filiere; + + private boolean status_snee; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "Projets.id_projets") + private Projets projets_participation; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "Projets.id_projets") + private Projets projets_propose; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RendezVous.id_rdv") + private RendezVous rendezVous; + + + public Entrepreneurs() { + } + + public Entrepreneurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone, String ecole, boolean status_snee, String filiere) { + super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); + this.ecole = ecole; + this.status_snee = status_snee; + this.filiere = filiere; + } + + public String getEcole() { + return ecole; + } + + public void setEcole(String ecole) { + this.ecole = ecole; + } + + public String getFiliere() { + return filiere; + } + + public void setFiliere(String filiere) { + this.filiere = filiere; + } + + public boolean isStatus_snee() { + return status_snee; + } + + public void setStatus_snee(boolean status_snee) { + this.status_snee = status_snee; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java new file mode 100644 index 0000000..6fd8d98 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java @@ -0,0 +1,95 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "projets") +public class Projets { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_projet; + + @Column(length=255) + private String nom_projet; + + private Byte[] logo; + + private LocalDate date_creation; + + @Column(length=255) + private String status_projet; + + @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) + private List listAdministrateurs = new ArrayList<>(); + + @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneursParticipation = new ArrayList<>(); + + @OneToOne(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) + private Entrepreneurs entrepreneurs_propose; + + @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); + + // Hibernate expects entities to have a no-arg constructor, + // though it does not necessarily have to be public. + + public Projets() { + } + + public Projets(Long id_projet, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { + this.id_projet = id_projet; + this.nom_projet = nom_projet; + this.logo = logo; + this.date_creation = date_creation; + this.status_projet = status_projet; + } + + public Long getId_projet() { + return id_projet; + } + + public void setId_projet(Long id_projet) { + this.id_projet = id_projet; + } + + public String getNom_projet() { + return nom_projet; + } + + public void setNom_projet(String nom_projet) { + this.nom_projet = nom_projet; + } + + public Byte[] getLogo() { + return logo; + } + + public void setLogo(Byte[] logo) { + this.logo = logo; + } + + public LocalDate getDate_creation() { + return date_creation; + } + + public void setDate_creation(LocalDate date_creation) { + this.date_creation = date_creation; + } + + public String getStatus_projet() { + return status_projet; + } + + public void setStatus_projet(String status_projet) { + this.status_projet = status_projet; + } + +} \ No newline at end of file diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java new file mode 100644 index 0000000..78fbfc2 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -0,0 +1,107 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "rendez_vous") +public class RendezVous { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_rdv; + + private LocalDate date_rdv; + + private LocalDateTime heure_rdv; + + private LocalDateTime duree_rdv; + + @Column(length=255) + private String lieu_rdv; + + private String sujet_rdv; + + @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneurs = new ArrayList<>(); + + @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListAdministrateurs = new ArrayList<>(); + + @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListComptesRendus = new ArrayList<>(); + + @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }) + @JoinTable( + name = "concerner", + joinColumns = @JoinColumn(name = "id_rdv"), + inverseJoinColumns = @JoinColumn(name = "id_sections")) + List ListSections = new ArrayList<>(); + + public RendezVous() { + } + + public RendezVous(Long id_rdv, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { + this.id_rdv = id_rdv; + this.date_rdv = date_rdv; + this.heure_rdv = heure_rdv; + this.duree_rdv = duree_rdv; + this.lieu_rdv = lieu_rdv; + this.sujet_rdv = sujet_rdv; + } + + public Long getId_rdv() { + return id_rdv; + } + + public void setId_rdv(Long id_rdv) { + this.id_rdv = id_rdv; + } + + public LocalDate getDate_rdv() { + return date_rdv; + } + + public void setDate_rdv(LocalDate date_rdv) { + this.date_rdv = date_rdv; + } + + public LocalDateTime getHeure_rdv() { + return heure_rdv; + } + + public void setHeure_rdv(LocalDateTime heure_rdv) { + this.heure_rdv = heure_rdv; + } + + public LocalDateTime getDuree_rdv() { + return duree_rdv; + } + + public void setDuree_rdv(LocalDateTime duree_rdv) { + this.duree_rdv = duree_rdv; + } + + public String getLieu_rdv() { + return lieu_rdv; + } + + public void setLieu_rdv(String lieu_rdv) { + this.lieu_rdv = lieu_rdv; + } + + public String getSujet_rdv() { + return sujet_rdv; + } + + public void setSujet_rdv(String sujet_rdv) { + this.sujet_rdv = sujet_rdv; + } + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java new file mode 100644 index 0000000..f5852ac --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java @@ -0,0 +1,78 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "sections") +public class Sections { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_section; + + @Column(length=255) + private String titre; + + private String contenu_section; + + private LocalDateTime date_modification; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "Projets.id_projets") + private Projets projets; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "Administrateurs.id_admnistrateur") + private Administrateurs administrateurs; + + @ManyToMany(mappedBy = "sections") + private List rendezVous = new ArrayList<>(); + + public Sections() { + } + + public Sections(Long id_section, String titre, String contenu_section, LocalDateTime date_modification) { + this.id_section = id_section; + this.titre = titre; + this.contenu_section = contenu_section; + this.date_modification = date_modification; + } + + public String getTitre() { + return titre; + } + + public void setTitre(String titre) { + this.titre = titre; + } + + public Long getId_section() { + return id_section; + } + + public void setId_section(Long id_section) { + this.id_section = id_section; + } + + public String getContenu_section() { + return contenu_section; + } + + public void setContenu_section(String contenu_section) { + this.contenu_section = contenu_section; + } + + public LocalDateTime getDate_modification() { + return date_modification; + } + + public void setDate_modification(LocalDateTime date_modification) { + this.date_modification = date_modification; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java new file mode 100644 index 0000000..e20de6b --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java @@ -0,0 +1,90 @@ +package enseirb.myinpulse.postgres_db.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "utilisateurs") +@Inheritance(strategy = InheritanceType.JOINED) +public class Utilisateurs { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_utilisateur; + + @Column(length=255) + private String nom_utilisateur; + + @Column(length=255) + private String prenom_utilisateur; + + @Column(length=255) + private String mail_principal; + + @Column(length=255) + private String mail_secondaire; + + @Column(length=15) + private String numero_telephone; + + public Utilisateurs() { + } + + public Utilisateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + this.nom_utilisateur = nom_utilisateur; + this.id_utilisateur = id_utilisateur; + this.prenom_utilisateur = prenom_utilisateur; + this.mail_principal = mail_principal; + this.mail_secondaire = mail_secondaire; + this.numero_telephone = numero_telephone; + } + + public Long getId_utilisateur() { + return id_utilisateur; + } + + public void setId_utilisateur(Long id_utilisateur) { + this.id_utilisateur = id_utilisateur; + } + + public String getNom_utilisateur() { + return nom_utilisateur; + } + + public void setNom_utilisateur(String nom_utilisateur) { + this.nom_utilisateur = nom_utilisateur; + } + + public String getPrenom_utilisateur() { + return prenom_utilisateur; + } + + public void setPrenom_utilisateur(String prenom_utilisateur) { + this.prenom_utilisateur = prenom_utilisateur; + } + + public String getMail_principal() { + return mail_principal; + } + + public void setMail_principal(String mail_principal) { + this.mail_principal = mail_principal; + } + + public String getMail_secondaire() { + return mail_secondaire; + } + + public void setMail_secondaire(String mail_secondaire) { + this.mail_secondaire = mail_secondaire; + } + + public String getNumero_telephone() { + return numero_telephone; + } + + public void setNumero_telephone(String numero_telephone) { + this.numero_telephone = numero_telephone; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java new file mode 100644 index 0000000..b59d2c0 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java @@ -0,0 +1,13 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.Administrateurs; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface AdministrateursRepository extends JpaRepository { + + /* @Query("SELECT a from Administrateurs a") + Administrateurs findAllAdministrateurs(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java new file mode 100644 index 0000000..41a9c0e --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java @@ -0,0 +1,9 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.ComptesRendus; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface ComptesRendusRepository extends JpaRepository { +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java new file mode 100644 index 0000000..bb09b74 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java @@ -0,0 +1,13 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.Entrepreneurs; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface EntrepreneursRepository extends JpaRepository { + + /* @Query("SELECT e from Entrepreneurs e") + Entrepreneurs findAllEntrepreneurs(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java new file mode 100644 index 0000000..6665c89 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java @@ -0,0 +1,9 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.Projets; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface ProjetsRepository extends JpaRepository { +} \ No newline at end of file diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java new file mode 100644 index 0000000..be67f00 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java @@ -0,0 +1,9 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.RendezVous; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface RendezVousRepository extends JpaRepository { +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java new file mode 100644 index 0000000..70411d3 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java @@ -0,0 +1,9 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.Sections; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface SectionsRepository extends JpaRepository { +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java new file mode 100644 index 0000000..28aca29 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java @@ -0,0 +1,13 @@ +package enseirb.myinpulse.postgres_db.repository; + +import enseirb.myinpulse.postgres_db.model.Utilisateurs; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface UtilisateursRepository extends JpaRepository { + + /* @Query("SELECT u from Utilisateurs u") + Utilisateurs findAllUtilisateurs(); */ + +} diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index 6d6825f..80f88b1 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -2,3 +2,10 @@ spring.application.name=myinpulse spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test logging.level.org.springframework.security=DEBUG +spring.datasource.url=jdbc:postgresql://localhost:5432/${MyINPulse_DB} +spring.datasource.username=${POSTGRES_USER} +spring.datasource.password=${POSTGRES_PASSWORD} +spring.jpa.hibernate.ddl-auto=update +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + +spring.data.rest.base-path=/my/base/path \ No newline at end of file diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql new file mode 100644 index 0000000..f1a2289 --- /dev/null +++ b/MyINPulse-back/src/main/resources/data.sql @@ -0,0 +1,63 @@ +INSERT INTO projets (nom_projet, logo, date_creation, status_projet) VALUES +('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_DATE('01-OCT-2023', 'DD-MON-YYYY'), 'En cours'), +('Air oxygéné', decode('150647a0984e8f228cd14b54', 'hex'), TO_DATE('04-APR-2024', 'DD-MON-YYYY'), 'En cours'), +('Débat concours', decode('022024abd5486e245c145dda65116f', 'hex'), TO_DATE('22-NOV-2023', 'DD-MON-YYYY'), 'Suspendu'), +('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), 'Lancement'); + + +INSERT INTO utilisateurs (nom, prenom, mail_principal, mail_secondaire, numero_telephone) VALUES +('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), +('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), +('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), +('Leguez', 'Theo', 'bof@mesmails.fr', 'bof2@mesmails.fr', '+33 6 78 14 25 29'), +('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'); + +INSERT INTO entrepreneurs (ecole, filiere, status_snee) VALUES +('ENSEIRB-MATMECA', 'INFO', TRUE), +('ENSC', 'Cognitique', TRUE), +('ENSEIRB-MATMECA', 'MATMECA', FALSE), +('SupOptique', 'Classique', TRUE), +('ENSEGID', 'Géoscience', FALSE), +('ENSMAC', 'Matériaux composites - Mécanique', FALSE); + +INSERT INTO sections (titre, contenu_section, date_modification) VALUES +("Problème", "les problèmes...", TO_DATE('15-JAN-2025', 'DD-MON-YYYY')), +("Segment de client", "Le segment AB passant le client n°8 est de longueur 32mm. + Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?", TO_DATE('12-OCT-2022', 'DD-MON-YYYY')), +("Proposition de valeur unique", "'Son prix est de 2594€' 'Ah oui c'est unique en effet'", TO_DATE('25-MAY-2024', 'DD-MON-YYYY')), +("Solution", "Un problème ? Une solution", TO_DATE('08-FEB-2024', 'DD-MON-YYYY')), +("Canaux", "Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez", TO_DATE('19-JUL-2023', 'DD-MON-YYYY')), +("Sources de revenus", "Y'en n'a pas on est pas payé. Enfin y'a du café quoi", TO_DATE('12-JAN-2025', 'DD-MON-YYYY')), +("Structure des coûts", "'Ah oui là ça va faire au moins 1000€ par mois', Eirbware", TO_DATE('06-FEB-2025', 'DD-MON-YYYY')), +("Indicateurs clés", "On apprend les clés comme des badges, ça se fait", TO_DATE('05-FEB-2025', 'DD-MON-YYYY')), +("Avantages concurrentiel", "On est meilleur", TO_DATE('23-APR-2024', 'DD-MON-YYYY')); + +INSERT INTO rendez_vous (date_rdv, heure_rdv, duree_rdv, lieu_rdv, sujet_rdv) VALUES +(TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', "À la maison", "Ouvrir les cadeaux"), +(TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', "Sur les quais ou dans un champ probablement", "BOUM BOUM les feux d'artifices (on fête quoi déjà ?)"), +(TO_DATE('29-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', "Salle TD 15", "Ah mince c'est pas une année bissextile !"), +(TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', "Là où le vent nous porte", "Journée la plus importante de l'année"), +(TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', "Euh c'est par où l'amphi 56 ?", "Rentrée scolaire (il fait trop froid c'est quoi ça on est en août)"); + + +INSERT INTO comptes_rendus (contenu_compte_rendu) VALUES +("Ah oui ça c'est super, ah ouais j'aime bien, bien vu de penser à ça"), +("Bonne réunion"), +("Ouais, j'ai rien compris mais niquel on fait comme vous avez dit"), +("Non non ça va pas du tout ce que tu me proposes, faut tout refaire"), +("Réponse de la DSI : non"), +("Trop dommage qu'Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence"); + + + + + + + + + + + + + + diff --git a/MyINPulse-back/src/main/resources/schema.sql b/MyINPulse-back/src/main/resources/schema.sql new file mode 100644 index 0000000..4bd1034 --- /dev/null +++ b/MyINPulse-back/src/main/resources/schema.sql @@ -0,0 +1,122 @@ +DROP TABLE IF EXISTS projets CASCADE; +DROP TABLE IF EXISTS utilisateurs CASCADE; +DROP TABLE IF EXISTS entrepreneurs CASCADE; +DROP TABLE IF EXISTS administrateurs CASCADE; +DROP TABLE IF EXISTS sections CASCADE; +DROP TABLE IF EXISTS rendez_vous CASCADE; +DROP TABLE IF EXISTS comptes_rendus CASCADE; +DROP TABLE IF EXISTS concerner CASCADE; +DROP TABLE IF EXISTS formes CASCADE; + +CREATE TABLE projets +( +id_projet SERIAL NOT NULL, +nom_projet VARCHAR(255) , +logo BYTEA , +date_creation DATE , +status_projet VARCHAR(255) , +CONSTRAINT pk_projet PRIMARY KEY (id_projet) ); + + +CREATE TABLE utilisateurs +( +id_utilisateur SERIAL NOT NULL, +nom_utilisateur VARCHAR(255) , +prenom_utilisateur VARCHAR(255) , +mail_principal VARCHAR(255) , +mail_secondaire VARCHAR(255) , +numero_telephone VARCHAR(15) , +CONSTRAINT pk_utilisateur PRIMARY KEY (id_utilisateur) ); + +CREATE TABLE entrepreneurs +( +id_entrepreneur SERIAL REFERENCES utilisateurs (id_utilisateur), +ecole VARCHAR(255) , +filiere VARCHAR(255) , +status_snee BOOLEAN , +CONSTRAINT pk_entrepreneur PRIMARY KEY (id_entrepreneur) ); + +CREATE TABLE administrateurs +( +id_administrateur SERIAL REFERENCES utilisateurs (id_utilisateur), +CONSTRAINT pk_administrateur PRIMARY KEY (id_administrateur) ); + +CREATE TABLE sections +( +id_section SERIAL NOT NULL, +titre VARCHAR(255) , +contenu_section TEXT , +date_modification TIMESTAMP , +CONSTRAINT pk_section PRIMARY KEY (id_section) ); + +CREATE TABLE rendez_vous +( +id_rdv SERIAL NOT NULL, +date_rdv DATE , +heure_rdv TIME , +duree_rdv TIME , +lieu_rdv VARCHAR(255) , +sujet_rdv TEXT , +CONSTRAINT pk_rdv PRIMARY KEY (id_rdv) ); + +CREATE TABLE comptes_rendus +( +id_compte_rendu SERIAL NOT NULL, +contenu_compte_rendu TEXT , +CONSTRAINT pk_compte_rendu PRIMARY KEY (id_compte_rendu) ); + +CREATE TABLE concerner +( +id_section SERIAL REFERENCES sections (id_section), +id_rdv SERIAL REFERENCES sections (id_rdv), +CONSTRAINT pk_concerner PRIMARY KEY (id_section, id_rdv) ); + + +ALTER TABLE projets + ADD CONSTRAINT fk1_projet FOREIGN KEY (id_administrateur) + REFERENCES administrateurs (id_administrateur) + ON DELETE CASCADE; + +ALTER TABLE projets + ADD CONSTRAINT fk2_projet FOREIGN KEY (id_entrepreneur_participation) + REFERENCES entrepreneurs (id_entrepreneur) + ON DELETE CASCADE; + +ALTER TABLE entrepreneurs + ADD CONSTRAINT fk1_entrepreneur FOREIGN KEY (id_projet_propose) + REFERENCES projets (id_projet) + ON DELETE CASCADE; + +ALTER TABLE sections + ADD CONSTRAINT fk1_section FOREIGN KEY (id_projet) + REFERENCES projets (id_projet) + ON DELETE CASCADE; + +ALTER TABLE sections + ADD CONSTRAINT fk2_section FOREIGN KEY (id_administrateur) + REFERENCES administrateurs (id_administrateur) + ON DELETE CASCADE; + +ALTER TABLE rendez-vous + ADD CONSTRAINT fk1_rdv FOREIGN KEY (id_entrepreneur) + REFERENCES entrepreneurs (id_entrepreneur) + ON DELETE CASCADE; + +ALTER TABLE rendez-vous + ADD CONSTRAINT fk2_rdv FOREIGN KEY (id_administrateur) + REFERENCES administrateurs (id_administrateur) + ON DELETE CASCADE; + +ALTER TABLE comptes-rendus + ADD CONSTRAINT fk1_compte_rendu FOREIGN KEY (id_rdv) + REFERENCES rendez_vous (id_rdv) + ON DELETE CASCADE; + + + + + + + + + diff --git a/config/backdev.docker-compose.yaml b/config/backdev.docker-compose.yaml index a73a010..607fa49 100644 --- a/config/backdev.docker-compose.yaml +++ b/config/backdev.docker-compose.yaml @@ -2,8 +2,8 @@ services: postgres: image: postgres:latest container_name: MyINPulse-DB - #ports: - # - 5432:5432 + ports: + - 5432:5432 volumes: - ./postgres:/var/lib/postgresql/data environment: diff --git a/config/backdev.main.env b/config/backdev.main.env index 6f32124..6ddb261 100644 --- a/config/backdev.main.env +++ b/config/backdev.main.env @@ -3,4 +3,8 @@ POSTGRES_USER=keycloak_db_user POSTGRES_PASSWORD=keycloak_db_user_password KEYCLOAK_ADMIN=admin KEYCLOAK_ADMIN_PASSWORD=admin -KEYCLOAK_HOSTNAME=localhost \ No newline at end of file +KEYCLOAK_HOSTNAME=localhost + +MYINPULSE_DB=MyINPulse_db +MYINPULSE_DB_USER=MyINPulse_db_user +MYINPULSE_DB_PASS=MyINPulse_db_user_pass \ No newline at end of file diff --git a/front/MyINPulse-front/src/components/temp-modal.vue b/front/MyINPulse-front/src/components/temp-modal.vue new file mode 100644 index 0000000..a8dd50e --- /dev/null +++ b/front/MyINPulse-front/src/components/temp-modal.vue @@ -0,0 +1,18 @@ + + + + + -- 2.47.2 From 249d00177ce044306b461cefe17dadbeffa559f8 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 10:00:11 +0100 Subject: [PATCH 02/97] feat: interraction between the backend and keycloak --- .../enseirb/myinpulse/api/GetUserInfo.java | 11 +-- .../exceptions/RoleNotFoudException.java | 7 ++ .../exceptions/UserNotFoundException.java | 7 ++ .../security/KeycloakJwtRolesConverter.java | 11 ++- .../enseirb/myinpulse/utils/KeycloakApi.java | 77 +++++++++++++++++++ front/MyINPulse-front/src/services/api.ts | 3 +- front/MyINPulse-front/src/views/test.vue | 73 ++++++++++++++++++ 7 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java create mode 100644 front/MyINPulse-front/src/views/test.vue diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java index 50262e1..3b4f04a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java @@ -2,13 +2,13 @@ package enseirb.myinpulse.api; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.*; +import javax.management.relation.RoleNotFoundException; import java.security.Principal; + + @SpringBootApplication @RestController public class GetUserInfo { @@ -22,7 +22,8 @@ public class GetUserInfo { @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random") - public boolean rand(){ + public boolean rand(@RequestHeader("Authorization") String token) throws RoleNotFoundException { + System.err.println(token); System.err.println("HELLO"); return Math.random() > 0.5; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java new file mode 100644 index 0000000..22e4c23 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.exceptions; + +public class RoleNotFoudException extends RuntimeException { + public RoleNotFoudException(String message) { + super(message); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java new file mode 100644 index 0000000..983e766 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.exceptions; + +public class UserNotFoundException extends RuntimeException { + public UserNotFoundException(String message) { + super(message); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java index fafbef5..08c5cab 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java @@ -1,3 +1,7 @@ +/* + * Source: https://github.com/ChristianHuff-DEV/secure-spring-rest-api-using-keycloak/blob/main/src/main/java/io/betweendata/RestApi/security/oauth2/KeycloakJwtRolesConverter.java + * edited by Pierre Tellier + */ package enseirb.myinpulse.security; import org.springframework.core.convert.converter.Converter; @@ -41,17 +45,16 @@ public class KeycloakJwtRolesConverter implements Converter TEMPORARNAME(Jwt jwt) { + public Collection tokenRolesExtractor(Jwt jwt) { // Collection that will hold the extracted roles Collection grantedAuthorities = new ArrayList<>(); diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java new file mode 100644 index 0000000..e91e9e1 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java @@ -0,0 +1,77 @@ +package enseirb.myinpulse.utils; + +import enseirb.myinpulse.exceptions.UserNotFoundException; +import org.springframework.web.client.RestClient; + +import javax.management.relation.RoleNotFoundException; + +import static org.springframework.http.MediaType.APPLICATION_JSON; + +public class KeycloakApi { + + static final String keycloakUrl = "http://localhost:7080"; + static final String realmName = "test"; + + /** + * Uses Keycloak API to retrieve a role representation of a role by its name + * @param roleName name of the role + * @param bearer authorization header used by the client to authenticate to keycloak + */ + static public RoleRepresentation getRoleRepresentationByName(String roleName, String bearer) throws RoleNotFoundException { + RoleRepresentation[] response = RestClient.builder().baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .get() + .uri("/admin/realms/{realmName}/roles/{roleName}", realmName, roleName) + .retrieve() + .body(RoleRepresentation[].class); + + if (response == null || response.length == 0) { + throw new RoleNotFoundException("Role not found"); + } + return response[0]; + } + + static public String getUserIdByName(String username, String bearer) throws UserNotFoundException { + UserRepresentation[] response = RestClient.builder().baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .get() + .uri("/admin/realms/{realmName}/users?username={username}", realmName, username) + .retrieve() + .body(UserRepresentation[].class); + + if (response == null || response.length == 0) { + throw new UserNotFoundException("User not found"); + } + return response[0].id; + } + + static public void setRoleToUser(String username, String roleName, String bearer) throws RoleNotFoundException, UserNotFoundException { + RoleRepresentation roleRepresentation = getRoleRepresentationByName(roleName, bearer); + String userId = getUserIdByName(username, bearer); + + + RestClient.builder().baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .post() + .uri("/admin/realms/${realmName}/users/${userId}/role-mappings/realm", realmName, userId) + .body(roleRepresentation) + .contentType(APPLICATION_JSON) + .retrieve(); + } +} + + +class RoleRepresentation { + public String id; + public String name; + public String description; +} + +class UserRepresentation { + public String id; + public String name; +} + diff --git a/front/MyINPulse-front/src/services/api.ts b/front/MyINPulse-front/src/services/api.ts index 091455c..5c4fc7b 100644 --- a/front/MyINPulse-front/src/services/api.ts +++ b/front/MyINPulse-front/src/services/api.ts @@ -14,7 +14,8 @@ axiosInstance.interceptors.response.use( async (error) => { const originalRequest = error.config; if ( - error.response.status === 401 && + ((error.response && error.response.status === 401) || + error.code == "ERR_NETWORK") && !originalRequest._retry && store.authenticated ) { diff --git a/front/MyINPulse-front/src/views/test.vue b/front/MyINPulse-front/src/views/test.vue new file mode 100644 index 0000000..9d98958 --- /dev/null +++ b/front/MyINPulse-front/src/views/test.vue @@ -0,0 +1,73 @@ + + + + + -- 2.47.2 From d2cc3e00e103c37983a91ebbc0c70875429e0efe Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 10:07:00 +0100 Subject: [PATCH 03/97] fix: Makefile now build correctly production environment --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6944ef4..26d5ccb 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ dev-front: clean vite prod: clean @cp config/prod.front.env front/MyINPulse-front/.env @cp config/prod.main.env .env - @cp config/frontdev.docker-compose.yaml docker-compose.yaml + @cp config/prod.docker-compose.yaml docker-compose.yaml @docker compose up -d --build -- 2.47.2 From eed4e6f85586c4e2f1712f8714cb26ce04241897 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 11:07:45 +0100 Subject: [PATCH 04/97] feat: multiple database and user in postgres --- .gitignore | 1 + config/backdev.docker-compose.yaml | 13 ++++++------- config/backdev.main.env | 16 ++++++++++------ config/frontdev.docker-compose.yaml | 12 ++++++------ config/frontdev.main.env | 16 ++++++++++++---- config/prod.docker-compose.yaml | 7 +++++-- config/prod.main.env | 16 ++++++++++++---- postgres/Dockerfile | 5 +++++ postgres/create_db.sh | 17 +++++++++++++++++ postgres/create_user.sh | 16 ++++++++++++++++ 10 files changed, 90 insertions(+), 29 deletions(-) create mode 100644 postgres/Dockerfile create mode 100644 postgres/create_db.sh create mode 100644 postgres/create_user.sh diff --git a/.gitignore b/.gitignore index 170ba0d..7117a86 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea keycloak/CAS/target docker-compose.yaml +postgres/data \ No newline at end of file diff --git a/config/backdev.docker-compose.yaml b/config/backdev.docker-compose.yaml index 607fa49..25151a0 100644 --- a/config/backdev.docker-compose.yaml +++ b/config/backdev.docker-compose.yaml @@ -1,15 +1,14 @@ services: postgres: - image: postgres:latest + env_file: .env + build: + context: postgres/ + dockerfile: Dockerfile container_name: MyINPulse-DB ports: - - 5432:5432 + - 5433:5432 volumes: - - ./postgres:/var/lib/postgresql/data - environment: - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + - ./postgres/data:/var/lib/postgresql/data keycloak: container_name: MyINPulse-keycloak diff --git a/config/backdev.main.env b/config/backdev.main.env index 6ddb261..2a597c3 100644 --- a/config/backdev.main.env +++ b/config/backdev.main.env @@ -1,10 +1,14 @@ -POSTGRES_DB=keycloak_db -POSTGRES_USER=keycloak_db_user -POSTGRES_PASSWORD=keycloak_db_user_password +POSTGRES_DB=postgres_db +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres_db_user_password + KEYCLOAK_ADMIN=admin KEYCLOAK_ADMIN_PASSWORD=admin KEYCLOAK_HOSTNAME=localhost +KEYCLOAK_DB=keycloak_db +KEYCLOAK_USER=keycloak_db_user +KEYCLOAK_PASSWORD=keycloak_db_user_password -MYINPULSE_DB=MyINPulse_db -MYINPULSE_DB_USER=MyINPulse_db_user -MYINPULSE_DB_PASS=MyINPulse_db_user_pass \ No newline at end of file +BACKEND_DB=backend_db +BACKEND_USER=backend_db_user +BACKEND_PASSWORD=backend_db_user_password \ No newline at end of file diff --git a/config/frontdev.docker-compose.yaml b/config/frontdev.docker-compose.yaml index aa6d0d0..529ac2c 100644 --- a/config/frontdev.docker-compose.yaml +++ b/config/frontdev.docker-compose.yaml @@ -1,15 +1,15 @@ services: postgres: - image: postgres:latest + env_file: .env + build: + context: postgres/ + dockerfile: Dockerfile container_name: MyINPulse-DB #ports: # - 5432:5432 volumes: - - ./postgres:/var/lib/postgresql/data - environment: - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + - ./postgres/data:/var/lib/postgresql/data + keycloak: container_name: MyINPulse-keycloak diff --git a/config/frontdev.main.env b/config/frontdev.main.env index 6f32124..26c2803 100644 --- a/config/frontdev.main.env +++ b/config/frontdev.main.env @@ -1,6 +1,14 @@ -POSTGRES_DB=keycloak_db -POSTGRES_USER=keycloak_db_user -POSTGRES_PASSWORD=keycloak_db_user_password +POSTGRES_DB=postgres_db +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres_db_user_password + KEYCLOAK_ADMIN=admin KEYCLOAK_ADMIN_PASSWORD=admin -KEYCLOAK_HOSTNAME=localhost \ No newline at end of file +KEYCLOAK_HOSTNAME=localhost +KEYCLOAK_DB=keycloak_db +KEYCLOAK_USER=keycloak_db_user +KEYCLOAK_PASSWORD=keycloak_db_user_password + +BACKEND_DB=backend_db +BACKEND_USER=backend_db_user +BACKEND_PASSWORD=backend_db_user_password diff --git a/config/prod.docker-compose.yaml b/config/prod.docker-compose.yaml index fe2a3d7..51f2d76 100644 --- a/config/prod.docker-compose.yaml +++ b/config/prod.docker-compose.yaml @@ -1,11 +1,14 @@ services: postgres: - image: postgres:latest + env_file: .env + build: + context: postgres/ + dockerfile: Dockerfile container_name: MyINPulse-DB #ports: # - 5432:5432 volumes: - - ./postgres:/var/lib/postgresql/data + - ./postgres/data:/var/lib/postgresql/data environment: POSTGRES_DB: ${POSTGRES_DB} POSTGRES_USER: ${POSTGRES_USER} diff --git a/config/prod.main.env b/config/prod.main.env index e8db94b..179d92c 100644 --- a/config/prod.main.env +++ b/config/prod.main.env @@ -1,6 +1,14 @@ -POSTGRES_DB=keycloak_db -POSTGRES_USER=keycloak_db_user -POSTGRES_PASSWORD=keycloak_db_user_password +POSTGRES_DB=postgres_db +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres_db_user_password + KEYCLOAK_ADMIN=admin KEYCLOAK_ADMIN_PASSWORD=admin -KEYCLOAK_HOSTNAME=0549cd63f912d5dc9b31278d6f.eirb.fr \ No newline at end of file +KEYCLOAK_HOSTNAME=0549cd63f912d5dc9b31278d6f.eirb.fr +KEYCLOAK_DB=keycloak_db +KEYCLOAK_USER=keycloak_db_user +KEYCLOAK_PASSWORD=keycloak_db_user_password + +BACKEND_DB=backend_db +BACKEND_USER=backend_db_user +BACKEND_PASSWORD=backend_db_user_password diff --git a/postgres/Dockerfile b/postgres/Dockerfile new file mode 100644 index 0000000..da99686 --- /dev/null +++ b/postgres/Dockerfile @@ -0,0 +1,5 @@ +FROM postgres:latest + +# Custom initialization scripts +COPY ./create_user.sh /docker-entrypoint-initdb.d/10-create_user.sh +COPY ./create_db.sh /docker-entrypoint-initdb.d/20-create_db.sh diff --git a/postgres/create_db.sh b/postgres/create_db.sh new file mode 100644 index 0000000..c1728a0 --- /dev/null +++ b/postgres/create_db.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +POSTGRES="psql --username ${POSTGRES_USER}" + +echo "Creating database: ${DB_NAME}" + +$POSTGRES < Date: Tue, 11 Feb 2025 19:04:02 +0100 Subject: [PATCH 05/97] test: check backend formatting --- .gitea/workflows/back.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .gitea/workflows/back.yaml diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml new file mode 100644 index 0000000..0af4bc6 --- /dev/null +++ b/.gitea/workflows/back.yaml @@ -0,0 +1,13 @@ +name: check backend + +on: [ push, pull_request ] + +jobs: + + formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 # v2 minimum required + - uses: axel-op/googlejavaformat-action@v3 + with: + args: "--set-exit-if-changed --aosp" \ No newline at end of file -- 2.47.2 From c7ddc37bf995e9e01e2644b57e51896f9e1c5d4e Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 19:12:49 +0100 Subject: [PATCH 06/97] test: changed the verification --- .gitea/workflows/back.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 0af4bc6..f68f425 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -1,4 +1,4 @@ -name: check backend +name: Format on: [ push, pull_request ] @@ -10,4 +10,7 @@ jobs: - uses: actions/checkout@v4 # v2 minimum required - uses: axel-op/googlejavaformat-action@v3 with: - args: "--set-exit-if-changed --aosp" \ No newline at end of file + args: "--replace" + skip-commit: true + - name: Print diffs + run: git --no-pager diff --exit-code \ No newline at end of file -- 2.47.2 From 0fc4be2008b208d2dab7b1824698582c1f3e7de2 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 19:18:08 +0100 Subject: [PATCH 07/97] test: changed the verification --- .gitea/workflows/back.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index f68f425..91ffdd3 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -8,6 +8,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 # v2 minimum required + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' - uses: axel-op/googlejavaformat-action@v3 with: args: "--replace" -- 2.47.2 From c7159557584eef7b4fe75593aab97f01da0799a3 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 19:20:49 +0100 Subject: [PATCH 08/97] feat: the backend validator is better --- .gitea/workflows/back.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 91ffdd3..0e74e38 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -14,7 +14,6 @@ jobs: java-version: '21' - uses: axel-op/googlejavaformat-action@v3 with: - args: "--replace" - skip-commit: true + args: "--replace --skip-sorting-imports --aosp" - name: Print diffs run: git --no-pager diff --exit-code \ No newline at end of file -- 2.47.2 From 45bbe51897ca81fcb27af13e8de7c559bc1c6ab9 Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Tue, 11 Feb 2025 18:21:00 +0000 Subject: [PATCH 09/97] Google Java Format --- .../myinpulse/MyinpulseApplication.java | 19 +---- .../enseirb/myinpulse/api/GetUserInfo.java | 6 +- .../WebSecurityCustomConfiguration.java | 41 ++++++---- .../controller/AdministrateursController.java | 10 +-- .../controller/ComptesRendusController.java | 3 +- .../controller/EntrepreneursController.java | 18 ++--- .../controller/ProjetsController.java | 16 ++-- .../controller/RendezVousController.java | 14 ++-- .../controller/SectionsController.java | 13 +-- .../controller/UtilisateursController.java | 15 ++-- .../postgres_db/model/Administrateurs.java | 21 +++-- .../postgres_db/model/ComptesRendus.java | 4 +- .../postgres_db/model/Entrepreneurs.java | 27 +++++-- .../myinpulse/postgres_db/model/Projets.java | 17 ++-- .../postgres_db/model/RendezVous.java | 18 +++-- .../myinpulse/postgres_db/model/Sections.java | 11 ++- .../postgres_db/model/Utilisateurs.java | 21 +++-- .../repository/ComptesRendusRepository.java | 3 +- .../repository/ProjetsRepository.java | 3 +- .../repository/RendezVousRepository.java | 3 +- .../repository/SectionsRepository.java | 3 +- .../security/KeycloakJwtRolesConverter.java | 79 ++++++++++--------- .../myinpulse/MyinpulseApplicationTests.java | 6 +- 23 files changed, 205 insertions(+), 166 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java index 23c2f28..1c39eef 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java @@ -1,29 +1,16 @@ package enseirb.myinpulse; -import enseirb.myinpulse.security.KeycloakJwtRolesConverter; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.core.convert.converter.Converter; -import org.springframework.security.authentication.AbstractAuthenticationToken; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.jwt.*; -import org.springframework.security.web.SecurityFilterChain; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.CorsConfigurationSource; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import java.util.*; -import java.util.stream.Collectors; -import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; @SpringBootApplication public class MyinpulseApplication { - public static void main(String[] args) { - SpringApplication.run(MyinpulseApplication.class, args); - } - - + public static void main(String[] args) { + SpringApplication.run(MyinpulseApplication.class, args); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java index 50262e1..63aef48 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java @@ -22,21 +22,21 @@ public class GetUserInfo { @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random") - public boolean rand(){ + public boolean rand() { System.err.println("HELLO"); return Math.random() > 0.5; } @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random2") - public boolean rand2(){ + public boolean rand2() { System.err.println("HELLO2"); return Math.random() > 0.5; } @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @GetMapping("/random3") - public boolean rand3(){ + public boolean rand3() { System.err.println("HELLO"); return Math.random() > 0.5; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index 14c46b3..e642fd8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -23,10 +23,13 @@ public class WebSecurityCustomConfiguration { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(List.of("*")); configuration.setAllowedMethods(Arrays.asList("GET", "OPTIONS")); - configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", - "x-auth-token")); // Do not remove, this fixes the CORS errors when unauthenticated - UrlBasedCorsConfigurationSource source = new - UrlBasedCorsConfigurationSource(); + configuration.setAllowedHeaders( + Arrays.asList( + "authorization", + "content-type", + "x-auth-token")); // Do not remove, this fixes the CORS errors when + // unauthenticated + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; @@ -34,17 +37,23 @@ public class WebSecurityCustomConfiguration { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http - .authorizeHttpRequests(authorize -> authorize - .requestMatchers("/random2").access(hasRole("REALM_MyINPulse-entrepreneur")) - .requestMatchers("/random").access(hasRole("REALM_MyINPulse-admin")) - .requestMatchers("/random3").permitAll() - .anyRequest().authenticated() - ) - .oauth2ResourceServer(oauth2 -> oauth2 - .jwt(jwt -> jwt. - jwtAuthenticationConverter(new KeycloakJwtRolesConverter()))); + http.authorizeHttpRequests( + authorize -> + authorize + .requestMatchers("/random2") + .access(hasRole("REALM_MyINPulse-entrepreneur")) + .requestMatchers("/random") + .access(hasRole("REALM_MyINPulse-admin")) + .requestMatchers("/random3") + .permitAll() + .anyRequest() + .authenticated()) + .oauth2ResourceServer( + oauth2 -> + oauth2.jwt( + jwt -> + jwt.jwtAuthenticationConverter( + new KeycloakJwtRolesConverter()))); return http.build(); - } -} \ No newline at end of file +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java index 5f1a718..f27240e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java @@ -12,8 +12,7 @@ import java.util.Optional; @RestController public class AdministrateursController { - @Autowired - AdministrateursRepository administrateursRepository; + @Autowired AdministrateursRepository administrateursRepository; @GetMapping("/Administrateurs") @ResponseBody @@ -22,11 +21,11 @@ public class AdministrateursController { } @GetMapping("/Administrateurs/{id}") - public Administrateurs getAdministrateursById(@PathVariable Long id) - { + public Administrateurs getAdministrateursById(@PathVariable Long id) { Optional administrateur = this.administrateursRepository.findById(id); if (administrateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); } return administrateur.get(); } @@ -35,5 +34,4 @@ public class AdministrateursController { public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { return this.administrateursRepository.save(administrateurs); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index 9bcc862..c6cccdb 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -12,8 +12,7 @@ import java.util.Optional; @RestController public class ComptesRendusController { - @Autowired - ComptesRendusRepository comptesRendusRepository; + @Autowired ComptesRendusRepository comptesRendusRepository; @GetMapping("/ComptesRendus") @ResponseBody diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java index 2bbc653..e07c359 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -3,19 +3,16 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.web.bind.annotation.*; import enseirb.myinpulse.postgres_db.model.Entrepreneurs; import org.springframework.web.server.ResponseStatusException; import java.util.Optional; - @RestController public class EntrepreneursController { - @Autowired - EntrepreneursRepository entrepreneursRepository; + @Autowired EntrepreneursRepository entrepreneursRepository; @GetMapping("/Entrepreneurs") @ResponseBody @@ -24,11 +21,11 @@ public class EntrepreneursController { } @GetMapping("/Entrepreneurs/{id}") - public Entrepreneurs getEntrepreneursById(@PathVariable Long id) - { + public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { Optional entrepreneur = entrepreneursRepository.findById(id); if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } return entrepreneur.get(); } @@ -39,10 +36,12 @@ public class EntrepreneursController { } @PostMapping("/Entrepreneurs/{id}") - public Entrepreneurs updateEntrepreneurs(@PathVariable Long id, String ecole, String filiere, Boolean status_snee) { + public Entrepreneurs updateEntrepreneurs( + @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { Optional entrepreneur = entrepreneursRepository.findById(id); if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } if (ecole != null) { entrepreneur.get().setEcole(ecole); @@ -55,5 +54,4 @@ public class EntrepreneursController { } return entrepreneur.get(); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java index 92b5908..2f11474 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -13,8 +13,7 @@ import java.util.Optional; @RestController public class ProjetsController { - @Autowired - ProjetsRepository projetsRepository; + @Autowired ProjetsRepository projetsRepository; @GetMapping("/Projets") @ResponseBody @@ -23,8 +22,7 @@ public class ProjetsController { } @GetMapping("/Projets/{id}") - public Projets getProjetsById(@PathVariable Long id) - { + public Projets getProjetsById(@PathVariable Long id) { Optional projet = this.projetsRepository.findById(id); if (projet.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); @@ -38,7 +36,12 @@ public class ProjetsController { } @PostMapping("/Projets/{id}") - public Projets updateProjets(@PathVariable Long id, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { + public Projets updateProjets( + @PathVariable Long id, + String nom_projet, + Byte[] logo, + LocalDate date_creation, + String status_projet) { Optional projet = this.projetsRepository.findById(id); if (projet.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); @@ -57,5 +60,4 @@ public class ProjetsController { } return projet.get(); } - -} \ No newline at end of file +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java index aa9e3ba..0ec0b0c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -14,8 +14,7 @@ import java.util.Optional; @RestController public class RendezVousController { - @Autowired - RendezVousRepository rendezVousRepository; + @Autowired RendezVousRepository rendezVousRepository; @GetMapping("/RendezVous") @ResponseBody @@ -24,8 +23,7 @@ public class RendezVousController { } @GetMapping("/RendezVous/{id}") - public RendezVous getRendezVousById(@PathVariable Long id) - { + public RendezVous getRendezVousById(@PathVariable Long id) { Optional rendezVous = this.rendezVousRepository.findById(id); if (rendezVous.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); @@ -39,7 +37,13 @@ public class RendezVousController { } @PostMapping("/RendezVous/{id}") - public RendezVous updateRendezVous(@PathVariable Long id, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { + public RendezVous updateRendezVous( + @PathVariable Long id, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { Optional rendezVous = this.rendezVousRepository.findById(id); if (rendezVous.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java index 49032fe..5f065a5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -13,8 +13,7 @@ import java.util.Optional; @RestController public class SectionsController { - @Autowired - SectionsRepository sectionsRepository; + @Autowired SectionsRepository sectionsRepository; @GetMapping("/Sections") @ResponseBody @@ -23,8 +22,7 @@ public class SectionsController { } @GetMapping("/Sections/{id}") - public Sections getSectionsById(@PathVariable Long id) - { + public Sections getSectionsById(@PathVariable Long id) { Optional section = this.sectionsRepository.findById(id); if (section.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); @@ -38,7 +36,11 @@ public class SectionsController { } @PostMapping("/Sections/{id}") - public Sections updateSections(@PathVariable Long id, String titre, String contenu_section, LocalDateTime date_modification) { + public Sections updateSections( + @PathVariable Long id, + String titre, + String contenu_section, + LocalDateTime date_modification) { Optional section = this.sectionsRepository.findById(id); if (section.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); @@ -54,5 +56,4 @@ public class SectionsController { } return section.get(); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java index 059e2f0..040b4d0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -12,8 +12,7 @@ import java.util.Optional; @RestController public class UtilisateursController { - @Autowired - UtilisateursRepository utilisateursRepository; + @Autowired UtilisateursRepository utilisateursRepository; @GetMapping("/Utilisateurs") @ResponseBody @@ -36,11 +35,18 @@ public class UtilisateursController { } @PostMapping("/Utilisateurs/{id}") - public Utilisateurs updateUtilisateurs(@PathVariable Long id, String nom_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + public Utilisateurs updateUtilisateurs( + @PathVariable Long id, + String nom_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { Optional utilisateur = utilisateursRepository.findById(id); if (utilisateur.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - }if (nom_utilisateur != null) { + } + if (nom_utilisateur != null) { utilisateur.get().setNom_utilisateur(nom_utilisateur); } if (prenom_utilisateur != null) { @@ -57,5 +63,4 @@ public class UtilisateursController { } return utilisateur.get(); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java index 0255adf..5620b9a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -10,7 +10,6 @@ import java.util.List; @Entity @Table(name = "administrateurs") @PrimaryKeyJoinColumn(name = "id_administrateur") - public class Administrateurs extends Utilisateurs { @ManyToOne(fetch = FetchType.LAZY) @@ -24,11 +23,21 @@ public class Administrateurs extends Utilisateurs { @JoinColumn(name = "RendezVous.id_rdv") private RendezVous rendezVous; - public Administrateurs() { - } + public Administrateurs() {} - public Administrateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { - super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); + public Administrateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java index cd7f283..a629e3b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java @@ -21,9 +21,7 @@ public class ComptesRendus { @JoinColumn(name = "RendezVous.id_rdv") private RendezVous rendezVous; - - public ComptesRendus() { - } + public ComptesRendus() {} public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { this.id_compte_rendu = id_compte_rendu; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java index b8f6964..4f73d19 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java @@ -9,10 +9,10 @@ import jakarta.persistence.Table; @PrimaryKeyJoinColumn(name = "id_entrepreneur") public class Entrepreneurs extends Utilisateurs { - @Column(length=255) + @Column(length = 255) private String ecole; - @Column(length=255) + @Column(length = 255) private String filiere; private boolean status_snee; @@ -29,12 +29,25 @@ public class Entrepreneurs extends Utilisateurs { @JoinColumn(name = "RendezVous.id_rdv") private RendezVous rendezVous; + public Entrepreneurs() {} - public Entrepreneurs() { - } - - public Entrepreneurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone, String ecole, boolean status_snee, String filiere) { - super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); + public Entrepreneurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone, + String ecole, + boolean status_snee, + String filiere) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); this.ecole = ecole; this.status_snee = status_snee; this.filiere = filiere; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java index 6fd8d98..63d3bc3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java @@ -16,14 +16,14 @@ public class Projets { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_projet; - @Column(length=255) + @Column(length = 255) private String nom_projet; private Byte[] logo; private LocalDate date_creation; - @Column(length=255) + @Column(length = 255) private String status_projet; @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) @@ -41,10 +41,14 @@ public class Projets { // Hibernate expects entities to have a no-arg constructor, // though it does not necessarily have to be public. - public Projets() { - } + public Projets() {} - public Projets(Long id_projet, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { + public Projets( + Long id_projet, + String nom_projet, + Byte[] logo, + LocalDate date_creation, + String status_projet) { this.id_projet = id_projet; this.nom_projet = nom_projet; this.logo = logo; @@ -91,5 +95,4 @@ public class Projets { public void setStatus_projet(String status_projet) { this.status_projet = status_projet; } - -} \ No newline at end of file +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index 78fbfc2..55732c1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -23,7 +23,7 @@ public class RendezVous { private LocalDateTime duree_rdv; - @Column(length=255) + @Column(length = 255) private String lieu_rdv; private String sujet_rdv; @@ -37,17 +37,24 @@ public class RendezVous { @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) private List ListComptesRendus = new ArrayList<>(); - @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }) + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.ALL}) @JoinTable( name = "concerner", joinColumns = @JoinColumn(name = "id_rdv"), inverseJoinColumns = @JoinColumn(name = "id_sections")) List ListSections = new ArrayList<>(); - public RendezVous() { - } + public RendezVous() {} - public RendezVous(Long id_rdv, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { + public RendezVous( + Long id_rdv, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { this.id_rdv = id_rdv; this.date_rdv = date_rdv; this.heure_rdv = heure_rdv; @@ -103,5 +110,4 @@ public class RendezVous { public void setSujet_rdv(String sujet_rdv) { this.sujet_rdv = sujet_rdv; } - } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java index f5852ac..0c9d013 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java @@ -16,7 +16,7 @@ public class Sections { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_section; - @Column(length=255) + @Column(length = 255) private String titre; private String contenu_section; @@ -34,10 +34,13 @@ public class Sections { @ManyToMany(mappedBy = "sections") private List rendezVous = new ArrayList<>(); - public Sections() { - } + public Sections() {} - public Sections(Long id_section, String titre, String contenu_section, LocalDateTime date_modification) { + public Sections( + Long id_section, + String titre, + String contenu_section, + LocalDateTime date_modification) { this.id_section = id_section; this.titre = titre; this.contenu_section = contenu_section; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java index e20de6b..9d81163 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java @@ -13,25 +13,30 @@ public class Utilisateurs { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_utilisateur; - @Column(length=255) + @Column(length = 255) private String nom_utilisateur; - @Column(length=255) + @Column(length = 255) private String prenom_utilisateur; - @Column(length=255) + @Column(length = 255) private String mail_principal; - @Column(length=255) + @Column(length = 255) private String mail_secondaire; - @Column(length=15) + @Column(length = 15) private String numero_telephone; - public Utilisateurs() { - } + public Utilisateurs() {} - public Utilisateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { + public Utilisateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { this.nom_utilisateur = nom_utilisateur; this.id_utilisateur = id_utilisateur; this.prenom_utilisateur = prenom_utilisateur; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java index 41a9c0e..e4de376 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ComptesRendusRepository extends JpaRepository { -} +public interface ComptesRendusRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java index 6665c89..37f5d8e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ProjetsRepository extends JpaRepository { -} \ No newline at end of file +public interface ProjetsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java index be67f00..93074f8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface RendezVousRepository extends JpaRepository { -} +public interface RendezVousRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java index 70411d3..cc25ab1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface SectionsRepository extends JpaRepository { -} +public interface SectionsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java index fafbef5..dba41cc 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java @@ -16,40 +16,35 @@ import java.util.stream.Stream; import static java.util.stream.Collectors.toSet; - public class KeycloakJwtRolesConverter implements Converter { - /** - * Prefix used for realm level roles. - */ + /** Prefix used for realm level roles. */ public static final String PREFIX_REALM_ROLE = "ROLE_REALM_"; - /** - * Prefix used in combination with the resource (client) name for resource level roles. - */ + + /** Prefix used in combination with the resource (client) name for resource level roles. */ public static final String PREFIX_RESOURCE_ROLE = "ROLE_"; - /** - * Name of the claim containing the realm level roles - */ + /** Name of the claim containing the realm level roles */ private static final String CLAIM_REALM_ACCESS = "realm_access"; - /** - * Name of the claim containing the resources (clients) the user has access to. - */ + + /** Name of the claim containing the resources (clients) the user has access to. */ private static final String CLAIM_RESOURCE_ACCESS = "resource_access"; - /** - * Name of the claim containing roles. (Applicable to realm and resource level.) - */ + + /** Name of the claim containing roles. (Applicable to realm and resource level.) */ private static final String CLAIM_ROLES = "roles"; @Override - public AbstractAuthenticationToken convert(Jwt source) - { - return new JwtAuthenticationToken(source, Stream.concat(new JwtGrantedAuthoritiesConverter().convert(source) - .stream(), TEMPORARNAME(source).stream()) - .collect(toSet())); + public AbstractAuthenticationToken convert(Jwt source) { + return new JwtAuthenticationToken( + source, + Stream.concat( + new JwtGrantedAuthoritiesConverter().convert(source).stream(), + TEMPORARNAME(source).stream()) + .collect(toSet())); } /** - * Extracts the realm and resource level roles from a JWT token distinguishing between them using prefixes. + * Extracts the realm and resource level roles from a JWT token distinguishing between them + * using prefixes. */ public Collection TEMPORARNAME(Jwt jwt) { // Collection that will hold the extracted roles @@ -66,33 +61,43 @@ public class KeycloakJwtRolesConverter implements Converter realmRoles = roles.stream() - // Prefix all realm roles with "ROLE_realm_" - .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role)) - .collect(Collectors.toList()); + Collection realmRoles = + roles.stream() + // Prefix all realm roles with "ROLE_realm_" + .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role)) + .collect(Collectors.toList()); grantedAuthorities.addAll(realmRoles); } } // Resource (client) roles - // A user might have access to multiple resources all containing their own roles. Therefore, it is a map of + // A user might have access to multiple resources all containing their own roles. Therefore, + // it is a map of // resource each possibly containing a "roles" property. - Map>> resourceAccess = jwt.getClaim(CLAIM_RESOURCE_ACCESS); + Map>> resourceAccess = + jwt.getClaim(CLAIM_RESOURCE_ACCESS); // Check if resources are assigned if (resourceAccess != null && !resourceAccess.isEmpty()) { // Iterate of all the resources - resourceAccess.forEach((resource, resourceClaims) -> { - // Iterate of the "roles" claim inside the resource claims - resourceClaims.get(CLAIM_ROLES).forEach( - // Add the role to the granted authority prefixed with ROLE_ and the name of the resource - role -> grantedAuthorities.add(new SimpleGrantedAuthority(PREFIX_RESOURCE_ROLE + resource + "_" + role)) - ); - }); + resourceAccess.forEach( + (resource, resourceClaims) -> { + // Iterate of the "roles" claim inside the resource claims + resourceClaims + .get(CLAIM_ROLES) + .forEach( + // Add the role to the granted authority prefixed with ROLE_ + // and the name of the resource + role -> + grantedAuthorities.add( + new SimpleGrantedAuthority( + PREFIX_RESOURCE_ROLE + + resource + + "_" + + role))); + }); } return grantedAuthorities; } - - } diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java index dce5ab2..04669ca 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java @@ -6,8 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class MyinpulseApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} } -- 2.47.2 From 1498b5908b84f554f6d5d96176d9d390dc7d39ae Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 19:24:04 +0100 Subject: [PATCH 10/97] fix: should now catch errors ? --- .gitea/workflows/back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 0e74e38..6cf8f56 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -14,6 +14,6 @@ jobs: java-version: '21' - uses: axel-op/googlejavaformat-action@v3 with: - args: "--replace --skip-sorting-imports --aosp" + args: "--skip-sorting-imports --aosp" - name: Print diffs run: git --no-pager diff --exit-code \ No newline at end of file -- 2.47.2 From 70b00a19967426f7b41a0507b0dc066f39e99a7e Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Feb 2025 19:27:22 +0100 Subject: [PATCH 11/97] feat: test on github validation --- .gitea/workflows/back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 6cf8f56..0e74e38 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -14,6 +14,6 @@ jobs: java-version: '21' - uses: axel-op/googlejavaformat-action@v3 with: - args: "--skip-sorting-imports --aosp" + args: "--replace --skip-sorting-imports --aosp" - name: Print diffs run: git --no-pager diff --exit-code \ No newline at end of file -- 2.47.2 From 9e2ab9fa5aa0dc72b663b479e3f6df3654ca6824 Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Tue, 11 Feb 2025 18:27:36 +0000 Subject: [PATCH 12/97] Google Java Format --- .../src/main/java/enseirb/myinpulse/MyinpulseApplication.java | 1 - .../myinpulse/config/WebSecurityCustomConfiguration.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java index 1c39eef..196569d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/MyinpulseApplication.java @@ -6,7 +6,6 @@ import org.springframework.security.oauth2.jwt.*; import java.util.*; - @SpringBootApplication public class MyinpulseApplication { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index e642fd8..43a9889 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -28,7 +28,7 @@ public class WebSecurityCustomConfiguration { "authorization", "content-type", "x-auth-token")); // Do not remove, this fixes the CORS errors when - // unauthenticated + // unauthenticated UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); -- 2.47.2 From 1e971777776b05f63c2bb9ceb09e72237be0b992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Tue, 11 Feb 2025 21:15:13 +0100 Subject: [PATCH 13/97] fix: issue with foreign keys --- .../controller/AdministrateursController.java | 44 +++--- .../controller/ComptesRendusController.java | 60 ++++---- .../controller/EntrepreneursController.java | 77 +++++----- .../controller/ProjetsController.java | 89 +++++------ .../controller/RendezVousController.java | 97 ++++++------ .../controller/SectionsController.java | 80 +++++----- .../controller/UtilisateursController.java | 90 +++++------ .../postgres_db/model/Administrateurs.java | 40 +++-- .../postgres_db/model/ComptesRendus.java | 54 ++++--- .../postgres_db/model/Entrepreneurs.java | 98 +++++++----- .../myinpulse/postgres_db/model/Projets.java | 126 +++++++-------- .../postgres_db/model/RendezVous.java | 144 +++++++++--------- .../myinpulse/postgres_db/model/Sections.java | 96 ++++++------ .../postgres_db/model/Utilisateurs.java | 125 +++++++-------- .../repository/AdministrateursRepository.java | 4 +- .../repository/ComptesRendusRepository.java | 3 +- .../repository/EntrepreneursRepository.java | 4 +- .../repository/ProjetsRepository.java | 3 +- .../repository/RendezVousRepository.java | 3 +- .../repository/SectionsRepository.java | 3 +- .../repository/UtilisateursRepository.java | 4 +- .../src/main/resources/application.properties | 2 +- MyINPulse-back/src/main/resources/data.sql | 2 - MyINPulse-back/src/main/resources/schema.sql | 1 - 24 files changed, 636 insertions(+), 613 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java index 5f1a718..dccde43 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java @@ -1,39 +1,35 @@ package enseirb.myinpulse.postgres_db.controller; +import enseirb.myinpulse.postgres_db.model.Administrateurs; import enseirb.myinpulse.postgres_db.repository.AdministrateursRepository; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import enseirb.myinpulse.postgres_db.model.Administrateurs; import org.springframework.web.server.ResponseStatusException; -import java.util.Optional; - @RestController public class AdministrateursController { - @Autowired - AdministrateursRepository administrateursRepository; + @Autowired AdministrateursRepository administrateursRepository; - @GetMapping("/Administrateurs") - @ResponseBody - public Iterable allAdministrateurs() { - return this.administrateursRepository.findAll(); - } - - @GetMapping("/Administrateurs/{id}") - public Administrateurs getAdministrateursById(@PathVariable Long id) - { - Optional administrateur = this.administrateursRepository.findById(id); - if (administrateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); - } - return administrateur.get(); - } - - @PostMapping("/Administrateurs") - public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { - return this.administrateursRepository.save(administrateurs); + @GetMapping("/Administrateurs") + @ResponseBody + public Iterable allAdministrateurs() { + return this.administrateursRepository.findAll(); + } + + @GetMapping("/Administrateurs/{id}") + public Administrateurs getAdministrateursById(@PathVariable Long id) { + Optional administrateur = this.administrateursRepository.findById(id); + if (administrateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); } + return administrateur.get(); + } + @PostMapping("/Administrateurs") + public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { + return this.administrateursRepository.save(administrateurs); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index 9bcc862..c0d1b01 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -1,49 +1,47 @@ package enseirb.myinpulse.postgres_db.controller; +import enseirb.myinpulse.postgres_db.model.ComptesRendus; import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import enseirb.myinpulse.postgres_db.model.ComptesRendus; import org.springframework.web.server.ResponseStatusException; -import java.util.Optional; - @RestController public class ComptesRendusController { - @Autowired - ComptesRendusRepository comptesRendusRepository; + @Autowired ComptesRendusRepository comptesRendusRepository; - @GetMapping("/ComptesRendus") - @ResponseBody - public Iterable allComptesRendus() { - return this.comptesRendusRepository.findAll(); - } + @GetMapping("/ComptesRendus") + @ResponseBody + public Iterable allComptesRendus() { + return this.comptesRendusRepository.findAll(); + } - @GetMapping("/ComptesRendus/{id}") - public ComptesRendus getComptesRendusById(@PathVariable Long id) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - return compteRendu.get(); + @GetMapping("/ComptesRendus/{id}") + public ComptesRendus getComptesRendusById(@PathVariable Long id) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); } + return compteRendu.get(); + } - @PostMapping("/ComptesRendus") - public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { - return this.comptesRendusRepository.save(comptesRendus); - } + @PostMapping("/ComptesRendus") + public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { + return this.comptesRendusRepository.save(comptesRendus); + } - @PostMapping("/ComptesRendus/{id}") - public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - if (contenu_compte_rendu != null) { - compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); - } - return compteRendu.get(); + @PostMapping("/ComptesRendus/{id}") + public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); } + if (contenu_compte_rendu != null) { + compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); + } + return compteRendu.get(); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java index 2bbc653..92aed2b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -1,59 +1,54 @@ package enseirb.myinpulse.postgres_db.controller; +import enseirb.myinpulse.postgres_db.model.Entrepreneurs; import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatusCode; import org.springframework.web.bind.annotation.*; -import enseirb.myinpulse.postgres_db.model.Entrepreneurs; import org.springframework.web.server.ResponseStatusException; -import java.util.Optional; - - @RestController public class EntrepreneursController { - @Autowired - EntrepreneursRepository entrepreneursRepository; + @Autowired EntrepreneursRepository entrepreneursRepository; - @GetMapping("/Entrepreneurs") - @ResponseBody - public Iterable allEntrepreneurs() { - return this.entrepreneursRepository.findAll(); + @GetMapping("/Entrepreneurs") + @ResponseBody + public Iterable allEntrepreneurs() { + return this.entrepreneursRepository.findAll(); + } + + @GetMapping("/Entrepreneurs/{id}") + public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } + return entrepreneur.get(); + } - @GetMapping("/Entrepreneurs/{id}") - public Entrepreneurs getEntrepreneursById(@PathVariable Long id) - { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); - } - return entrepreneur.get(); + @PostMapping("/Entrepreneurs") + public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { + return this.entrepreneursRepository.save(entrepreneurs); + } + + @PostMapping("/Entrepreneurs/{id}") + public Entrepreneurs updateEntrepreneurs( + @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } - - @PostMapping("/Entrepreneurs") - public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { - return this.entrepreneursRepository.save(entrepreneurs); + if (ecole != null) { + entrepreneur.get().setEcole(ecole); } - - @PostMapping("/Entrepreneurs/{id}") - public Entrepreneurs updateEntrepreneurs(@PathVariable Long id, String ecole, String filiere, Boolean status_snee) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); - } - if (ecole != null) { - entrepreneur.get().setEcole(ecole); - } - if (filiere != null) { - entrepreneur.get().setFiliere(filiere); - } - if (status_snee != null) { - entrepreneur.get().setStatus_snee(status_snee); - } - return entrepreneur.get(); + if (filiere != null) { + entrepreneur.get().setFiliere(filiere); } - + if (status_snee != null) { + entrepreneur.get().setStatus_snee(status_snee); + } + return entrepreneur.get(); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java index 92b5908..2f7418a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -1,61 +1,62 @@ package enseirb.myinpulse.postgres_db.controller; +import enseirb.myinpulse.postgres_db.model.Projets; import enseirb.myinpulse.postgres_db.repository.ProjetsRepository; +import java.time.LocalDate; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import enseirb.myinpulse.postgres_db.model.Projets; import org.springframework.web.server.ResponseStatusException; -import java.time.LocalDate; -import java.util.Optional; - @RestController public class ProjetsController { - @Autowired - ProjetsRepository projetsRepository; + @Autowired ProjetsRepository projetsRepository; - @GetMapping("/Projets") - @ResponseBody - public Iterable allProjets() { - return this.projetsRepository.findAll(); + @GetMapping("/Projets") + @ResponseBody + public Iterable allProjets() { + return this.projetsRepository.findAll(); + } + + @GetMapping("/Projets/{id}") + public Projets getProjetsById(@PathVariable Long id) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); } + return projet.get(); + } - @GetMapping("/Projets/{id}") - public Projets getProjetsById(@PathVariable Long id) - { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); - } - return projet.get(); + @PostMapping("/Projets") + public Projets addProjets(@RequestBody Projets projet) { + return this.projetsRepository.save(projet); + } + + @PostMapping("/Projets/{id}") + public Projets updateProjets( + @PathVariable Long id, + String nom_projet, + byte[] logo, + LocalDate date_creation, + String status_projet) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); } - - @PostMapping("/Projets") - public Projets addProjets(@RequestBody Projets projet) { - return this.projetsRepository.save(projet); + if (nom_projet != null) { + projet.get().setNom_projet(nom_projet); } - - @PostMapping("/Projets/{id}") - public Projets updateProjets(@PathVariable Long id, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); - } - if (nom_projet != null) { - projet.get().setNom_projet(nom_projet); - } - if (logo != null) { - projet.get().setLogo(logo); - } - if (date_creation != null) { - projet.get().setDate_creation(date_creation); - } - if (status_projet != null) { - projet.get().setStatus_projet(status_projet); - } - return projet.get(); + if (logo != null) { + projet.get().setLogo(logo); } - -} \ No newline at end of file + if (date_creation != null) { + projet.get().setDate_creation(date_creation); + } + if (status_projet != null) { + projet.get().setStatus_projet(status_projet); + } + return projet.get(); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java index aa9e3ba..1b05bc4 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -1,64 +1,67 @@ package enseirb.myinpulse.postgres_db.controller; -import enseirb.myinpulse.postgres_db.repository.RendezVousRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; import enseirb.myinpulse.postgres_db.model.RendezVous; -import org.springframework.web.server.ResponseStatusException; - +import enseirb.myinpulse.postgres_db.repository.RendezVousRepository; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Optional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; @RestController public class RendezVousController { - @Autowired - RendezVousRepository rendezVousRepository; + @Autowired RendezVousRepository rendezVousRepository; - @GetMapping("/RendezVous") - @ResponseBody - public Iterable allRendezVous() { - return this.rendezVousRepository.findAll(); - } + @GetMapping("/RendezVous") + @ResponseBody + public Iterable allRendezVous() { + return this.rendezVousRepository.findAll(); + } - @GetMapping("/RendezVous/{id}") - public RendezVous getRendezVousById(@PathVariable Long id) - { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - return rendezVous.get(); + @GetMapping("/RendezVous/{id}") + public RendezVous getRendezVousById(@PathVariable Long id) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); } + return rendezVous.get(); + } - @PostMapping("/RendezVous") - public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { - return this.rendezVousRepository.save(rendezVous); - } + @PostMapping("/RendezVous") + public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { + return this.rendezVousRepository.save(rendezVous); + } - @PostMapping("/RendezVous/{id}") - public RendezVous updateRendezVous(@PathVariable Long id, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - if (date_rdv != null) { - rendezVous.get().setDate_rdv(date_rdv); - } - if (heure_rdv != null) { - rendezVous.get().setHeure_rdv(heure_rdv); - } - if (duree_rdv != null) { - rendezVous.get().setDuree_rdv(duree_rdv); - } - if (lieu_rdv != null) { - rendezVous.get().setLieu_rdv(lieu_rdv); - } - if (sujet_rdv != null) { - rendezVous.get().setSujet_rdv(sujet_rdv); - } - return rendezVous.get(); + @PostMapping("/RendezVous/{id}") + public RendezVous updateRendezVous( + @PathVariable Long id, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); } + if (date_rdv != null) { + rendezVous.get().setDate_rdv(date_rdv); + } + if (heure_rdv != null) { + rendezVous.get().setHeure_rdv(heure_rdv); + } + if (duree_rdv != null) { + rendezVous.get().setDuree_rdv(duree_rdv); + } + if (lieu_rdv != null) { + rendezVous.get().setLieu_rdv(lieu_rdv); + } + if (sujet_rdv != null) { + rendezVous.get().setSujet_rdv(sujet_rdv); + } + return rendezVous.get(); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java index 49032fe..487615a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -1,58 +1,58 @@ package enseirb.myinpulse.postgres_db.controller; +import enseirb.myinpulse.postgres_db.model.Sections; import enseirb.myinpulse.postgres_db.repository.SectionsRepository; +import java.time.LocalDateTime; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import enseirb.myinpulse.postgres_db.model.Sections; import org.springframework.web.server.ResponseStatusException; -import java.time.LocalDateTime; -import java.util.Optional; - @RestController public class SectionsController { - @Autowired - SectionsRepository sectionsRepository; + @Autowired SectionsRepository sectionsRepository; - @GetMapping("/Sections") - @ResponseBody - public Iterable allSections() { - return this.sectionsRepository.findAll(); + @GetMapping("/Sections") + @ResponseBody + public Iterable allSections() { + return this.sectionsRepository.findAll(); + } + + @GetMapping("/Sections/{id}") + public Sections getSectionsById(@PathVariable Long id) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); } + return section.get(); + } - @GetMapping("/Sections/{id}") - public Sections getSectionsById(@PathVariable Long id) - { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); - } - return section.get(); + @PostMapping("/Sections") + public Sections addSections(@RequestBody Sections sections) { + return this.sectionsRepository.save(sections); + } + + @PostMapping("/Sections/{id}") + public Sections updateSections( + @PathVariable Long id, + String titre, + String contenu_section, + LocalDateTime date_modification) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); } - - @PostMapping("/Sections") - public Sections addSections(@RequestBody Sections sections) { - return this.sectionsRepository.save(sections); + if (titre != null) { + section.get().setTitre(titre); } - - @PostMapping("/Sections/{id}") - public Sections updateSections(@PathVariable Long id, String titre, String contenu_section, LocalDateTime date_modification) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); - } - if (titre != null) { - section.get().setTitre(titre); - } - if (contenu_section != null) { - section.get().setContenu_section(contenu_section); - } - if (date_modification != null) { - section.get().setDate_modification(date_modification); - } - return section.get(); + if (contenu_section != null) { + section.get().setContenu_section(contenu_section); } - + if (date_modification != null) { + section.get().setDate_modification(date_modification); + } + return section.get(); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java index 059e2f0..ee5be49 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -1,61 +1,65 @@ package enseirb.myinpulse.postgres_db.controller; +import enseirb.myinpulse.postgres_db.model.Utilisateurs; import enseirb.myinpulse.postgres_db.repository.UtilisateursRepository; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; -import enseirb.myinpulse.postgres_db.model.Utilisateurs; import org.springframework.web.server.ResponseStatusException; -import java.util.Optional; - @RestController public class UtilisateursController { - @Autowired - UtilisateursRepository utilisateursRepository; + @Autowired UtilisateursRepository utilisateursRepository; - @GetMapping("/Utilisateurs") - @ResponseBody - public Iterable allUtilisateurs() { - return this.utilisateursRepository.findAll(); + @GetMapping("/Utilisateurs") + @ResponseBody + public Iterable allUtilisateurs() { + return this.utilisateursRepository.findAll(); + } + + @GetMapping("/Utilisateurs/{id}") + public Utilisateurs getUtilisateursById(@PathVariable Long id) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); } + return utilisateur.get(); + } - @GetMapping("/Utilisateurs/{id}") - public Utilisateurs getUtilisateursById(@PathVariable Long id) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - return utilisateur.get(); + @PostMapping("/Utilisateurs") + public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { + return this.utilisateursRepository.save(utilisateurs); + } + + @PostMapping("/Utilisateurs/{id}") + public Utilisateurs updateUtilisateurs( + @PathVariable Long id, + String nom_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); } - - @PostMapping("/Utilisateurs") - public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { - return this.utilisateursRepository.save(utilisateurs); + if (nom_utilisateur != null) { + utilisateur.get().setNom_utilisateur(nom_utilisateur); } - - @PostMapping("/Utilisateurs/{id}") - public Utilisateurs updateUtilisateurs(@PathVariable Long id, String nom_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - }if (nom_utilisateur != null) { - utilisateur.get().setNom_utilisateur(nom_utilisateur); - } - if (prenom_utilisateur != null) { - utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); - } - if (mail_principal != null) { - utilisateur.get().setMail_principal(mail_principal); - } - if (mail_secondaire != null) { - utilisateur.get().setMail_secondaire(mail_secondaire); - } - if (numero_telephone != null) { - utilisateur.get().setNumero_telephone(numero_telephone); - } - return utilisateur.get(); + if (prenom_utilisateur != null) { + utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); } - + if (mail_principal != null) { + utilisateur.get().setMail_principal(mail_principal); + } + if (mail_secondaire != null) { + utilisateur.get().setMail_secondaire(mail_secondaire); + } + if (numero_telephone != null) { + utilisateur.get().setNumero_telephone(numero_telephone); + } + return utilisateur.get(); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java index 0255adf..a7390d0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -3,32 +3,40 @@ package enseirb.myinpulse.postgres_db.model; import jakarta.persistence.*; import jakarta.persistence.PrimaryKeyJoinColumn; import jakarta.persistence.Table; - import java.util.ArrayList; import java.util.List; @Entity @Table(name = "administrateurs") @PrimaryKeyJoinColumn(name = "id_administrateur") - public class Administrateurs extends Utilisateurs { - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "Projets.id_projets") - private Projets projets; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet") + private Projets projetsAdministrateurs; - @OneToMany(mappedBy = "administrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); + @OneToMany(mappedBy = "administrateursSections", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "RendezVous.id_rdv") - private RendezVous rendezVous; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousAdministrateurs; - public Administrateurs() { - } - - public Administrateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { - super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); - } + public Administrateurs() {} + public Administrateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java index cd7f283..83871cc 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java @@ -1,7 +1,7 @@ package enseirb.myinpulse.postgres_db.model; -import jakarta.persistence.Entity; import jakarta.persistence.*; +import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; @@ -10,39 +10,37 @@ import jakarta.validation.constraints.NotNull; @Table(name = "comptes_rendus") public class ComptesRendus { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_compte_rendu; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_compte_rendu; - private String contenu_compte_rendu; + private String contenu_compte_rendu; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "RendezVous.id_rdv") - private RendezVous rendezVous; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousComptesRendus; + public ComptesRendus() {} - public ComptesRendus() { - } + public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + this.contenu_compte_rendu = contenu_compte_rendu; + } - public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - this.contenu_compte_rendu = contenu_compte_rendu; - } + public Long getId_compte_rendu() { + return id_compte_rendu; + } - public Long getId_compte_rendu() { - return id_compte_rendu; - } + public void setId_compte_rendu(Long id_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + } - public void setId_compte_rendu(Long id_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - } + public String getContenu_compte_rendu() { + return contenu_compte_rendu; + } - public String getContenu_compte_rendu() { - return contenu_compte_rendu; - } - - public void setContenu_compte_rendu(String contenu_compte_rendu) { - this.contenu_compte_rendu = contenu_compte_rendu; - } + public void setContenu_compte_rendu(String contenu_compte_rendu) { + this.contenu_compte_rendu = contenu_compte_rendu; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java index b8f6964..a353b51 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java @@ -1,7 +1,7 @@ package enseirb.myinpulse.postgres_db.model; -import jakarta.persistence.Entity; import jakarta.persistence.*; +import jakarta.persistence.Entity; import jakarta.persistence.Table; @Entity @@ -9,58 +9,72 @@ import jakarta.persistence.Table; @PrimaryKeyJoinColumn(name = "id_entrepreneur") public class Entrepreneurs extends Utilisateurs { - @Column(length=255) - private String ecole; + @Column(length = 255) + private String ecole; - @Column(length=255) - private String filiere; + @Column(length = 255) + private String filiere; - private boolean status_snee; + private boolean status_snee; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "Projets.id_projets") - private Projets projets_participation; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet_participation", referencedColumnName = "id_projet") + private Projets projetsParticipation; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "Projets.id_projets") - private Projets projets_propose; + // @Column(insertable=false, updatable=false) + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet_propose", referencedColumnName = "id_projet") + private Projets projetsPropose; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "RendezVous.id_rdv") - private RendezVous rendezVous; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousEntrepreneurs; + public Entrepreneurs() {} - public Entrepreneurs() { - } + public Entrepreneurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone, + String ecole, + boolean status_snee, + String filiere) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); + this.ecole = ecole; + this.status_snee = status_snee; + this.filiere = filiere; + } - public Entrepreneurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone, String ecole, boolean status_snee, String filiere) { - super(nom_utilisateur, id_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone); - this.ecole = ecole; - this.status_snee = status_snee; - this.filiere = filiere; - } + public String getEcole() { + return ecole; + } - public String getEcole() { - return ecole; - } + public void setEcole(String ecole) { + this.ecole = ecole; + } - public void setEcole(String ecole) { - this.ecole = ecole; - } + public String getFiliere() { + return filiere; + } - public String getFiliere() { - return filiere; - } + public void setFiliere(String filiere) { + this.filiere = filiere; + } - public void setFiliere(String filiere) { - this.filiere = filiere; - } + public boolean isStatus_snee() { + return status_snee; + } - public boolean isStatus_snee() { - return status_snee; - } - - public void setStatus_snee(boolean status_snee) { - this.status_snee = status_snee; - } + public void setStatus_snee(boolean status_snee) { + this.status_snee = status_snee; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java index 6fd8d98..b034432 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java @@ -2,7 +2,6 @@ package enseirb.myinpulse.postgres_db.model; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; - import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -11,85 +10,88 @@ import java.util.List; @Table(name = "projets") public class Projets { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_projet; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_projet; - @Column(length=255) - private String nom_projet; + @Column(length = 255) + private String nom_projet; - private Byte[] logo; + private byte[] logo; - private LocalDate date_creation; + private LocalDate date_creation; - @Column(length=255) - private String status_projet; + @Column(length = 255) + private String status_projet; - @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) - private List listAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "projetsAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List listAdministrateurs = new ArrayList<>(); - @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneursParticipation = new ArrayList<>(); + @OneToMany(mappedBy = "projetsParticipation", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneursParticipation = new ArrayList<>(); - @OneToOne(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) - private Entrepreneurs entrepreneurs_propose; + @OneToOne(mappedBy = "projetsPropose", fetch = FetchType.LAZY, orphanRemoval = true) + private Entrepreneurs entrepreneursPropose; - @OneToMany(mappedBy = "projets", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); + @OneToMany(mappedBy = "projetsSections", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); - // Hibernate expects entities to have a no-arg constructor, - // though it does not necessarily have to be public. + // Hibernate expects entities to have a no-arg constructor, + // though it does not necessarily have to be public. - public Projets() { - } + public Projets() {} - public Projets(Long id_projet, String nom_projet, Byte[] logo, LocalDate date_creation, String status_projet) { - this.id_projet = id_projet; - this.nom_projet = nom_projet; - this.logo = logo; - this.date_creation = date_creation; - this.status_projet = status_projet; - } + public Projets( + Long id_projet, + String nom_projet, + byte[] logo, + LocalDate date_creation, + String status_projet) { + this.id_projet = id_projet; + this.nom_projet = nom_projet; + this.logo = logo; + this.date_creation = date_creation; + this.status_projet = status_projet; + } - public Long getId_projet() { - return id_projet; - } + public Long getId_projet() { + return id_projet; + } - public void setId_projet(Long id_projet) { - this.id_projet = id_projet; - } + public void setId_projet(Long id_projet) { + this.id_projet = id_projet; + } - public String getNom_projet() { - return nom_projet; - } + public String getNom_projet() { + return nom_projet; + } - public void setNom_projet(String nom_projet) { - this.nom_projet = nom_projet; - } + public void setNom_projet(String nom_projet) { + this.nom_projet = nom_projet; + } - public Byte[] getLogo() { - return logo; - } + public byte[] getLogo() { + return logo; + } - public void setLogo(Byte[] logo) { - this.logo = logo; - } + public void setLogo(byte[] logo) { + this.logo = logo; + } - public LocalDate getDate_creation() { - return date_creation; - } + public LocalDate getDate_creation() { + return date_creation; + } - public void setDate_creation(LocalDate date_creation) { - this.date_creation = date_creation; - } + public void setDate_creation(LocalDate date_creation) { + this.date_creation = date_creation; + } - public String getStatus_projet() { - return status_projet; - } + public String getStatus_projet() { + return status_projet; + } - public void setStatus_projet(String status_projet) { - this.status_projet = status_projet; - } - -} \ No newline at end of file + public void setStatus_projet(String status_projet) { + this.status_projet = status_projet; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index 78fbfc2..bd2f482 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -12,96 +12,102 @@ import java.util.List; @Table(name = "rendez_vous") public class RendezVous { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_rdv; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_rdv; - private LocalDate date_rdv; + private LocalDate date_rdv; - private LocalDateTime heure_rdv; + private LocalDateTime heure_rdv; - private LocalDateTime duree_rdv; + private LocalDateTime duree_rdv; - @Column(length=255) - private String lieu_rdv; + @Column(length = 255) + private String lieu_rdv; - private String sujet_rdv; + private String sujet_rdv; - @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneurs = new ArrayList<>(); - @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListAdministrateurs = new ArrayList<>(); - @OneToMany(mappedBy = "rendez_vous", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListComptesRendus = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListComptesRendus = new ArrayList<>(); - @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }) - @JoinTable( - name = "concerner", - joinColumns = @JoinColumn(name = "id_rdv"), - inverseJoinColumns = @JoinColumn(name = "id_sections")) - List ListSections = new ArrayList<>(); + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.ALL}) + @JoinTable( + name = "concerner", + joinColumns = @JoinColumn(name = "id_rdv"), + inverseJoinColumns = @JoinColumn(name = "id_section")) + List ListSections = new ArrayList<>(); - public RendezVous() { - } + public RendezVous() {} - public RendezVous(Long id_rdv, LocalDate date_rdv, LocalDateTime heure_rdv, LocalDateTime duree_rdv, String lieu_rdv, String sujet_rdv) { - this.id_rdv = id_rdv; - this.date_rdv = date_rdv; - this.heure_rdv = heure_rdv; - this.duree_rdv = duree_rdv; - this.lieu_rdv = lieu_rdv; - this.sujet_rdv = sujet_rdv; - } + public RendezVous( + Long id_rdv, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { + this.id_rdv = id_rdv; + this.date_rdv = date_rdv; + this.heure_rdv = heure_rdv; + this.duree_rdv = duree_rdv; + this.lieu_rdv = lieu_rdv; + this.sujet_rdv = sujet_rdv; + } - public Long getId_rdv() { - return id_rdv; - } + public Long getId_rdv() { + return id_rdv; + } - public void setId_rdv(Long id_rdv) { - this.id_rdv = id_rdv; - } + public void setId_rdv(Long id_rdv) { + this.id_rdv = id_rdv; + } - public LocalDate getDate_rdv() { - return date_rdv; - } + public LocalDate getDate_rdv() { + return date_rdv; + } - public void setDate_rdv(LocalDate date_rdv) { - this.date_rdv = date_rdv; - } + public void setDate_rdv(LocalDate date_rdv) { + this.date_rdv = date_rdv; + } - public LocalDateTime getHeure_rdv() { - return heure_rdv; - } + public LocalDateTime getHeure_rdv() { + return heure_rdv; + } - public void setHeure_rdv(LocalDateTime heure_rdv) { - this.heure_rdv = heure_rdv; - } + public void setHeure_rdv(LocalDateTime heure_rdv) { + this.heure_rdv = heure_rdv; + } - public LocalDateTime getDuree_rdv() { - return duree_rdv; - } + public LocalDateTime getDuree_rdv() { + return duree_rdv; + } - public void setDuree_rdv(LocalDateTime duree_rdv) { - this.duree_rdv = duree_rdv; - } + public void setDuree_rdv(LocalDateTime duree_rdv) { + this.duree_rdv = duree_rdv; + } - public String getLieu_rdv() { - return lieu_rdv; - } + public String getLieu_rdv() { + return lieu_rdv; + } - public void setLieu_rdv(String lieu_rdv) { - this.lieu_rdv = lieu_rdv; - } + public void setLieu_rdv(String lieu_rdv) { + this.lieu_rdv = lieu_rdv; + } - public String getSujet_rdv() { - return sujet_rdv; - } - - public void setSujet_rdv(String sujet_rdv) { - this.sujet_rdv = sujet_rdv; - } + public String getSujet_rdv() { + return sujet_rdv; + } + public void setSujet_rdv(String sujet_rdv) { + this.sujet_rdv = sujet_rdv; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java index f5852ac..299ab3e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java @@ -11,68 +11,68 @@ import java.util.List; @Table(name = "sections") public class Sections { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_section; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_section; - @Column(length=255) - private String titre; + @Column(length = 255) + private String titre; - private String contenu_section; + private String contenu_section; - private LocalDateTime date_modification; + private LocalDateTime date_modification; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "Projets.id_projets") - private Projets projets; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet") + private Projets projetsSections; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "Administrateurs.id_admnistrateur") - private Administrateurs administrateurs; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_admnistrateur") + private Administrateurs administrateursSections; - @ManyToMany(mappedBy = "sections") - private List rendezVous = new ArrayList<>(); + @ManyToMany(mappedBy = "ListSections") + private List rendezVous = new ArrayList<>(); - public Sections() { - } + public Sections() {} - public Sections(Long id_section, String titre, String contenu_section, LocalDateTime date_modification) { - this.id_section = id_section; - this.titre = titre; - this.contenu_section = contenu_section; - this.date_modification = date_modification; - } + public Sections( + Long id_section, String titre, String contenu_section, LocalDateTime date_modification) { + this.id_section = id_section; + this.titre = titre; + this.contenu_section = contenu_section; + this.date_modification = date_modification; + } - public String getTitre() { - return titre; - } + public String getTitre() { + return titre; + } - public void setTitre(String titre) { - this.titre = titre; - } + public void setTitre(String titre) { + this.titre = titre; + } - public Long getId_section() { - return id_section; - } + public Long getId_section() { + return id_section; + } - public void setId_section(Long id_section) { - this.id_section = id_section; - } + public void setId_section(Long id_section) { + this.id_section = id_section; + } - public String getContenu_section() { - return contenu_section; - } + public String getContenu_section() { + return contenu_section; + } - public void setContenu_section(String contenu_section) { - this.contenu_section = contenu_section; - } + public void setContenu_section(String contenu_section) { + this.contenu_section = contenu_section; + } - public LocalDateTime getDate_modification() { - return date_modification; - } + public LocalDateTime getDate_modification() { + return date_modification; + } - public void setDate_modification(LocalDateTime date_modification) { - this.date_modification = date_modification; - } + public void setDate_modification(LocalDateTime date_modification) { + this.date_modification = date_modification; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java index e20de6b..683ee06 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java @@ -8,83 +8,88 @@ import jakarta.validation.constraints.NotNull; @Inheritance(strategy = InheritanceType.JOINED) public class Utilisateurs { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_utilisateur; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_utilisateur; - @Column(length=255) - private String nom_utilisateur; + @Column(length = 255) + private String nom_utilisateur; - @Column(length=255) - private String prenom_utilisateur; + @Column(length = 255) + private String prenom_utilisateur; - @Column(length=255) - private String mail_principal; + @Column(length = 255) + private String mail_principal; - @Column(length=255) - private String mail_secondaire; + @Column(length = 255) + private String mail_secondaire; - @Column(length=15) - private String numero_telephone; + @Column(length = 15) + private String numero_telephone; - public Utilisateurs() { - } + public Utilisateurs() {} - public Utilisateurs(String nom_utilisateur, Long id_utilisateur, String prenom_utilisateur, String mail_principal, String mail_secondaire, String numero_telephone) { - this.nom_utilisateur = nom_utilisateur; - this.id_utilisateur = id_utilisateur; - this.prenom_utilisateur = prenom_utilisateur; - this.mail_principal = mail_principal; - this.mail_secondaire = mail_secondaire; - this.numero_telephone = numero_telephone; - } + public Utilisateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + this.nom_utilisateur = nom_utilisateur; + this.id_utilisateur = id_utilisateur; + this.prenom_utilisateur = prenom_utilisateur; + this.mail_principal = mail_principal; + this.mail_secondaire = mail_secondaire; + this.numero_telephone = numero_telephone; + } - public Long getId_utilisateur() { - return id_utilisateur; - } + public Long getId_utilisateur() { + return id_utilisateur; + } - public void setId_utilisateur(Long id_utilisateur) { - this.id_utilisateur = id_utilisateur; - } + public void setId_utilisateur(Long id_utilisateur) { + this.id_utilisateur = id_utilisateur; + } - public String getNom_utilisateur() { - return nom_utilisateur; - } + public String getNom_utilisateur() { + return nom_utilisateur; + } - public void setNom_utilisateur(String nom_utilisateur) { - this.nom_utilisateur = nom_utilisateur; - } + public void setNom_utilisateur(String nom_utilisateur) { + this.nom_utilisateur = nom_utilisateur; + } - public String getPrenom_utilisateur() { - return prenom_utilisateur; - } + public String getPrenom_utilisateur() { + return prenom_utilisateur; + } - public void setPrenom_utilisateur(String prenom_utilisateur) { - this.prenom_utilisateur = prenom_utilisateur; - } + public void setPrenom_utilisateur(String prenom_utilisateur) { + this.prenom_utilisateur = prenom_utilisateur; + } - public String getMail_principal() { - return mail_principal; - } + public String getMail_principal() { + return mail_principal; + } - public void setMail_principal(String mail_principal) { - this.mail_principal = mail_principal; - } + public void setMail_principal(String mail_principal) { + this.mail_principal = mail_principal; + } - public String getMail_secondaire() { - return mail_secondaire; - } + public String getMail_secondaire() { + return mail_secondaire; + } - public void setMail_secondaire(String mail_secondaire) { - this.mail_secondaire = mail_secondaire; - } + public void setMail_secondaire(String mail_secondaire) { + this.mail_secondaire = mail_secondaire; + } - public String getNumero_telephone() { - return numero_telephone; - } + public String getNumero_telephone() { + return numero_telephone; + } - public void setNumero_telephone(String numero_telephone) { - this.numero_telephone = numero_telephone; - } + public void setNumero_telephone(String numero_telephone) { + this.numero_telephone = numero_telephone; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java index b59d2c0..c57ea24 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface AdministrateursRepository extends JpaRepository { - /* @Query("SELECT a from Administrateurs a") - Administrateurs findAllAdministrateurs(); */ + /* @Query("SELECT a from Administrateurs a") + Administrateurs findAllAdministrateurs(); */ } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java index 41a9c0e..e4de376 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ComptesRendusRepository extends JpaRepository { -} +public interface ComptesRendusRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java index bb09b74..02d2a29 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface EntrepreneursRepository extends JpaRepository { - /* @Query("SELECT e from Entrepreneurs e") - Entrepreneurs findAllEntrepreneurs(); */ + /* @Query("SELECT e from Entrepreneurs e") + Entrepreneurs findAllEntrepreneurs(); */ } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java index 6665c89..37f5d8e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ProjetsRepository extends JpaRepository { -} \ No newline at end of file +public interface ProjetsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java index be67f00..93074f8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface RendezVousRepository extends JpaRepository { -} +public interface RendezVousRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java index 70411d3..cc25ab1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java @@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface SectionsRepository extends JpaRepository { -} +public interface SectionsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java index 28aca29..40a14f8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface UtilisateursRepository extends JpaRepository { - /* @Query("SELECT u from Utilisateurs u") - Utilisateurs findAllUtilisateurs(); */ + /* @Query("SELECT u from Utilisateurs u") + Utilisateurs findAllUtilisateurs(); */ } diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index 80f88b1..b53191b 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -2,7 +2,7 @@ spring.application.name=myinpulse spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test logging.level.org.springframework.security=DEBUG -spring.datasource.url=jdbc:postgresql://localhost:5432/${MyINPulse_DB} +spring.datasource.url=jdbc:postgresql://postgres/${POSTGRES_DB} spring.datasource.username=${POSTGRES_USER} spring.datasource.password=${POSTGRES_PASSWORD} spring.jpa.hibernate.ddl-auto=update diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index f1a2289..bd0f49a 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -4,7 +4,6 @@ INSERT INTO projets (nom_projet, logo, date_creation, status_projet) VALUES ('Débat concours', decode('022024abd5486e245c145dda65116f', 'hex'), TO_DATE('22-NOV-2023', 'DD-MON-YYYY'), 'Suspendu'), ('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), 'Lancement'); - INSERT INTO utilisateurs (nom, prenom, mail_principal, mail_secondaire, numero_telephone) VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), @@ -39,7 +38,6 @@ INSERT INTO rendez_vous (date_rdv, heure_rdv, duree_rdv, lieu_rdv, sujet_rdv) VA (TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', "Là où le vent nous porte", "Journée la plus importante de l'année"), (TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', "Euh c'est par où l'amphi 56 ?", "Rentrée scolaire (il fait trop froid c'est quoi ça on est en août)"); - INSERT INTO comptes_rendus (contenu_compte_rendu) VALUES ("Ah oui ça c'est super, ah ouais j'aime bien, bien vu de penser à ça"), ("Bonne réunion"), diff --git a/MyINPulse-back/src/main/resources/schema.sql b/MyINPulse-back/src/main/resources/schema.sql index 4bd1034..4916414 100644 --- a/MyINPulse-back/src/main/resources/schema.sql +++ b/MyINPulse-back/src/main/resources/schema.sql @@ -17,7 +17,6 @@ date_creation DATE , status_projet VARCHAR(255) , CONSTRAINT pk_projet PRIMARY KEY (id_projet) ); - CREATE TABLE utilisateurs ( id_utilisateur SERIAL NOT NULL, -- 2.47.2 From f629fb4a4e0b461be6db627e48e13479db78d3c7 Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Wed, 12 Feb 2025 09:20:00 +0000 Subject: [PATCH 14/97] Google Java Format --- .../controller/AdministrateursController.java | 37 ++--- .../controller/ComptesRendusController.java | 54 +++---- .../controller/EntrepreneursController.java | 70 ++++---- .../controller/ProjetsController.java | 82 +++++----- .../controller/RendezVousController.java | 90 +++++------ .../controller/SectionsController.java | 74 ++++----- .../controller/UtilisateursController.java | 90 +++++------ .../postgres_db/model/Administrateurs.java | 48 +++--- .../postgres_db/model/ComptesRendus.java | 50 +++--- .../postgres_db/model/Entrepreneurs.java | 110 ++++++------- .../myinpulse/postgres_db/model/Projets.java | 126 +++++++-------- .../postgres_db/model/RendezVous.java | 150 +++++++++--------- .../myinpulse/postgres_db/model/Sections.java | 99 ++++++------ .../postgres_db/model/Utilisateurs.java | 130 +++++++-------- .../repository/AdministrateursRepository.java | 4 +- .../repository/EntrepreneursRepository.java | 4 +- .../repository/UtilisateursRepository.java | 4 +- 17 files changed, 614 insertions(+), 608 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java index dccde43..2a5d05e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java @@ -11,25 +11,26 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class AdministrateursController { - @Autowired AdministrateursRepository administrateursRepository; + @Autowired AdministrateursRepository administrateursRepository; - @GetMapping("/Administrateurs") - @ResponseBody - public Iterable allAdministrateurs() { - return this.administrateursRepository.findAll(); - } - - @GetMapping("/Administrateurs/{id}") - public Administrateurs getAdministrateursById(@PathVariable Long id) { - Optional administrateur = this.administrateursRepository.findById(id); - if (administrateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + @GetMapping("/Administrateurs") + @ResponseBody + public Iterable allAdministrateurs() { + return this.administrateursRepository.findAll(); } - return administrateur.get(); - } - @PostMapping("/Administrateurs") - public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { - return this.administrateursRepository.save(administrateurs); - } + @GetMapping("/Administrateurs/{id}") + public Administrateurs getAdministrateursById(@PathVariable Long id) { + Optional administrateur = this.administrateursRepository.findById(id); + if (administrateur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + return administrateur.get(); + } + + @PostMapping("/Administrateurs") + public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { + return this.administrateursRepository.save(administrateurs); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index c0d1b01..312ae9e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -11,37 +11,37 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class ComptesRendusController { - @Autowired ComptesRendusRepository comptesRendusRepository; + @Autowired ComptesRendusRepository comptesRendusRepository; - @GetMapping("/ComptesRendus") - @ResponseBody - public Iterable allComptesRendus() { - return this.comptesRendusRepository.findAll(); - } - - @GetMapping("/ComptesRendus/{id}") - public ComptesRendus getComptesRendusById(@PathVariable Long id) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + @GetMapping("/ComptesRendus") + @ResponseBody + public Iterable allComptesRendus() { + return this.comptesRendusRepository.findAll(); } - return compteRendu.get(); - } - @PostMapping("/ComptesRendus") - public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { - return this.comptesRendusRepository.save(comptesRendus); - } + @GetMapping("/ComptesRendus/{id}") + public ComptesRendus getComptesRendusById(@PathVariable Long id) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + return compteRendu.get(); + } - @PostMapping("/ComptesRendus/{id}") - public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + @PostMapping("/ComptesRendus") + public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { + return this.comptesRendusRepository.save(comptesRendus); } - if (contenu_compte_rendu != null) { - compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); + + @PostMapping("/ComptesRendus/{id}") + public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + if (contenu_compte_rendu != null) { + compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); + } + return compteRendu.get(); } - return compteRendu.get(); - } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java index 92aed2b..f789e0d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -11,44 +11,46 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class EntrepreneursController { - @Autowired EntrepreneursRepository entrepreneursRepository; + @Autowired EntrepreneursRepository entrepreneursRepository; - @GetMapping("/Entrepreneurs") - @ResponseBody - public Iterable allEntrepreneurs() { - return this.entrepreneursRepository.findAll(); - } + @GetMapping("/Entrepreneurs") + @ResponseBody + public Iterable allEntrepreneurs() { + return this.entrepreneursRepository.findAll(); + } - @GetMapping("/Entrepreneurs/{id}") - public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + @GetMapping("/Entrepreneurs/{id}") + public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + return entrepreneur.get(); } - return entrepreneur.get(); - } - @PostMapping("/Entrepreneurs") - public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { - return this.entrepreneursRepository.save(entrepreneurs); - } + @PostMapping("/Entrepreneurs") + public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { + return this.entrepreneursRepository.save(entrepreneurs); + } - @PostMapping("/Entrepreneurs/{id}") - public Entrepreneurs updateEntrepreneurs( - @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + @PostMapping("/Entrepreneurs/{id}") + public Entrepreneurs updateEntrepreneurs( + @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + if (ecole != null) { + entrepreneur.get().setEcole(ecole); + } + if (filiere != null) { + entrepreneur.get().setFiliere(filiere); + } + if (status_snee != null) { + entrepreneur.get().setStatus_snee(status_snee); + } + return entrepreneur.get(); } - if (ecole != null) { - entrepreneur.get().setEcole(ecole); - } - if (filiere != null) { - entrepreneur.get().setFiliere(filiere); - } - if (status_snee != null) { - entrepreneur.get().setStatus_snee(status_snee); - } - return entrepreneur.get(); - } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java index 2f7418a..f3a469c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -12,51 +12,51 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class ProjetsController { - @Autowired ProjetsRepository projetsRepository; + @Autowired ProjetsRepository projetsRepository; - @GetMapping("/Projets") - @ResponseBody - public Iterable allProjets() { - return this.projetsRepository.findAll(); - } + @GetMapping("/Projets") + @ResponseBody + public Iterable allProjets() { + return this.projetsRepository.findAll(); + } - @GetMapping("/Projets/{id}") - public Projets getProjetsById(@PathVariable Long id) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + @GetMapping("/Projets/{id}") + public Projets getProjetsById(@PathVariable Long id) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + return projet.get(); } - return projet.get(); - } - @PostMapping("/Projets") - public Projets addProjets(@RequestBody Projets projet) { - return this.projetsRepository.save(projet); - } + @PostMapping("/Projets") + public Projets addProjets(@RequestBody Projets projet) { + return this.projetsRepository.save(projet); + } - @PostMapping("/Projets/{id}") - public Projets updateProjets( - @PathVariable Long id, - String nom_projet, - byte[] logo, - LocalDate date_creation, - String status_projet) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + @PostMapping("/Projets/{id}") + public Projets updateProjets( + @PathVariable Long id, + String nom_projet, + byte[] logo, + LocalDate date_creation, + String status_projet) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + if (nom_projet != null) { + projet.get().setNom_projet(nom_projet); + } + if (logo != null) { + projet.get().setLogo(logo); + } + if (date_creation != null) { + projet.get().setDate_creation(date_creation); + } + if (status_projet != null) { + projet.get().setStatus_projet(status_projet); + } + return projet.get(); } - if (nom_projet != null) { - projet.get().setNom_projet(nom_projet); - } - if (logo != null) { - projet.get().setLogo(logo); - } - if (date_creation != null) { - projet.get().setDate_creation(date_creation); - } - if (status_projet != null) { - projet.get().setStatus_projet(status_projet); - } - return projet.get(); - } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java index 1b05bc4..6f2a39f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -13,55 +13,55 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class RendezVousController { - @Autowired RendezVousRepository rendezVousRepository; + @Autowired RendezVousRepository rendezVousRepository; - @GetMapping("/RendezVous") - @ResponseBody - public Iterable allRendezVous() { - return this.rendezVousRepository.findAll(); - } + @GetMapping("/RendezVous") + @ResponseBody + public Iterable allRendezVous() { + return this.rendezVousRepository.findAll(); + } - @GetMapping("/RendezVous/{id}") - public RendezVous getRendezVousById(@PathVariable Long id) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + @GetMapping("/RendezVous/{id}") + public RendezVous getRendezVousById(@PathVariable Long id) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + return rendezVous.get(); } - return rendezVous.get(); - } - @PostMapping("/RendezVous") - public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { - return this.rendezVousRepository.save(rendezVous); - } + @PostMapping("/RendezVous") + public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { + return this.rendezVousRepository.save(rendezVous); + } - @PostMapping("/RendezVous/{id}") - public RendezVous updateRendezVous( - @PathVariable Long id, - LocalDate date_rdv, - LocalDateTime heure_rdv, - LocalDateTime duree_rdv, - String lieu_rdv, - String sujet_rdv) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + @PostMapping("/RendezVous/{id}") + public RendezVous updateRendezVous( + @PathVariable Long id, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + if (date_rdv != null) { + rendezVous.get().setDate_rdv(date_rdv); + } + if (heure_rdv != null) { + rendezVous.get().setHeure_rdv(heure_rdv); + } + if (duree_rdv != null) { + rendezVous.get().setDuree_rdv(duree_rdv); + } + if (lieu_rdv != null) { + rendezVous.get().setLieu_rdv(lieu_rdv); + } + if (sujet_rdv != null) { + rendezVous.get().setSujet_rdv(sujet_rdv); + } + return rendezVous.get(); } - if (date_rdv != null) { - rendezVous.get().setDate_rdv(date_rdv); - } - if (heure_rdv != null) { - rendezVous.get().setHeure_rdv(heure_rdv); - } - if (duree_rdv != null) { - rendezVous.get().setDuree_rdv(duree_rdv); - } - if (lieu_rdv != null) { - rendezVous.get().setLieu_rdv(lieu_rdv); - } - if (sujet_rdv != null) { - rendezVous.get().setSujet_rdv(sujet_rdv); - } - return rendezVous.get(); - } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java index 487615a..5b4df39 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -12,47 +12,47 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class SectionsController { - @Autowired SectionsRepository sectionsRepository; + @Autowired SectionsRepository sectionsRepository; - @GetMapping("/Sections") - @ResponseBody - public Iterable allSections() { - return this.sectionsRepository.findAll(); - } + @GetMapping("/Sections") + @ResponseBody + public Iterable allSections() { + return this.sectionsRepository.findAll(); + } - @GetMapping("/Sections/{id}") - public Sections getSectionsById(@PathVariable Long id) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + @GetMapping("/Sections/{id}") + public Sections getSectionsById(@PathVariable Long id) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + } + return section.get(); } - return section.get(); - } - @PostMapping("/Sections") - public Sections addSections(@RequestBody Sections sections) { - return this.sectionsRepository.save(sections); - } + @PostMapping("/Sections") + public Sections addSections(@RequestBody Sections sections) { + return this.sectionsRepository.save(sections); + } - @PostMapping("/Sections/{id}") - public Sections updateSections( - @PathVariable Long id, - String titre, - String contenu_section, - LocalDateTime date_modification) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + @PostMapping("/Sections/{id}") + public Sections updateSections( + @PathVariable Long id, + String titre, + String contenu_section, + LocalDateTime date_modification) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + } + if (titre != null) { + section.get().setTitre(titre); + } + if (contenu_section != null) { + section.get().setContenu_section(contenu_section); + } + if (date_modification != null) { + section.get().setDate_modification(date_modification); + } + return section.get(); } - if (titre != null) { - section.get().setTitre(titre); - } - if (contenu_section != null) { - section.get().setContenu_section(contenu_section); - } - if (date_modification != null) { - section.get().setDate_modification(date_modification); - } - return section.get(); - } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java index ee5be49..a6c128d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -11,55 +11,55 @@ import org.springframework.web.server.ResponseStatusException; @RestController public class UtilisateursController { - @Autowired UtilisateursRepository utilisateursRepository; + @Autowired UtilisateursRepository utilisateursRepository; - @GetMapping("/Utilisateurs") - @ResponseBody - public Iterable allUtilisateurs() { - return this.utilisateursRepository.findAll(); - } + @GetMapping("/Utilisateurs") + @ResponseBody + public Iterable allUtilisateurs() { + return this.utilisateursRepository.findAll(); + } - @GetMapping("/Utilisateurs/{id}") - public Utilisateurs getUtilisateursById(@PathVariable Long id) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + @GetMapping("/Utilisateurs/{id}") + public Utilisateurs getUtilisateursById(@PathVariable Long id) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + return utilisateur.get(); } - return utilisateur.get(); - } - @PostMapping("/Utilisateurs") - public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { - return this.utilisateursRepository.save(utilisateurs); - } + @PostMapping("/Utilisateurs") + public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { + return this.utilisateursRepository.save(utilisateurs); + } - @PostMapping("/Utilisateurs/{id}") - public Utilisateurs updateUtilisateurs( - @PathVariable Long id, - String nom_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + @PostMapping("/Utilisateurs/{id}") + public Utilisateurs updateUtilisateurs( + @PathVariable Long id, + String nom_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + if (nom_utilisateur != null) { + utilisateur.get().setNom_utilisateur(nom_utilisateur); + } + if (prenom_utilisateur != null) { + utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); + } + if (mail_principal != null) { + utilisateur.get().setMail_principal(mail_principal); + } + if (mail_secondaire != null) { + utilisateur.get().setMail_secondaire(mail_secondaire); + } + if (numero_telephone != null) { + utilisateur.get().setNumero_telephone(numero_telephone); + } + return utilisateur.get(); } - if (nom_utilisateur != null) { - utilisateur.get().setNom_utilisateur(nom_utilisateur); - } - if (prenom_utilisateur != null) { - utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); - } - if (mail_principal != null) { - utilisateur.get().setMail_principal(mail_principal); - } - if (mail_secondaire != null) { - utilisateur.get().setMail_secondaire(mail_secondaire); - } - if (numero_telephone != null) { - utilisateur.get().setNumero_telephone(numero_telephone); - } - return utilisateur.get(); - } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java index a7390d0..30b70d1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -11,32 +11,32 @@ import java.util.List; @PrimaryKeyJoinColumn(name = "id_administrateur") public class Administrateurs extends Utilisateurs { - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet") - private Projets projetsAdministrateurs; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet") + private Projets projetsAdministrateurs; - @OneToMany(mappedBy = "administrateursSections", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); + @OneToMany(mappedBy = "administrateursSections", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousAdministrateurs; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousAdministrateurs; - public Administrateurs() {} + public Administrateurs() {} - public Administrateurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - super( - nom_utilisateur, - id_utilisateur, - prenom_utilisateur, - mail_principal, - mail_secondaire, - numero_telephone); - } + public Administrateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java index 83871cc..74c97ec 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java @@ -10,37 +10,37 @@ import jakarta.validation.constraints.NotNull; @Table(name = "comptes_rendus") public class ComptesRendus { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_compte_rendu; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_compte_rendu; - private String contenu_compte_rendu; + private String contenu_compte_rendu; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousComptesRendus; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousComptesRendus; - public ComptesRendus() {} + public ComptesRendus() {} - public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - this.contenu_compte_rendu = contenu_compte_rendu; - } + public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + this.contenu_compte_rendu = contenu_compte_rendu; + } - public Long getId_compte_rendu() { - return id_compte_rendu; - } + public Long getId_compte_rendu() { + return id_compte_rendu; + } - public void setId_compte_rendu(Long id_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - } + public void setId_compte_rendu(Long id_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + } - public String getContenu_compte_rendu() { - return contenu_compte_rendu; - } + public String getContenu_compte_rendu() { + return contenu_compte_rendu; + } - public void setContenu_compte_rendu(String contenu_compte_rendu) { - this.contenu_compte_rendu = contenu_compte_rendu; - } + public void setContenu_compte_rendu(String contenu_compte_rendu) { + this.contenu_compte_rendu = contenu_compte_rendu; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java index a353b51..9b696f3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java @@ -9,72 +9,72 @@ import jakarta.persistence.Table; @PrimaryKeyJoinColumn(name = "id_entrepreneur") public class Entrepreneurs extends Utilisateurs { - @Column(length = 255) - private String ecole; + @Column(length = 255) + private String ecole; - @Column(length = 255) - private String filiere; + @Column(length = 255) + private String filiere; - private boolean status_snee; + private boolean status_snee; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet_participation", referencedColumnName = "id_projet") - private Projets projetsParticipation; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet_participation", referencedColumnName = "id_projet") + private Projets projetsParticipation; - // @Column(insertable=false, updatable=false) - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet_propose", referencedColumnName = "id_projet") - private Projets projetsPropose; + // @Column(insertable=false, updatable=false) + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet_propose", referencedColumnName = "id_projet") + private Projets projetsPropose; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousEntrepreneurs; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousEntrepreneurs; - public Entrepreneurs() {} + public Entrepreneurs() {} - public Entrepreneurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone, - String ecole, - boolean status_snee, - String filiere) { - super( - nom_utilisateur, - id_utilisateur, - prenom_utilisateur, - mail_principal, - mail_secondaire, - numero_telephone); - this.ecole = ecole; - this.status_snee = status_snee; - this.filiere = filiere; - } + public Entrepreneurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone, + String ecole, + boolean status_snee, + String filiere) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); + this.ecole = ecole; + this.status_snee = status_snee; + this.filiere = filiere; + } - public String getEcole() { - return ecole; - } + public String getEcole() { + return ecole; + } - public void setEcole(String ecole) { - this.ecole = ecole; - } + public void setEcole(String ecole) { + this.ecole = ecole; + } - public String getFiliere() { - return filiere; - } + public String getFiliere() { + return filiere; + } - public void setFiliere(String filiere) { - this.filiere = filiere; - } + public void setFiliere(String filiere) { + this.filiere = filiere; + } - public boolean isStatus_snee() { - return status_snee; - } + public boolean isStatus_snee() { + return status_snee; + } - public void setStatus_snee(boolean status_snee) { - this.status_snee = status_snee; - } + public void setStatus_snee(boolean status_snee) { + this.status_snee = status_snee; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java index b034432..b49c12f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java @@ -10,88 +10,88 @@ import java.util.List; @Table(name = "projets") public class Projets { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_projet; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_projet; - @Column(length = 255) - private String nom_projet; + @Column(length = 255) + private String nom_projet; - private byte[] logo; + private byte[] logo; - private LocalDate date_creation; + private LocalDate date_creation; - @Column(length = 255) - private String status_projet; + @Column(length = 255) + private String status_projet; - @OneToMany(mappedBy = "projetsAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List listAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "projetsAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List listAdministrateurs = new ArrayList<>(); - @OneToMany(mappedBy = "projetsParticipation", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneursParticipation = new ArrayList<>(); + @OneToMany(mappedBy = "projetsParticipation", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneursParticipation = new ArrayList<>(); - @OneToOne(mappedBy = "projetsPropose", fetch = FetchType.LAZY, orphanRemoval = true) - private Entrepreneurs entrepreneursPropose; + @OneToOne(mappedBy = "projetsPropose", fetch = FetchType.LAZY, orphanRemoval = true) + private Entrepreneurs entrepreneursPropose; - @OneToMany(mappedBy = "projetsSections", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); + @OneToMany(mappedBy = "projetsSections", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); - // Hibernate expects entities to have a no-arg constructor, - // though it does not necessarily have to be public. + // Hibernate expects entities to have a no-arg constructor, + // though it does not necessarily have to be public. - public Projets() {} + public Projets() {} - public Projets( - Long id_projet, - String nom_projet, - byte[] logo, - LocalDate date_creation, - String status_projet) { - this.id_projet = id_projet; - this.nom_projet = nom_projet; - this.logo = logo; - this.date_creation = date_creation; - this.status_projet = status_projet; - } + public Projets( + Long id_projet, + String nom_projet, + byte[] logo, + LocalDate date_creation, + String status_projet) { + this.id_projet = id_projet; + this.nom_projet = nom_projet; + this.logo = logo; + this.date_creation = date_creation; + this.status_projet = status_projet; + } - public Long getId_projet() { - return id_projet; - } + public Long getId_projet() { + return id_projet; + } - public void setId_projet(Long id_projet) { - this.id_projet = id_projet; - } + public void setId_projet(Long id_projet) { + this.id_projet = id_projet; + } - public String getNom_projet() { - return nom_projet; - } + public String getNom_projet() { + return nom_projet; + } - public void setNom_projet(String nom_projet) { - this.nom_projet = nom_projet; - } + public void setNom_projet(String nom_projet) { + this.nom_projet = nom_projet; + } - public byte[] getLogo() { - return logo; - } + public byte[] getLogo() { + return logo; + } - public void setLogo(byte[] logo) { - this.logo = logo; - } + public void setLogo(byte[] logo) { + this.logo = logo; + } - public LocalDate getDate_creation() { - return date_creation; - } + public LocalDate getDate_creation() { + return date_creation; + } - public void setDate_creation(LocalDate date_creation) { - this.date_creation = date_creation; - } + public void setDate_creation(LocalDate date_creation) { + this.date_creation = date_creation; + } - public String getStatus_projet() { - return status_projet; - } + public String getStatus_projet() { + return status_projet; + } - public void setStatus_projet(String status_projet) { - this.status_projet = status_projet; - } + public void setStatus_projet(String status_projet) { + this.status_projet = status_projet; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index bd2f482..e1625e5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -12,102 +12,102 @@ import java.util.List; @Table(name = "rendez_vous") public class RendezVous { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_rdv; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_rdv; - private LocalDate date_rdv; + private LocalDate date_rdv; - private LocalDateTime heure_rdv; + private LocalDateTime heure_rdv; - private LocalDateTime duree_rdv; + private LocalDateTime duree_rdv; - @Column(length = 255) - private String lieu_rdv; + @Column(length = 255) + private String lieu_rdv; - private String sujet_rdv; + private String sujet_rdv; - @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneurs = new ArrayList<>(); - @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListAdministrateurs = new ArrayList<>(); - @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListComptesRendus = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListComptesRendus = new ArrayList<>(); - @ManyToMany( - fetch = FetchType.LAZY, - cascade = {CascadeType.ALL}) - @JoinTable( - name = "concerner", - joinColumns = @JoinColumn(name = "id_rdv"), - inverseJoinColumns = @JoinColumn(name = "id_section")) - List ListSections = new ArrayList<>(); + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.ALL}) + @JoinTable( + name = "concerner", + joinColumns = @JoinColumn(name = "id_rdv"), + inverseJoinColumns = @JoinColumn(name = "id_section")) + List ListSections = new ArrayList<>(); - public RendezVous() {} + public RendezVous() {} - public RendezVous( - Long id_rdv, - LocalDate date_rdv, - LocalDateTime heure_rdv, - LocalDateTime duree_rdv, - String lieu_rdv, - String sujet_rdv) { - this.id_rdv = id_rdv; - this.date_rdv = date_rdv; - this.heure_rdv = heure_rdv; - this.duree_rdv = duree_rdv; - this.lieu_rdv = lieu_rdv; - this.sujet_rdv = sujet_rdv; - } + public RendezVous( + Long id_rdv, + LocalDate date_rdv, + LocalDateTime heure_rdv, + LocalDateTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { + this.id_rdv = id_rdv; + this.date_rdv = date_rdv; + this.heure_rdv = heure_rdv; + this.duree_rdv = duree_rdv; + this.lieu_rdv = lieu_rdv; + this.sujet_rdv = sujet_rdv; + } - public Long getId_rdv() { - return id_rdv; - } + public Long getId_rdv() { + return id_rdv; + } - public void setId_rdv(Long id_rdv) { - this.id_rdv = id_rdv; - } + public void setId_rdv(Long id_rdv) { + this.id_rdv = id_rdv; + } - public LocalDate getDate_rdv() { - return date_rdv; - } + public LocalDate getDate_rdv() { + return date_rdv; + } - public void setDate_rdv(LocalDate date_rdv) { - this.date_rdv = date_rdv; - } + public void setDate_rdv(LocalDate date_rdv) { + this.date_rdv = date_rdv; + } - public LocalDateTime getHeure_rdv() { - return heure_rdv; - } + public LocalDateTime getHeure_rdv() { + return heure_rdv; + } - public void setHeure_rdv(LocalDateTime heure_rdv) { - this.heure_rdv = heure_rdv; - } + public void setHeure_rdv(LocalDateTime heure_rdv) { + this.heure_rdv = heure_rdv; + } - public LocalDateTime getDuree_rdv() { - return duree_rdv; - } + public LocalDateTime getDuree_rdv() { + return duree_rdv; + } - public void setDuree_rdv(LocalDateTime duree_rdv) { - this.duree_rdv = duree_rdv; - } + public void setDuree_rdv(LocalDateTime duree_rdv) { + this.duree_rdv = duree_rdv; + } - public String getLieu_rdv() { - return lieu_rdv; - } + public String getLieu_rdv() { + return lieu_rdv; + } - public void setLieu_rdv(String lieu_rdv) { - this.lieu_rdv = lieu_rdv; - } + public void setLieu_rdv(String lieu_rdv) { + this.lieu_rdv = lieu_rdv; + } - public String getSujet_rdv() { - return sujet_rdv; - } + public String getSujet_rdv() { + return sujet_rdv; + } - public void setSujet_rdv(String sujet_rdv) { - this.sujet_rdv = sujet_rdv; - } + public void setSujet_rdv(String sujet_rdv) { + this.sujet_rdv = sujet_rdv; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java index 299ab3e..6e56fce 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java @@ -11,68 +11,71 @@ import java.util.List; @Table(name = "sections") public class Sections { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_section; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_section; - @Column(length = 255) - private String titre; + @Column(length = 255) + private String titre; - private String contenu_section; + private String contenu_section; - private LocalDateTime date_modification; + private LocalDateTime date_modification; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet") - private Projets projetsSections; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet") + private Projets projetsSections; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_admnistrateur") - private Administrateurs administrateursSections; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_admnistrateur") + private Administrateurs administrateursSections; - @ManyToMany(mappedBy = "ListSections") - private List rendezVous = new ArrayList<>(); + @ManyToMany(mappedBy = "ListSections") + private List rendezVous = new ArrayList<>(); - public Sections() {} + public Sections() {} - public Sections( - Long id_section, String titre, String contenu_section, LocalDateTime date_modification) { - this.id_section = id_section; - this.titre = titre; - this.contenu_section = contenu_section; - this.date_modification = date_modification; - } + public Sections( + Long id_section, + String titre, + String contenu_section, + LocalDateTime date_modification) { + this.id_section = id_section; + this.titre = titre; + this.contenu_section = contenu_section; + this.date_modification = date_modification; + } - public String getTitre() { - return titre; - } + public String getTitre() { + return titre; + } - public void setTitre(String titre) { - this.titre = titre; - } + public void setTitre(String titre) { + this.titre = titre; + } - public Long getId_section() { - return id_section; - } + public Long getId_section() { + return id_section; + } - public void setId_section(Long id_section) { - this.id_section = id_section; - } + public void setId_section(Long id_section) { + this.id_section = id_section; + } - public String getContenu_section() { - return contenu_section; - } + public String getContenu_section() { + return contenu_section; + } - public void setContenu_section(String contenu_section) { - this.contenu_section = contenu_section; - } + public void setContenu_section(String contenu_section) { + this.contenu_section = contenu_section; + } - public LocalDateTime getDate_modification() { - return date_modification; - } + public LocalDateTime getDate_modification() { + return date_modification; + } - public void setDate_modification(LocalDateTime date_modification) { - this.date_modification = date_modification; - } + public void setDate_modification(LocalDateTime date_modification) { + this.date_modification = date_modification; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java index 683ee06..9d81163 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java @@ -8,88 +8,88 @@ import jakarta.validation.constraints.NotNull; @Inheritance(strategy = InheritanceType.JOINED) public class Utilisateurs { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_utilisateur; + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_utilisateur; - @Column(length = 255) - private String nom_utilisateur; + @Column(length = 255) + private String nom_utilisateur; - @Column(length = 255) - private String prenom_utilisateur; + @Column(length = 255) + private String prenom_utilisateur; - @Column(length = 255) - private String mail_principal; + @Column(length = 255) + private String mail_principal; - @Column(length = 255) - private String mail_secondaire; + @Column(length = 255) + private String mail_secondaire; - @Column(length = 15) - private String numero_telephone; + @Column(length = 15) + private String numero_telephone; - public Utilisateurs() {} + public Utilisateurs() {} - public Utilisateurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - this.nom_utilisateur = nom_utilisateur; - this.id_utilisateur = id_utilisateur; - this.prenom_utilisateur = prenom_utilisateur; - this.mail_principal = mail_principal; - this.mail_secondaire = mail_secondaire; - this.numero_telephone = numero_telephone; - } + public Utilisateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + this.nom_utilisateur = nom_utilisateur; + this.id_utilisateur = id_utilisateur; + this.prenom_utilisateur = prenom_utilisateur; + this.mail_principal = mail_principal; + this.mail_secondaire = mail_secondaire; + this.numero_telephone = numero_telephone; + } - public Long getId_utilisateur() { - return id_utilisateur; - } + public Long getId_utilisateur() { + return id_utilisateur; + } - public void setId_utilisateur(Long id_utilisateur) { - this.id_utilisateur = id_utilisateur; - } + public void setId_utilisateur(Long id_utilisateur) { + this.id_utilisateur = id_utilisateur; + } - public String getNom_utilisateur() { - return nom_utilisateur; - } + public String getNom_utilisateur() { + return nom_utilisateur; + } - public void setNom_utilisateur(String nom_utilisateur) { - this.nom_utilisateur = nom_utilisateur; - } + public void setNom_utilisateur(String nom_utilisateur) { + this.nom_utilisateur = nom_utilisateur; + } - public String getPrenom_utilisateur() { - return prenom_utilisateur; - } + public String getPrenom_utilisateur() { + return prenom_utilisateur; + } - public void setPrenom_utilisateur(String prenom_utilisateur) { - this.prenom_utilisateur = prenom_utilisateur; - } + public void setPrenom_utilisateur(String prenom_utilisateur) { + this.prenom_utilisateur = prenom_utilisateur; + } - public String getMail_principal() { - return mail_principal; - } + public String getMail_principal() { + return mail_principal; + } - public void setMail_principal(String mail_principal) { - this.mail_principal = mail_principal; - } + public void setMail_principal(String mail_principal) { + this.mail_principal = mail_principal; + } - public String getMail_secondaire() { - return mail_secondaire; - } + public String getMail_secondaire() { + return mail_secondaire; + } - public void setMail_secondaire(String mail_secondaire) { - this.mail_secondaire = mail_secondaire; - } + public void setMail_secondaire(String mail_secondaire) { + this.mail_secondaire = mail_secondaire; + } - public String getNumero_telephone() { - return numero_telephone; - } + public String getNumero_telephone() { + return numero_telephone; + } - public void setNumero_telephone(String numero_telephone) { - this.numero_telephone = numero_telephone; - } + public void setNumero_telephone(String numero_telephone) { + this.numero_telephone = numero_telephone; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java index c57ea24..b59d2c0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface AdministrateursRepository extends JpaRepository { - /* @Query("SELECT a from Administrateurs a") - Administrateurs findAllAdministrateurs(); */ + /* @Query("SELECT a from Administrateurs a") + Administrateurs findAllAdministrateurs(); */ } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java index 02d2a29..bb09b74 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface EntrepreneursRepository extends JpaRepository { - /* @Query("SELECT e from Entrepreneurs e") - Entrepreneurs findAllEntrepreneurs(); */ + /* @Query("SELECT e from Entrepreneurs e") + Entrepreneurs findAllEntrepreneurs(); */ } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java index 40a14f8..28aca29 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface UtilisateursRepository extends JpaRepository { - /* @Query("SELECT u from Utilisateurs u") - Utilisateurs findAllUtilisateurs(); */ + /* @Query("SELECT u from Utilisateurs u") + Utilisateurs findAllUtilisateurs(); */ } -- 2.47.2 From e6565275c85c055cecf4565436e64b1d7bf2f1ff Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 11:04:49 +0100 Subject: [PATCH 15/97] fix: removed git action push to not destroy our history --- .gitea/workflows/back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 0e74e38..bd6f476 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -14,6 +14,6 @@ jobs: java-version: '21' - uses: axel-op/googlejavaformat-action@v3 with: - args: "--replace --skip-sorting-imports --aosp" + args: "--set-exit-if-changed --skip-sorting-imports --aosp" - name: Print diffs run: git --no-pager diff --exit-code \ No newline at end of file -- 2.47.2 From a8ae5f14d48adf44c71e7c575e73f62d0858131b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 12 Feb 2025 11:09:17 +0100 Subject: [PATCH 16/97] fix: db connection --- MyINPulse-back/src/main/resources/application.properties | 7 ++++--- MyINPulse-back/src/main/resources/data.sql | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index b53191b..e67e4f6 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -2,9 +2,10 @@ spring.application.name=myinpulse spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test logging.level.org.springframework.security=DEBUG -spring.datasource.url=jdbc:postgresql://postgres/${POSTGRES_DB} -spring.datasource.username=${POSTGRES_USER} -spring.datasource.password=${POSTGRES_PASSWORD} +#spring.datasource.url=jdbc:postgresql://postgres/${POSTGRES_DB} +spring.datasource.url=jdbc:postgresql://localhost:5433/backend_db +spring.datasource.username=backend_db_user +spring.datasource.password=backend_db_user_password spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index bd0f49a..4014267 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -4,7 +4,7 @@ INSERT INTO projets (nom_projet, logo, date_creation, status_projet) VALUES ('Débat concours', decode('022024abd5486e245c145dda65116f', 'hex'), TO_DATE('22-NOV-2023', 'DD-MON-YYYY'), 'Suspendu'), ('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), 'Lancement'); -INSERT INTO utilisateurs (nom, prenom, mail_principal, mail_secondaire, numero_telephone) VALUES +INSERT INTO utilisateurs (nom_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone) VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), ('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), -- 2.47.2 From 184642a7507e142809da1b71091d7ce2608a4f69 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 11:32:41 +0100 Subject: [PATCH 17/97] fix: coherent syntax --- MyINPulse-back/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MyINPulse-back/build.gradle b/MyINPulse-back/build.gradle index 5d1c2fd..abb4635 100644 --- a/MyINPulse-back/build.gradle +++ b/MyINPulse-back/build.gradle @@ -21,8 +21,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation('org.springframework.boot:spring-boot-starter-validation') - implementation('org.springframework.boot:spring-boot-starter-data-rest') + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-data-rest' implementation 'org.postgresql:postgresql' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' -- 2.47.2 From e7cb8cf469dc414ca640f9c309cd54c838b3b591 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 11:34:11 +0100 Subject: [PATCH 18/97] feat: single .env file --- Makefile | 22 +++++++++++-------- .../src/main/resources/application.properties | 9 +++----- config/{frontdev.main.env => backdev.env} | 8 +++++++ config/backdev.front.env | 5 ----- config/{backdev.main.env => frontdev.env} | 10 ++++++++- config/frontdev.front.env | 5 ----- config/{prod.main.env => prod.env} | 8 +++++++ config/prod.front.env | 5 ----- 8 files changed, 41 insertions(+), 31 deletions(-) rename config/{frontdev.main.env => backdev.env} (64%) delete mode 100644 config/backdev.front.env rename config/{backdev.main.env => frontdev.env} (56%) delete mode 100644 config/frontdev.front.env rename config/{prod.main.env => prod.env} (61%) delete mode 100644 config/prod.front.env diff --git a/Makefile b/Makefile index 26d5ccb..1e3a808 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ clean: @rm -f docker-compose.yaml @rm -f .env @rm -f front/MyINPulse-front/.env - + @rm -f MyINPulse-back/.env # Install npm packages front/MyINPulse-front/.installed: @@ -18,24 +18,28 @@ vite: ./front/MyINPulse-front/.installed dev-front: clean vite - @cp config/frontdev.front.env front/MyINPulse-front/.env - @cp config/frontdev.main.env .env + @cp config/frontdev.env front/MyINPulse-front/.env + @cp config/frontdev.env .env + @cp config/frontdev.env MyINPulse-back/.env @cp config/frontdev.docker-compose.yaml docker-compose.yaml @docker compose up -d --build @cd ./front/MyINPulse-front/ && npm run dev prod: clean - @cp config/prod.front.env front/MyINPulse-front/.env - @cp config/prod.main.env .env + @cp config/prod.env front/MyINPulse-front/.env + @cp config/prod.env .env + @cp config/prod.env .env @cp config/prod.docker-compose.yaml docker-compose.yaml @docker compose up -d --build dev-back: - @cp config/backdev.front.env front/MyINPulse-front/.env - @cp config/backdev.main.env .env + @cp config/backdev.env front/MyINPulse-front/.env + @cp config/backdev.env .env + @cp config/backdev.env MyINPulse-back/.env @cp config/backdev.docker-compose.yaml docker-compose.yaml @docker compose up -d --build - @echo "cd MyINPulse-back" - @echo "./gradlew bootRun --args='--server.port=8081'" \ No newline at end of file + @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' + @echo "./gradlew bootRun --args='--server.port=8081'" + \ No newline at end of file diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index e67e4f6..cc1afe6 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -2,11 +2,8 @@ spring.application.name=myinpulse spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test logging.level.org.springframework.security=DEBUG -#spring.datasource.url=jdbc:postgresql://postgres/${POSTGRES_DB} -spring.datasource.url=jdbc:postgresql://localhost:5433/backend_db -spring.datasource.username=backend_db_user -spring.datasource.password=backend_db_user_password +spring.datasource.url=jdbc:postgresql://${DATABASE_URL}/${BACKEND_DB} +spring.datasource.username=${BACKEND_USER} +spring.datasource.password=${BACKEND_PASSWORD} spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - -spring.data.rest.base-path=/my/base/path \ No newline at end of file diff --git a/config/frontdev.main.env b/config/backdev.env similarity index 64% rename from config/frontdev.main.env rename to config/backdev.env index 26c2803..a7e5517 100644 --- a/config/frontdev.main.env +++ b/config/backdev.env @@ -12,3 +12,11 @@ KEYCLOAK_PASSWORD=keycloak_db_user_password BACKEND_DB=backend_db BACKEND_USER=backend_db_user BACKEND_PASSWORD=backend_db_user_password + +DATABASE_URL=localhost:5433 + +VITE_KEYCLOAK_URL=http://localhost:7080 +VITE_KEYCLOAK_CLIENT_ID=myinpulse +VITE_KEYCLOAK_REALM=test +VITE_APP_URL=http://localhost:8080 +VITE_BACKEND_URL=http://localhost:8081/ diff --git a/config/backdev.front.env b/config/backdev.front.env deleted file mode 100644 index 27cf54e..0000000 --- a/config/backdev.front.env +++ /dev/null @@ -1,5 +0,0 @@ -VITE_KEYCLOAK_URL=http://localhost:7080 -VITE_KEYCLOAK_CLIENT_ID=myinpulse -VITE_KEYCLOAK_REALM=test -VITE_APP_URL=http://localhost:8080 -VITE_BACKEND_URL=http://localhost:8081/ diff --git a/config/backdev.main.env b/config/frontdev.env similarity index 56% rename from config/backdev.main.env rename to config/frontdev.env index 2a597c3..ed4a23b 100644 --- a/config/backdev.main.env +++ b/config/frontdev.env @@ -11,4 +11,12 @@ KEYCLOAK_PASSWORD=keycloak_db_user_password BACKEND_DB=backend_db BACKEND_USER=backend_db_user -BACKEND_PASSWORD=backend_db_user_password \ No newline at end of file +BACKEND_PASSWORD=backend_db_user_password + +DATABASE_URL=MyINPulse-DB + +VITE_KEYCLOAK_URL=http://localhost:7080 +VITE_KEYCLOAK_CLIENT_ID=myinpulse-dev +VITE_KEYCLOAK_REALM=test +VITE_APP_URL=http://localhost:5173 +VITE_BACKEND_URL=http://localhost:8081/ diff --git a/config/frontdev.front.env b/config/frontdev.front.env deleted file mode 100644 index 5eba221..0000000 --- a/config/frontdev.front.env +++ /dev/null @@ -1,5 +0,0 @@ -VITE_KEYCLOAK_URL=http://localhost:7080 -VITE_KEYCLOAK_CLIENT_ID=myinpulse-dev -VITE_KEYCLOAK_REALM=test -VITE_APP_URL=http://localhost:5173 -VITE_BACKEND_URL=http://localhost:8081/ diff --git a/config/prod.main.env b/config/prod.env similarity index 61% rename from config/prod.main.env rename to config/prod.env index 179d92c..2fb8da9 100644 --- a/config/prod.main.env +++ b/config/prod.env @@ -12,3 +12,11 @@ KEYCLOAK_PASSWORD=keycloak_db_user_password BACKEND_DB=backend_db BACKEND_USER=backend_db_user BACKEND_PASSWORD=backend_db_user_password + +DATABASE_URL=MyINPulse-DB + +VITE_KEYCLOAK_URL=https://0549cd63f912d5dc9b31278d6f.eirb.fr +VITE_KEYCLOAK_CLIENT_ID=myinpulse-eirb +VITE_KEYCLOAK_REALM=test +VITE_APP_URL=https://0549cd63f912d5dc9b31278d6f.piair.dev +VITE_BACKEND_URL=http://TODO/ diff --git a/config/prod.front.env b/config/prod.front.env deleted file mode 100644 index cb42a37..0000000 --- a/config/prod.front.env +++ /dev/null @@ -1,5 +0,0 @@ -VITE_KEYCLOAK_URL=https://0549cd63f912d5dc9b31278d6f.eirb.fr -VITE_KEYCLOAK_CLIENT_ID=myinpulse-eirb -VITE_KEYCLOAK_REALM=test -VITE_APP_URL=https://0549cd63f912d5dc9b31278d6f.piair.dev -VITE_BACKEND_URL=http://TODO/ -- 2.47.2 From 013b97cec0268cbaa7a60f9b23c4f03015c775d7 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 11:34:57 +0100 Subject: [PATCH 19/97] test: check if the action is now red --- .../myinpulse/config/WebSecurityCustomConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index 43a9889..b3525af 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -15,7 +15,7 @@ import java.util.List; import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; @Configuration -public class WebSecurityCustomConfiguration { +public class WebSecurityCustomConfiguration{ // CORS configuration // TODO: make sure to only accept our own domains @Bean -- 2.47.2 From 1ed976b039468cb5ac17a0d73f4893a189f84fa9 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 11:42:16 +0100 Subject: [PATCH 20/97] fix: now only show the incorrect files --- .gitea/workflows/back.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index bd6f476..10718aa 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -14,6 +14,4 @@ jobs: java-version: '21' - uses: axel-op/googlejavaformat-action@v3 with: - args: "--set-exit-if-changed --skip-sorting-imports --aosp" - - name: Print diffs - run: git --no-pager diff --exit-code \ No newline at end of file + args: "--set-exit-if-changed --skip-sorting-imports --aosp -n" -- 2.47.2 From 6e5651c527019ccfbfcd8152fa457a89ff657e59 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 12:04:19 +0100 Subject: [PATCH 21/97] fix: remove dialect to supress a warning --- MyINPulse-back/src/main/resources/application.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index cc1afe6..08dccb9 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -6,4 +6,3 @@ spring.datasource.url=jdbc:postgresql://${DATABASE_URL}/${BACKEND_DB} spring.datasource.username=${BACKEND_USER} spring.datasource.password=${BACKEND_PASSWORD} spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -- 2.47.2 From 07f66f65ed4764ab12b0dacbcac92d6db263c939 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 12:04:59 +0100 Subject: [PATCH 22/97] feat: comments and security comfiguration improved. --- .../WebSecurityCustomConfiguration.java | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index b3525af..637b6c2 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.config; import enseirb.myinpulse.security.KeycloakJwtRolesConverter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -14,37 +15,55 @@ import java.util.List; import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; + @Configuration -public class WebSecurityCustomConfiguration{ +public class WebSecurityCustomConfiguration { // CORS configuration - // TODO: make sure to only accept our own domains + + @Value("${VITE_APP_URL}") + private String frontendUrl; + + /** + * Configure the CORS (Cross Origin Ressource Sharing -- a security feature) configuration. + * The only allowed website is the frontend, defined in the .env file. + * + * @return the CORS configuration used by the backend + */ @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(List.of("*")); + configuration.setAllowedOrigins(List.of(frontendUrl)); configuration.setAllowedMethods(Arrays.asList("GET", "OPTIONS")); configuration.setAllowedHeaders( Arrays.asList( "authorization", "content-type", - "x-auth-token")); // Do not remove, this fixes the CORS errors when - // unauthenticated + "x-auth-token")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; } + /** + * Configure the authorisation required for each path. + * admin endpoints are under /admin/* and entrepreneur are under /entrepreneur/* + * If endpoints dont require authentication, they are under /unauth/ + * + * @param http automatically filled in by spring. + * @return a securityfilterchain, automatically used by spring. + * @throws Exception TODO: figure out when the exception are raised + */ @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests( authorize -> authorize - .requestMatchers("/random2") + .requestMatchers("/entrepreneur/**") .access(hasRole("REALM_MyINPulse-entrepreneur")) - .requestMatchers("/random") + .requestMatchers("/admin/**") .access(hasRole("REALM_MyINPulse-admin")) - .requestMatchers("/random3") + .requestMatchers("/unauth/**") .permitAll() .anyRequest() .authenticated()) -- 2.47.2 From 43aadac5031bdbc95479099992142dae9d65c1d1 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 12:23:04 +0100 Subject: [PATCH 23/97] feat: reflected changes of path change --- .../enseirb/myinpulse/api/GetUserInfo.java | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java index 63aef48..ad008f0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java @@ -1,43 +1,24 @@ package enseirb.myinpulse.api; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.CrossOrigin; - -import java.security.Principal; @SpringBootApplication @RestController public class GetUserInfo { - // TODO: understand how to get data - @GetMapping("/getUserInfo") - public Object user(Principal principal) { - System.out.println("GetUserInfo + " + principal); - System.out.println(SecurityContextHolder.getContext().getAuthentication()); - return SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - } - - @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) - @GetMapping("/random") + @GetMapping("/unauth/random") public boolean rand() { - System.err.println("HELLO"); return Math.random() > 0.5; } - @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) - @GetMapping("/random2") + @GetMapping("/admin/random") public boolean rand2() { - System.err.println("HELLO2"); return Math.random() > 0.5; } - @CrossOrigin(methods = {RequestMethod.GET, RequestMethod.OPTIONS}) - @GetMapping("/random3") + @GetMapping("/entrepreneur/random") public boolean rand3() { - System.err.println("HELLO"); return Math.random() > 0.5; } } -- 2.47.2 From 525f98a05480d7e2839819be55445e63a2b60617 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 12:23:53 +0100 Subject: [PATCH 24/97] feat: new makefile option --- Makefile | 16 +++++++++-- config/dev.docker-compose.yaml | 52 ++++++++++++++++++++++++++++++++++ config/dev.env | 22 ++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 config/dev.docker-compose.yaml create mode 100644 config/dev.env diff --git a/Makefile b/Makefile index 1e3a808..617387b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ help: - @echo "make [clean dev-front prod dev-back]" + @echo "make [clean dev-front prod dev-back dev]" clean: + @cp config/frontdev.env front/MyINPulse-front/.env + @cp config/frontdev.env .env + @cp config/frontdev.env MyINPulse-back/.env @cp config/prod.docker-compose.yaml docker-compose.yaml @docker compose down @rm -f docker-compose.yaml @@ -42,4 +45,13 @@ dev-back: @docker compose up -d --build @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' @echo "./gradlew bootRun --args='--server.port=8081'" - \ No newline at end of file + +dev: clean vite + @cp config/dev.env front/MyINPulse-front/.env + @cp config/dev.env .env + @cp config/dev.env MyINPulse-back/.env + @cp config/dev.docker-compose.yaml docker-compose.yaml + @docker compose up -d --build + @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' + @echo "./gradlew bootRun --args='--server.port=8081'" + @cd ./front/MyINPulse-front/ && npm run dev & diff --git a/config/dev.docker-compose.yaml b/config/dev.docker-compose.yaml new file mode 100644 index 0000000..d66d92a --- /dev/null +++ b/config/dev.docker-compose.yaml @@ -0,0 +1,52 @@ +services: + postgres: + env_file: .env + build: + context: postgres/ + dockerfile: Dockerfile + container_name: MyINPulse-DB + ports: + - 5433:5432 + volumes: + - ./postgres/data:/var/lib/postgresql/data + + + keycloak: + container_name: MyINPulse-keycloak + build: + context: ./keycloak + dockerfile: Dockerfile + args: + KC_DB: postgres + KC_DB_URL: jdbc:postgresql://postgres/${POSTGRES_DB} + KC_DB_USERNAME: ${POSTGRES_USER} + KC_DB_PASSWORD: ${POSTGRES_PASSWORD} + environment: + KC_HOSTNAME_PORT: 7080 + KC_HOSTNAME_STRICT_BACKCHANNEL: "true" + KC_BOOTSTRAP_ADMIN_USERNAME: ${KEYCLOAK_ADMIN} + KC_BOOTSTRAP_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD} + KC_LOG_LEVEL: info + command: ["start-dev", "--http-port", "7080", "--https-port", "7443", "--hostname", "${KEYCLOAK_HOSTNAME}"] + ports: + - "7080:7080" + - "7443:7443" + depends_on: + - postgres + + #front: + # build: + # context: ./front/ + # dockerfile: Dockerfile + # container_name: MyINPulse-front + # ports: + # - "8080:80" + + #back: + # build: + # context: ./MyINPulse-back/ + # dockerfile: Dockerfile + # container_name: MyINPulse-back + # ports: + # - "8081:8080" + \ No newline at end of file diff --git a/config/dev.env b/config/dev.env new file mode 100644 index 0000000..bcd45f3 --- /dev/null +++ b/config/dev.env @@ -0,0 +1,22 @@ +POSTGRES_DB=postgres_db +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres_db_user_password + +KEYCLOAK_ADMIN=admin +KEYCLOAK_ADMIN_PASSWORD=admin +KEYCLOAK_HOSTNAME=localhost +KEYCLOAK_DB=keycloak_db +KEYCLOAK_USER=keycloak_db_user +KEYCLOAK_PASSWORD=keycloak_db_user_password + +BACKEND_DB=backend_db +BACKEND_USER=backend_db_user +BACKEND_PASSWORD=backend_db_user_password + +DATABASE_URL=localhost:5433 + +VITE_KEYCLOAK_URL=http://localhost:7080 +VITE_KEYCLOAK_CLIENT_ID=myinpulse-dev +VITE_KEYCLOAK_REALM=test +VITE_APP_URL=http://localhost:5173 +VITE_BACKEND_URL=http://localhost:8081/ -- 2.47.2 From d77f38b405f78df57b4af909dcade88ac79da487 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 12:24:15 +0100 Subject: [PATCH 25/97] fix: removed exposed ports on the frontend --- config/prod.docker-compose.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/prod.docker-compose.yaml b/config/prod.docker-compose.yaml index 51f2d76..496efb3 100644 --- a/config/prod.docker-compose.yaml +++ b/config/prod.docker-compose.yaml @@ -30,10 +30,10 @@ services: KC_BOOTSTRAP_ADMIN_USERNAME: ${KEYCLOAK_ADMIN} KC_BOOTSTRAP_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD} KC_LOG_LEVEL: info - command: ["start-dev", "--http-port", "7080", "--https-port", "7443", "--hostname", "${KEYCLOAK_HOSTNAME}"] - ports: - - "7080:7080" - - "7443:7443" + command: ["start-dev", "--http-port", "7080", "--https-port", "7443", "--hostname", "${KEYCLOAK_HOSTNAME}"] # TODO: remove start-dev + #ports: + # - "7080:7080" + # - "7443:7443" depends_on: - postgres @@ -50,6 +50,6 @@ services: context: ./MyINPulse-back/ dockerfile: Dockerfile container_name: MyINPulse-back - ports: - - "8081:8080" + #ports: + # - "8081:8080" \ No newline at end of file -- 2.47.2 From 208cbbfa1d59b9b8dbc80a232cef92e4a5552d4e Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 14:51:37 +0100 Subject: [PATCH 26/97] feat: now uses intellij --- .gitea/workflows/back.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 10718aa..ee533f9 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -12,6 +12,7 @@ jobs: with: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - - uses: axel-op/googlejavaformat-action@v3 + - uses: findologic/intellij-format-action@v1.1.0 with: - args: "--set-exit-if-changed --skip-sorting-imports --aosp -n" + include-glob: '*.kt,*.java' + path: . -- 2.47.2 From b00c28a02ac589f749cf33e4c68322fb06413697 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 14:54:27 +0100 Subject: [PATCH 27/97] fix: now uses the correct version --- .gitea/workflows/back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index ee533f9..5211e51 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -12,7 +12,7 @@ jobs: with: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - - uses: findologic/intellij-format-action@v1.1.0 + - uses: findologic/intellij-format-action@v1.0.1 with: include-glob: '*.kt,*.java' path: . -- 2.47.2 From dacb0dd179974c8c28db4d7bd5913e708bdf6a35 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 14:56:09 +0100 Subject: [PATCH 28/97] fix: now uses another library --- .gitea/workflows/back.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 5211e51..e8d3617 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -12,7 +12,10 @@ jobs: with: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - - uses: findologic/intellij-format-action@v1.0.1 + - name: Check IntelliJ Formatting + uses: sidhant92/intellij-format-action@v1 with: - include-glob: '*.kt,*.java' - path: . + tool_name: 'IntelliJ Diff' + fail_on_changes: true + path: './MyINPulse-back/' + file_mask: '*.java' -- 2.47.2 From c739b4d26d669c0e1df353fb3e792dc98f2467bb Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:07:36 +0100 Subject: [PATCH 29/97] test: syntax validataion --- .gitea/workflows/back.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index e8d3617..80b451a 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -13,9 +13,8 @@ jobs: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - name: Check IntelliJ Formatting - uses: sidhant92/intellij-format-action@v1 + uses: findologic/intellij-format-action with: - tool_name: 'IntelliJ Diff' - fail_on_changes: true - path: './MyINPulse-back/' - file_mask: '*.java' + include-glob: '*.kt,*.java' + path: . + fail-on-changes: true -- 2.47.2 From db094a8d86d173e300bf6317267af40ac1b40081 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:09:42 +0100 Subject: [PATCH 30/97] test: syntax validataion --- .gitea/workflows/back.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 80b451a..2d6b648 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -13,8 +13,6 @@ jobs: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - name: Check IntelliJ Formatting - uses: findologic/intellij-format-action - with: - include-glob: '*.kt,*.java' - path: . - fail-on-changes: true + - uses: joutvhu/intellij-format@v1 + with: + verify: true \ No newline at end of file -- 2.47.2 From 6befd10735550b7a2ff9488de3d22fad26b117d7 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:10:59 +0100 Subject: [PATCH 31/97] test: syntax validation --- .gitea/workflows/back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 2d6b648..bf333ae 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -12,7 +12,7 @@ jobs: with: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - - name: Check IntelliJ Formatting + - uses: joutvhu/intellij-format@v1 with: verify: true \ No newline at end of file -- 2.47.2 From 8b24456b487a2725e1ce66f5fa4069e2a07a44b1 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:14:48 +0100 Subject: [PATCH 32/97] feat: back to google as I can't make the other one work --- .gitea/workflows/back.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index bf333ae..31aa219 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -13,6 +13,6 @@ jobs: distribution: 'temurin' # See 'Supported distributions' for available options java-version: '21' - - uses: joutvhu/intellij-format@v1 - with: - verify: true \ No newline at end of file + - uses: axel-op/googlejavaformat-action@v3 + with: + args: "--set-exit-if-changed --skip-sorting-imports --aosp -n" \ No newline at end of file -- 2.47.2 From 746fa97cf3148038b62abb3e218a521281613592 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:29:12 +0100 Subject: [PATCH 33/97] fix: applied formatter (on all import as well :) --- .../WebSecurityCustomConfiguration.java | 21 ++- .../controller/AdministrateursController.java | 4 +- .../controller/ComptesRendusController.java | 4 +- .../controller/EntrepreneursController.java | 4 +- .../controller/ProjetsController.java | 6 +- .../controller/RendezVousController.java | 8 +- .../controller/SectionsController.java | 6 +- .../controller/UtilisateursController.java | 4 +- .../postgres_db/model/Administrateurs.java | 1 + .../myinpulse/postgres_db/model/Projets.java | 1 + .../postgres_db/model/RendezVous.java | 41 ++--- .../repository/AdministrateursRepository.java | 1 + .../repository/ComptesRendusRepository.java | 1 + .../repository/EntrepreneursRepository.java | 1 + .../repository/ProjetsRepository.java | 1 + .../repository/RendezVousRepository.java | 1 + .../repository/SectionsRepository.java | 1 + .../repository/UtilisateursRepository.java | 1 + .../security/KeycloakJwtRolesConverter.java | 4 +- MyINPulse-back/src/main/resources/data.sql | 96 +++++++----- MyINPulse-back/src/main/resources/schema.sql | 148 ++++++++++-------- 21 files changed, 197 insertions(+), 158 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index 637b6c2..b8f0e4f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -1,6 +1,9 @@ package enseirb.myinpulse.config; +import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; + import enseirb.myinpulse.security.KeycloakJwtRolesConverter; + import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,9 +16,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import java.util.Arrays; import java.util.List; -import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; - - @Configuration public class WebSecurityCustomConfiguration { // CORS configuration @@ -24,8 +24,8 @@ public class WebSecurityCustomConfiguration { private String frontendUrl; /** - * Configure the CORS (Cross Origin Ressource Sharing -- a security feature) configuration. - * The only allowed website is the frontend, defined in the .env file. + * Configure the CORS (Cross Origin Ressource Sharing -- a security feature) configuration. The + * only allowed website is the frontend, defined in the .env file. * * @return the CORS configuration used by the backend */ @@ -35,10 +35,7 @@ public class WebSecurityCustomConfiguration { configuration.setAllowedOrigins(List.of(frontendUrl)); configuration.setAllowedMethods(Arrays.asList("GET", "OPTIONS")); configuration.setAllowedHeaders( - Arrays.asList( - "authorization", - "content-type", - "x-auth-token")); + Arrays.asList("authorization", "content-type", "x-auth-token")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); @@ -47,8 +44,10 @@ public class WebSecurityCustomConfiguration { /** * Configure the authorisation required for each path. - * admin endpoints are under /admin/* and entrepreneur are under /entrepreneur/* - * If endpoints dont require authentication, they are under /unauth/ + * + *

admin endpoints are under /admin/* and entrepreneur are under /entrepreneur/* + * + *

If endpoints dont require authentication, they are under /unauth/ * * @param http automatically filled in by spring. * @return a securityfilterchain, automatically used by spring. diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java index 2a5d05e..b9a8259 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java @@ -2,12 +2,14 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.Administrateurs; import enseirb.myinpulse.postgres_db.repository.AdministrateursRepository; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.util.Optional; + @RestController public class AdministrateursController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index 312ae9e..5d35227 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -2,12 +2,14 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.ComptesRendus; import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.util.Optional; + @RestController public class ComptesRendusController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java index f789e0d..3124257 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -2,12 +2,14 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.Entrepreneurs; import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.util.Optional; + @RestController public class EntrepreneursController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java index f3a469c..62dfce2 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -2,13 +2,15 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.Projets; import enseirb.myinpulse.postgres_db.repository.ProjetsRepository; -import java.time.LocalDate; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.time.LocalDate; +import java.util.Optional; + @RestController public class ProjetsController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java index 6f2a39f..027b394 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -2,14 +2,16 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.RendezVous; import enseirb.myinpulse.postgres_db.repository.RendezVousRepository; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Optional; + @RestController public class RendezVousController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java index 5b4df39..7aaf15f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -2,13 +2,15 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.Sections; import enseirb.myinpulse.postgres_db.repository.SectionsRepository; -import java.time.LocalDateTime; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.time.LocalDateTime; +import java.util.Optional; + @RestController public class SectionsController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java index a6c128d..c6c8878 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -2,12 +2,14 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.Utilisateurs; import enseirb.myinpulse.postgres_db.repository.UtilisateursRepository; -import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; +import java.util.Optional; + @RestController public class UtilisateursController { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java index 30b70d1..ac42bdb 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -3,6 +3,7 @@ package enseirb.myinpulse.postgres_db.model; import jakarta.persistence.*; import jakarta.persistence.PrimaryKeyJoinColumn; import jakarta.persistence.Table; + import java.util.ArrayList; import java.util.List; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java index b49c12f..e543549 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java @@ -2,6 +2,7 @@ package enseirb.myinpulse.postgres_db.model; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; + import java.time.LocalDate; import java.util.ArrayList; import java.util.List; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index e1625e5..b1cc5a2 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -12,31 +12,6 @@ import java.util.List; @Table(name = "rendez_vous") public class RendezVous { - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_rdv; - - private LocalDate date_rdv; - - private LocalDateTime heure_rdv; - - private LocalDateTime duree_rdv; - - @Column(length = 255) - private String lieu_rdv; - - private String sujet_rdv; - - @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneurs = new ArrayList<>(); - - @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListAdministrateurs = new ArrayList<>(); - - @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListComptesRendus = new ArrayList<>(); - @ManyToMany( fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @@ -45,6 +20,22 @@ public class RendezVous { joinColumns = @JoinColumn(name = "id_rdv"), inverseJoinColumns = @JoinColumn(name = "id_section")) List ListSections = new ArrayList<>(); + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_rdv; + private LocalDate date_rdv; + private LocalDateTime heure_rdv; + private LocalDateTime duree_rdv; + @Column(length = 255) + private String lieu_rdv; + private String sujet_rdv; + @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListComptesRendus = new ArrayList<>(); public RendezVous() {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java index b59d2c0..0454e64 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.Administrateurs; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java index e4de376..168fd87 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.ComptesRendus; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java index bb09b74..fc288f5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.Entrepreneurs; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java index 37f5d8e..d9d2e59 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.Projets; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java index 93074f8..2856de3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.RendezVous; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java index cc25ab1..4d68027 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.Sections; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java index 28aca29..de8371c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.postgres_db.repository; import enseirb.myinpulse.postgres_db.model.Utilisateurs; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java index dba41cc..c73b82a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java @@ -1,5 +1,7 @@ package enseirb.myinpulse.security; +import static java.util.stream.Collectors.toSet; + import org.springframework.core.convert.converter.Converter; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; @@ -14,8 +16,6 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.stream.Collectors.toSet; - public class KeycloakJwtRolesConverter implements Converter { /** Prefix used for realm level roles. */ public static final String PREFIX_REALM_ROLE = "ROLE_REALM_"; diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index 4014267..788f9dd 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -1,50 +1,62 @@ -INSERT INTO projets (nom_projet, logo, date_creation, status_projet) VALUES -('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_DATE('01-OCT-2023', 'DD-MON-YYYY'), 'En cours'), -('Air oxygéné', decode('150647a0984e8f228cd14b54', 'hex'), TO_DATE('04-APR-2024', 'DD-MON-YYYY'), 'En cours'), -('Débat concours', decode('022024abd5486e245c145dda65116f', 'hex'), TO_DATE('22-NOV-2023', 'DD-MON-YYYY'), 'Suspendu'), -('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), 'Lancement'); +INSERT INTO projets (nom_projet, logo, date_creation, status_projet) +VALUES ('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_DATE('01-OCT-2023', 'DD-MON-YYYY'), + 'En cours'), + ('Air oxygéné', decode('150647a0984e8f228cd14b54', 'hex'), TO_DATE('04-APR-2024', 'DD-MON-YYYY'), 'En cours'), + ('Débat concours', decode('022024abd5486e245c145dda65116f', 'hex'), TO_DATE('22-NOV-2023', 'DD-MON-YYYY'), + 'Suspendu'), + ('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), + 'Lancement'); -INSERT INTO utilisateurs (nom_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone) VALUES -('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), -('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), -('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), -('Leguez', 'Theo', 'bof@mesmails.fr', 'bof2@mesmails.fr', '+33 6 78 14 25 29'), -('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'); +INSERT INTO utilisateurs (nom_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone) +VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), + ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), + ('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), + ('Leguez', 'Theo', 'bof@mesmails.fr', 'bof2@mesmails.fr', '+33 6 78 14 25 29'), + ('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'); -INSERT INTO entrepreneurs (ecole, filiere, status_snee) VALUES -('ENSEIRB-MATMECA', 'INFO', TRUE), -('ENSC', 'Cognitique', TRUE), -('ENSEIRB-MATMECA', 'MATMECA', FALSE), -('SupOptique', 'Classique', TRUE), -('ENSEGID', 'Géoscience', FALSE), -('ENSMAC', 'Matériaux composites - Mécanique', FALSE); +INSERT INTO entrepreneurs (ecole, filiere, status_snee) +VALUES ('ENSEIRB-MATMECA', 'INFO', TRUE), + ('ENSC', 'Cognitique', TRUE), + ('ENSEIRB-MATMECA', 'MATMECA', FALSE), + ('SupOptique', 'Classique', TRUE), + ('ENSEGID', 'Géoscience', FALSE), + ('ENSMAC', 'Matériaux composites - Mécanique', FALSE); -INSERT INTO sections (titre, contenu_section, date_modification) VALUES -("Problème", "les problèmes...", TO_DATE('15-JAN-2025', 'DD-MON-YYYY')), -("Segment de client", "Le segment AB passant le client n°8 est de longueur 32mm. - Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?", TO_DATE('12-OCT-2022', 'DD-MON-YYYY')), -("Proposition de valeur unique", "'Son prix est de 2594€' 'Ah oui c'est unique en effet'", TO_DATE('25-MAY-2024', 'DD-MON-YYYY')), -("Solution", "Un problème ? Une solution", TO_DATE('08-FEB-2024', 'DD-MON-YYYY')), -("Canaux", "Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez", TO_DATE('19-JUL-2023', 'DD-MON-YYYY')), -("Sources de revenus", "Y'en n'a pas on est pas payé. Enfin y'a du café quoi", TO_DATE('12-JAN-2025', 'DD-MON-YYYY')), -("Structure des coûts", "'Ah oui là ça va faire au moins 1000€ par mois', Eirbware", TO_DATE('06-FEB-2025', 'DD-MON-YYYY')), -("Indicateurs clés", "On apprend les clés comme des badges, ça se fait", TO_DATE('05-FEB-2025', 'DD-MON-YYYY')), -("Avantages concurrentiel", "On est meilleur", TO_DATE('23-APR-2024', 'DD-MON-YYYY')); +INSERT INTO sections (titre, contenu_section, date_modification) +VALUES ("Problème", "les problèmes...", TO_DATE('15-JAN-2025', 'DD-MON-YYYY')), + ("Segment de client", "Le segment AB passant le client n°8 est de longueur 32mm. + Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?", + TO_DATE('12-OCT-2022', 'DD-MON-YYYY')), + ("Proposition de valeur unique", "'Son prix est de 2594€' 'Ah oui c'est unique en effet'", + TO_DATE('25-MAY-2024', 'DD-MON-YYYY')), + ("Solution", "Un problème ? Une solution", TO_DATE('08-FEB-2024', 'DD-MON-YYYY')), + ("Canaux", "Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez", + TO_DATE('19-JUL-2023', 'DD-MON-YYYY')), + ("Sources de revenus", "Y'en n'a pas on est pas payé. Enfin y'a du café quoi", + TO_DATE('12-JAN-2025', 'DD-MON-YYYY')), + ("Structure des coûts", "'Ah oui là ça va faire au moins 1000€ par mois', Eirbware", + TO_DATE('06-FEB-2025', 'DD-MON-YYYY')), + ("Indicateurs clés", "On apprend les clés comme des badges, ça se fait", TO_DATE('05-FEB-2025', 'DD-MON-YYYY')), + ("Avantages concurrentiel", "On est meilleur", TO_DATE('23-APR-2024', 'DD-MON-YYYY')); -INSERT INTO rendez_vous (date_rdv, heure_rdv, duree_rdv, lieu_rdv, sujet_rdv) VALUES -(TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', "À la maison", "Ouvrir les cadeaux"), -(TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', "Sur les quais ou dans un champ probablement", "BOUM BOUM les feux d'artifices (on fête quoi déjà ?)"), -(TO_DATE('29-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', "Salle TD 15", "Ah mince c'est pas une année bissextile !"), -(TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', "Là où le vent nous porte", "Journée la plus importante de l'année"), -(TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', "Euh c'est par où l'amphi 56 ?", "Rentrée scolaire (il fait trop froid c'est quoi ça on est en août)"); +INSERT INTO rendez_vous (date_rdv, heure_rdv, duree_rdv, lieu_rdv, sujet_rdv) +VALUES (TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', "À la maison", "Ouvrir les cadeaux"), + (TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', "Sur les quais ou dans un champ probablement", + "BOUM BOUM les feux d'artifices (on fête quoi déjà ?)"), + (TO_DATE('29-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', "Salle TD 15", + "Ah mince c'est pas une année bissextile !"), + (TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', "Là où le vent nous porte", + "Journée la plus importante de l'année"), + (TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', "Euh c'est par où l'amphi 56 ?", + "Rentrée scolaire (il fait trop froid c'est quoi ça on est en août)"); -INSERT INTO comptes_rendus (contenu_compte_rendu) VALUES -("Ah oui ça c'est super, ah ouais j'aime bien, bien vu de penser à ça"), -("Bonne réunion"), -("Ouais, j'ai rien compris mais niquel on fait comme vous avez dit"), -("Non non ça va pas du tout ce que tu me proposes, faut tout refaire"), -("Réponse de la DSI : non"), -("Trop dommage qu'Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence"); +INSERT INTO comptes_rendus (contenu_compte_rendu) +VALUES ("Ah oui ça c'est super, ah ouais j'aime bien, bien vu de penser à ça"), + ("Bonne réunion"), + ("Ouais, j'ai rien compris mais niquel on fait comme vous avez dit"), + ("Non non ça va pas du tout ce que tu me proposes, faut tout refaire"), + ("Réponse de la DSI : non"), + ("Trop dommage qu'Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence"); diff --git a/MyINPulse-back/src/main/resources/schema.sql b/MyINPulse-back/src/main/resources/schema.sql index 4916414..9ad3241 100644 --- a/MyINPulse-back/src/main/resources/schema.sql +++ b/MyINPulse-back/src/main/resources/schema.sql @@ -10,106 +10,120 @@ DROP TABLE IF EXISTS formes CASCADE; CREATE TABLE projets ( -id_projet SERIAL NOT NULL, -nom_projet VARCHAR(255) , -logo BYTEA , -date_creation DATE , -status_projet VARCHAR(255) , -CONSTRAINT pk_projet PRIMARY KEY (id_projet) ); + id_projet SERIAL NOT NULL, + nom_projet VARCHAR(255), + logo BYTEA, + date_creation DATE, + status_projet VARCHAR(255), + CONSTRAINT pk_projet PRIMARY KEY (id_projet) +); CREATE TABLE utilisateurs ( -id_utilisateur SERIAL NOT NULL, -nom_utilisateur VARCHAR(255) , -prenom_utilisateur VARCHAR(255) , -mail_principal VARCHAR(255) , -mail_secondaire VARCHAR(255) , -numero_telephone VARCHAR(15) , -CONSTRAINT pk_utilisateur PRIMARY KEY (id_utilisateur) ); + id_utilisateur SERIAL NOT NULL, + nom_utilisateur VARCHAR(255), + prenom_utilisateur VARCHAR(255), + mail_principal VARCHAR(255), + mail_secondaire VARCHAR(255), + numero_telephone VARCHAR(15), + CONSTRAINT pk_utilisateur PRIMARY KEY (id_utilisateur) +); CREATE TABLE entrepreneurs ( -id_entrepreneur SERIAL REFERENCES utilisateurs (id_utilisateur), -ecole VARCHAR(255) , -filiere VARCHAR(255) , -status_snee BOOLEAN , -CONSTRAINT pk_entrepreneur PRIMARY KEY (id_entrepreneur) ); + id_entrepreneur SERIAL REFERENCES utilisateurs (id_utilisateur), + ecole VARCHAR(255), + filiere VARCHAR(255), + status_snee BOOLEAN, + CONSTRAINT pk_entrepreneur PRIMARY KEY (id_entrepreneur) +); CREATE TABLE administrateurs -( -id_administrateur SERIAL REFERENCES utilisateurs (id_utilisateur), -CONSTRAINT pk_administrateur PRIMARY KEY (id_administrateur) ); +( + id_administrateur SERIAL REFERENCES utilisateurs (id_utilisateur), + CONSTRAINT pk_administrateur PRIMARY KEY (id_administrateur) +); CREATE TABLE sections ( -id_section SERIAL NOT NULL, -titre VARCHAR(255) , -contenu_section TEXT , -date_modification TIMESTAMP , -CONSTRAINT pk_section PRIMARY KEY (id_section) ); + id_section SERIAL NOT NULL, + titre VARCHAR(255), + contenu_section TEXT, + date_modification TIMESTAMP, + CONSTRAINT pk_section PRIMARY KEY (id_section) +); CREATE TABLE rendez_vous ( -id_rdv SERIAL NOT NULL, -date_rdv DATE , -heure_rdv TIME , -duree_rdv TIME , -lieu_rdv VARCHAR(255) , -sujet_rdv TEXT , -CONSTRAINT pk_rdv PRIMARY KEY (id_rdv) ); + id_rdv SERIAL NOT NULL, + date_rdv DATE, + heure_rdv TIME, + duree_rdv TIME, + lieu_rdv VARCHAR(255), + sujet_rdv TEXT, + CONSTRAINT pk_rdv PRIMARY KEY (id_rdv) +); -CREATE TABLE comptes_rendus +CREATE TABLE comptes_rendus ( -id_compte_rendu SERIAL NOT NULL, -contenu_compte_rendu TEXT , -CONSTRAINT pk_compte_rendu PRIMARY KEY (id_compte_rendu) ); + id_compte_rendu SERIAL NOT NULL, + contenu_compte_rendu TEXT, + CONSTRAINT pk_compte_rendu PRIMARY KEY (id_compte_rendu) +); CREATE TABLE concerner ( -id_section SERIAL REFERENCES sections (id_section), -id_rdv SERIAL REFERENCES sections (id_rdv), -CONSTRAINT pk_concerner PRIMARY KEY (id_section, id_rdv) ); + id_section SERIAL REFERENCES sections (id_section), + id_rdv SERIAL REFERENCES sections (id_rdv), + CONSTRAINT pk_concerner PRIMARY KEY (id_section, id_rdv) +); ALTER TABLE projets - ADD CONSTRAINT fk1_projet FOREIGN KEY (id_administrateur) - REFERENCES administrateurs (id_administrateur) - ON DELETE CASCADE; + ADD CONSTRAINT fk1_projet FOREIGN KEY (id_administrateur) + REFERENCES administrateurs (id_administrateur) + ON DELETE CASCADE; ALTER TABLE projets ADD CONSTRAINT fk2_projet FOREIGN KEY (id_entrepreneur_participation) REFERENCES entrepreneurs (id_entrepreneur) ON DELETE CASCADE; -ALTER TABLE entrepreneurs - ADD CONSTRAINT fk1_entrepreneur FOREIGN KEY (id_projet_propose) - REFERENCES projets (id_projet) - ON DELETE CASCADE; +ALTER TABLE entrepreneurs + ADD CONSTRAINT fk1_entrepreneur FOREIGN KEY (id_projet_propose) + REFERENCES projets (id_projet) + ON DELETE CASCADE; -ALTER TABLE sections - ADD CONSTRAINT fk1_section FOREIGN KEY (id_projet) - REFERENCES projets (id_projet) - ON DELETE CASCADE; +ALTER TABLE sections + ADD CONSTRAINT fk1_section FOREIGN KEY (id_projet) + REFERENCES projets (id_projet) + ON DELETE CASCADE; -ALTER TABLE sections - ADD CONSTRAINT fk2_section FOREIGN KEY (id_administrateur) - REFERENCES administrateurs (id_administrateur) - ON DELETE CASCADE; +ALTER TABLE sections + ADD CONSTRAINT fk2_section FOREIGN KEY (id_administrateur) + REFERENCES administrateurs (id_administrateur) + ON DELETE CASCADE; -ALTER TABLE rendez-vous - ADD CONSTRAINT fk1_rdv FOREIGN KEY (id_entrepreneur) - REFERENCES entrepreneurs (id_entrepreneur) - ON DELETE CASCADE; +ALTER TABLE rendez-vous + ADD CONSTRAINT fk1_rdv FOREIGN KEY (id_entrepreneur) + REFERENCES entrepreneurs (id_entrepreneur) + ON +DELETE +CASCADE; -ALTER TABLE rendez-vous - ADD CONSTRAINT fk2_rdv FOREIGN KEY (id_administrateur) - REFERENCES administrateurs (id_administrateur) - ON DELETE CASCADE; +ALTER TABLE rendez-vous + ADD CONSTRAINT fk2_rdv FOREIGN KEY (id_administrateur) + REFERENCES administrateurs (id_administrateur) + ON +DELETE +CASCADE; -ALTER TABLE comptes-rendus - ADD CONSTRAINT fk1_compte_rendu FOREIGN KEY (id_rdv) - REFERENCES rendez_vous (id_rdv) - ON DELETE CASCADE; +ALTER TABLE comptes-rendus + ADD CONSTRAINT fk1_compte_rendu FOREIGN KEY (id_rdv) + REFERENCES rendez_vous (id_rdv) + ON +DELETE +CASCADE; -- 2.47.2 From ca282378ecdc405935ed8ca6cc02e4676469e826 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:34:16 +0100 Subject: [PATCH 34/97] fix: changed the formatting ? --- .../myinpulse/postgres_db/model/RendezVous.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index b1cc5a2..438a7a5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -12,6 +12,12 @@ import java.util.List; @Table(name = "rendez_vous") public class RendezVous { + @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) + private final List ListEntrepreneurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private final List ListAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) + private final List ListComptesRendus = new ArrayList<>(); @ManyToMany( fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @@ -30,12 +36,6 @@ public class RendezVous { @Column(length = 255) private String lieu_rdv; private String sujet_rdv; - @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneurs = new ArrayList<>(); - @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListAdministrateurs = new ArrayList<>(); - @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListComptesRendus = new ArrayList<>(); public RendezVous() {} -- 2.47.2 From b4c05f8c594d98acb1da1ccc4ccfbd961fefa0da Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Feb 2025 15:38:55 +0100 Subject: [PATCH 35/97] fix: formatting again --- .../enseirb/myinpulse/postgres_db/model/RendezVous.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index 438a7a5..7616ff6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -14,10 +14,13 @@ public class RendezVous { @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) private final List ListEntrepreneurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) private final List ListAdministrateurs = new ArrayList<>(); + @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) private final List ListComptesRendus = new ArrayList<>(); + @ManyToMany( fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @@ -26,15 +29,19 @@ public class RendezVous { joinColumns = @JoinColumn(name = "id_rdv"), inverseJoinColumns = @JoinColumn(name = "id_section")) List ListSections = new ArrayList<>(); + @Id @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_rdv; + private LocalDate date_rdv; private LocalDateTime heure_rdv; private LocalDateTime duree_rdv; + @Column(length = 255) private String lieu_rdv; + private String sujet_rdv; public RendezVous() {} -- 2.47.2 From e26f8da66289199788ad8aaad1b55f62d7d6e44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 12 Feb 2025 18:51:27 +0100 Subject: [PATCH 36/97] fix: inserting data in db --- .../controller/ComptesRendusController.java | 2 +- .../controller/EntrepreneursController.java | 2 +- .../controller/ProjetsController.java | 2 +- .../controller/RendezVousController.java | 8 +-- .../controller/SectionsController.java | 2 +- .../controller/UtilisateursController.java | 2 +- .../postgres_db/model/Administrateurs.java | 2 +- .../postgres_db/model/Entrepreneurs.java | 2 +- .../postgres_db/model/RendezVous.java | 18 +++--- .../postgres_db/model/Utilisateurs.java | 2 +- MyINPulse-back/src/main/resources/data.sql | 62 ++++++++++--------- MyINPulse-back/src/main/resources/delete.sql | 1 + MyINPulse-back/src/main/resources/schema.sql | 12 ++-- 13 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 MyINPulse-back/src/main/resources/delete.sql diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index 312ae9e..3862118 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -42,6 +42,6 @@ public class ComptesRendusController { if (contenu_compte_rendu != null) { compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); } - return compteRendu.get(); + return this.comptesRendusRepository.save(compteRendu.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java index f789e0d..8fdc1dd 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java @@ -51,6 +51,6 @@ public class EntrepreneursController { if (status_snee != null) { entrepreneur.get().setStatus_snee(status_snee); } - return entrepreneur.get(); + return this.entrepreneursRepository.save(entrepreneur.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java index f3a469c..d0909b0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java @@ -57,6 +57,6 @@ public class ProjetsController { if (status_projet != null) { projet.get().setStatus_projet(status_projet); } - return projet.get(); + return this.projetsRepository.save(projet.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java index 6f2a39f..9761fd9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java @@ -3,7 +3,7 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.RendezVous; import enseirb.myinpulse.postgres_db.repository.RendezVousRepository; import java.time.LocalDate; -import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -39,8 +39,8 @@ public class RendezVousController { public RendezVous updateRendezVous( @PathVariable Long id, LocalDate date_rdv, - LocalDateTime heure_rdv, - LocalDateTime duree_rdv, + LocalTime heure_rdv, + LocalTime duree_rdv, String lieu_rdv, String sujet_rdv) { Optional rendezVous = this.rendezVousRepository.findById(id); @@ -62,6 +62,6 @@ public class RendezVousController { if (sujet_rdv != null) { rendezVous.get().setSujet_rdv(sujet_rdv); } - return rendezVous.get(); + return this.rendezVousRepository.save(rendezVous.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java index 5b4df39..01f94ae 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java @@ -53,6 +53,6 @@ public class SectionsController { if (date_modification != null) { section.get().setDate_modification(date_modification); } - return section.get(); + return this.sectionsRepository.save(section.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java index a6c128d..c46d688 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java @@ -60,6 +60,6 @@ public class UtilisateursController { if (numero_telephone != null) { utilisateur.get().setNumero_telephone(numero_telephone); } - return utilisateur.get(); + return this.utilisateursRepository.save(utilisateur.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java index 30b70d1..0f91f9a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java @@ -8,7 +8,7 @@ import java.util.List; @Entity @Table(name = "administrateurs") -@PrimaryKeyJoinColumn(name = "id_administrateur") +@PrimaryKeyJoinColumn(name = "id_administrateur", referencedColumnName = "id_utilisateur") public class Administrateurs extends Utilisateurs { @ManyToOne(fetch = FetchType.LAZY) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java index 9b696f3..dbe9a81 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java @@ -6,7 +6,7 @@ import jakarta.persistence.Table; @Entity @Table(name = "entrepreneurs") -@PrimaryKeyJoinColumn(name = "id_entrepreneur") +@PrimaryKeyJoinColumn(name = "id_entrepreneur", referencedColumnName = "id_utilisateur") public class Entrepreneurs extends Utilisateurs { @Column(length = 255) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java index e1625e5..3bf380d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java @@ -4,7 +4,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import java.time.LocalDate; -import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.ArrayList; import java.util.List; @@ -19,9 +19,9 @@ public class RendezVous { private LocalDate date_rdv; - private LocalDateTime heure_rdv; + private LocalTime heure_rdv; - private LocalDateTime duree_rdv; + private LocalTime duree_rdv; @Column(length = 255) private String lieu_rdv; @@ -51,8 +51,8 @@ public class RendezVous { public RendezVous( Long id_rdv, LocalDate date_rdv, - LocalDateTime heure_rdv, - LocalDateTime duree_rdv, + LocalTime heure_rdv, + LocalTime duree_rdv, String lieu_rdv, String sujet_rdv) { this.id_rdv = id_rdv; @@ -79,19 +79,19 @@ public class RendezVous { this.date_rdv = date_rdv; } - public LocalDateTime getHeure_rdv() { + public LocalTime getHeure_rdv() { return heure_rdv; } - public void setHeure_rdv(LocalDateTime heure_rdv) { + public void setHeure_rdv(LocalTime heure_rdv) { this.heure_rdv = heure_rdv; } - public LocalDateTime getDuree_rdv() { + public LocalTime getDuree_rdv() { return duree_rdv; } - public void setDuree_rdv(LocalDateTime duree_rdv) { + public void setDuree_rdv(LocalTime duree_rdv) { this.duree_rdv = duree_rdv; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java index 9d81163..478b9ef 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java @@ -25,7 +25,7 @@ public class Utilisateurs { @Column(length = 255) private String mail_secondaire; - @Column(length = 15) + @Column(length = 20) private String numero_telephone; public Utilisateurs() {} diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index 4014267..eb4eb9a 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -1,3 +1,5 @@ +TRUNCATE projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus CASCADE; + INSERT INTO projets (nom_projet, logo, date_creation, status_projet) VALUES ('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_DATE('01-OCT-2023', 'DD-MON-YYYY'), 'En cours'), ('Air oxygéné', decode('150647a0984e8f228cd14b54', 'hex'), TO_DATE('04-APR-2024', 'DD-MON-YYYY'), 'En cours'), @@ -9,42 +11,44 @@ INSERT INTO utilisateurs (nom_utilisateur, prenom_utilisateur, mail_principal, m ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), ('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), ('Leguez', 'Theo', 'bof@mesmails.fr', 'bof2@mesmails.fr', '+33 6 78 14 25 29'), -('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'); +('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'), +('Ducaillou', 'Pierre', 'maildefou@xyz.fr', 'maildefou2@xyz.fr', '06 54 78 12 62'); -INSERT INTO entrepreneurs (ecole, filiere, status_snee) VALUES -('ENSEIRB-MATMECA', 'INFO', TRUE), -('ENSC', 'Cognitique', TRUE), -('ENSEIRB-MATMECA', 'MATMECA', FALSE), -('SupOptique', 'Classique', TRUE), -('ENSEGID', 'Géoscience', FALSE), -('ENSMAC', 'Matériaux composites - Mécanique', FALSE); + +INSERT INTO entrepreneurs (ecole, filiere, status_snee, id_entrepreneur) VALUES +('ENSEIRB-MATMECA', 'INFO', TRUE, 1), +('ENSC', 'Cognitique', TRUE, 2), +('ENSEIRB-MATMECA', 'MATMECA', FALSE, 3), +('SupOptique', 'Classique', TRUE, 4), +('ENSEGID', 'Géoscience', FALSE, 5), +('ENSMAC', 'Matériaux composites - Mécanique', FALSE, 6); INSERT INTO sections (titre, contenu_section, date_modification) VALUES -("Problème", "les problèmes...", TO_DATE('15-JAN-2025', 'DD-MON-YYYY')), -("Segment de client", "Le segment AB passant le client n°8 est de longueur 32mm. - Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?", TO_DATE('12-OCT-2022', 'DD-MON-YYYY')), -("Proposition de valeur unique", "'Son prix est de 2594€' 'Ah oui c'est unique en effet'", TO_DATE('25-MAY-2024', 'DD-MON-YYYY')), -("Solution", "Un problème ? Une solution", TO_DATE('08-FEB-2024', 'DD-MON-YYYY')), -("Canaux", "Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez", TO_DATE('19-JUL-2023', 'DD-MON-YYYY')), -("Sources de revenus", "Y'en n'a pas on est pas payé. Enfin y'a du café quoi", TO_DATE('12-JAN-2025', 'DD-MON-YYYY')), -("Structure des coûts", "'Ah oui là ça va faire au moins 1000€ par mois', Eirbware", TO_DATE('06-FEB-2025', 'DD-MON-YYYY')), -("Indicateurs clés", "On apprend les clés comme des badges, ça se fait", TO_DATE('05-FEB-2025', 'DD-MON-YYYY')), -("Avantages concurrentiel", "On est meilleur", TO_DATE('23-APR-2024', 'DD-MON-YYYY')); +('Problème', 'les problèmes...', TO_TIMESTAMP('15-JAN-2025 09:30:20', 'DD-MON-YYYY, HH24:MI:SS')), +('Segment de client', 'Le segment AB passant le client n°8 est de longueur 32mm. + Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?', TO_TIMESTAMP('12-OCT-2022 17:47:38', 'DD-MON-YYYY, HH24:MI:SS')), +('Proposition de valeur unique', '''Son prix est de 2594€'' ''Ah oui c''est unique en effet', TO_TIMESTAMP('25-MAY-2024 11:12:04', 'DD-MON-YYYY, HH24:MI:SS')), +('Solution', 'Un problème ? Une solution', TO_TIMESTAMP('08-FEB-2024 10:17:53', 'DD-MON-YYYY, HH24:MI:SS')), +('Canaux', 'Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez', TO_TIMESTAMP('19-JUL-2023 19:22:45', 'DD-MON-YYYY, HH24:MI:SS')), +('Sources de revenus', 'Y''en n''a pas on est pas payé. Enfin y''a du café quoi', TO_TIMESTAMP('12-JAN-2025 11:40:26', 'DD-MON-YYYY, HH24:MI:SS')), +('Structure des coûts', '''Ah oui là ça va faire au moins 1000€ par mois'', Eirbware', TO_TIMESTAMP('06-FEB-2025 13:04:06', 'DD-MON-YYYY, HH24:MI:SS')), +('Indicateurs clés', 'On apprend les clés comme des badges, ça se fait', TO_TIMESTAMP('05-FEB-2025 12:42:38', 'DD-MON-YYYY, HH24:MI:SS')), +('Avantages concurrentiel', 'On est meilleur', TO_TIMESTAMP('23-APR-2024 16:24:02', 'DD-MON-YYYY, HH24:MI:SS')); INSERT INTO rendez_vous (date_rdv, heure_rdv, duree_rdv, lieu_rdv, sujet_rdv) VALUES -(TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', "À la maison", "Ouvrir les cadeaux"), -(TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', "Sur les quais ou dans un champ probablement", "BOUM BOUM les feux d'artifices (on fête quoi déjà ?)"), -(TO_DATE('29-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', "Salle TD 15", "Ah mince c'est pas une année bissextile !"), -(TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', "Là où le vent nous porte", "Journée la plus importante de l'année"), -(TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', "Euh c'est par où l'amphi 56 ?", "Rentrée scolaire (il fait trop froid c'est quoi ça on est en août)"); +(TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', 'À la maison', 'Ouvrir les cadeaux'), +(TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', 'Sur les quais ou dans un champ probablement', 'BOUM BOUM les feux d''artifices (on fête quoi déjà ?)'), +(TO_DATE('28-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', 'Salle TD 15', 'Ah mince c''est pas une année bissextile !'), +(TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', 'Là où le vent nous porte', 'Journée la plus importante de l''année'), +(TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', 'Euh c''est par où l''amphi 56 ?', 'Rentrée scolaire (il fait trop froid c''est quoi ça on est en août)'); INSERT INTO comptes_rendus (contenu_compte_rendu) VALUES -("Ah oui ça c'est super, ah ouais j'aime bien, bien vu de penser à ça"), -("Bonne réunion"), -("Ouais, j'ai rien compris mais niquel on fait comme vous avez dit"), -("Non non ça va pas du tout ce que tu me proposes, faut tout refaire"), -("Réponse de la DSI : non"), -("Trop dommage qu'Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence"); +('Ah oui ça c''est super, ah ouais j''aime bien, bien vu de penser à ça'), +('Bonne réunion'), +('Ouais, j''ai rien compris mais niquel on fait comme vous avez dit'), +('Non non ça va pas du tout ce que tu me proposes, faut tout refaire'), +('Réponse de la DSI : non'), +('Trop dommage qu''Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence'); diff --git a/MyINPulse-back/src/main/resources/delete.sql b/MyINPulse-back/src/main/resources/delete.sql new file mode 100644 index 0000000..c494872 --- /dev/null +++ b/MyINPulse-back/src/main/resources/delete.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE; \ No newline at end of file diff --git a/MyINPulse-back/src/main/resources/schema.sql b/MyINPulse-back/src/main/resources/schema.sql index 4916414..f1f8b08 100644 --- a/MyINPulse-back/src/main/resources/schema.sql +++ b/MyINPulse-back/src/main/resources/schema.sql @@ -24,21 +24,21 @@ nom_utilisateur VARCHAR(255) , prenom_utilisateur VARCHAR(255) , mail_principal VARCHAR(255) , mail_secondaire VARCHAR(255) , -numero_telephone VARCHAR(15) , +numero_telephone VARCHAR(20) , CONSTRAINT pk_utilisateur PRIMARY KEY (id_utilisateur) ); CREATE TABLE entrepreneurs ( -id_entrepreneur SERIAL REFERENCES utilisateurs (id_utilisateur), ecole VARCHAR(255) , filiere VARCHAR(255) , status_snee BOOLEAN , -CONSTRAINT pk_entrepreneur PRIMARY KEY (id_entrepreneur) ); +CONSTRAINT pk_entrepreneur PRIMARY KEY (id_utilisateur), +INHERITS (utilisateurs) ); CREATE TABLE administrateurs -( -id_administrateur SERIAL REFERENCES utilisateurs (id_utilisateur), -CONSTRAINT pk_administrateur PRIMARY KEY (id_administrateur) ); +( +CONSTRAINT pk_administrateur PRIMARY KEY (id_utilisateur), +INHERITS (utilisateurs) ); CREATE TABLE sections ( -- 2.47.2 From 0a9d83655f7c42241c7521196c61912afa66a919 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Thu, 13 Feb 2025 21:57:41 +0100 Subject: [PATCH 37/97] feat: query to database from and unaut endpoint --- .../java/enseirb/myinpulse/api/GetUserInfo.java | 13 +++++++++++++ .../controller/ComptesRendusController.java | 7 +++++-- front/MyINPulse-front/src/views/testComponent.vue | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java index ad008f0..18c3f07 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java @@ -1,5 +1,10 @@ package enseirb.myinpulse.api; +import enseirb.myinpulse.postgres_db.controller.ComptesRendusController; +import enseirb.myinpulse.postgres_db.model.ComptesRendus; +import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -7,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class GetUserInfo { + @GetMapping("/unauth/random") public boolean rand() { return Math.random() > 0.5; @@ -21,4 +27,11 @@ public class GetUserInfo { public boolean rand3() { return Math.random() > 0.5; } + + @Autowired + @GetMapping("/unauth/dev") + public ComptesRendus testApi(ComptesRendusRepository repository) { + ComptesRendusController comptesRendusController = new ComptesRendusController(repository); + return comptesRendusController.getComptesRendusById((long) 1); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java index 5d35227..97faafd 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java @@ -3,7 +3,6 @@ package enseirb.myinpulse.postgres_db.controller; import enseirb.myinpulse.postgres_db.model.ComptesRendus; import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; @@ -13,7 +12,11 @@ import java.util.Optional; @RestController public class ComptesRendusController { - @Autowired ComptesRendusRepository comptesRendusRepository; + private final ComptesRendusRepository comptesRendusRepository; + + public ComptesRendusController(ComptesRendusRepository comptesRendusRepository) { + this.comptesRendusRepository = comptesRendusRepository; + } @GetMapping("/ComptesRendus") @ResponseBody diff --git a/front/MyINPulse-front/src/views/testComponent.vue b/front/MyINPulse-front/src/views/testComponent.vue index 9ba1d5a..53febbf 100644 --- a/front/MyINPulse-front/src/views/testComponent.vue +++ b/front/MyINPulse-front/src/views/testComponent.vue @@ -50,7 +50,7 @@ import { callApi } from "@/services/api.ts"; Unauth API call - + res -- 2.47.2 From 3cb12dab4fe79c42a5cfa42c9e79317666066976 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 18 Feb 2025 10:50:21 +0100 Subject: [PATCH 38/97] feat: created signature of all api functions --- .../java/enseirb/myinpulse/api/AdminApi.java | 78 +++++++++++++++++++ .../myinpulse/api/EntrepreneurApi.java | 51 ++++++++++++ .../java/enseirb/myinpulse/api/SharedApi.java | 78 +++++++++++++++++++ .../myinpulse/api/datatypes/Appointment.java | 8 ++ .../myinpulse/api/datatypes/LCSection.java | 7 ++ .../myinpulse/api/datatypes/Project.java | 7 ++ .../api/datatypes/ProjectDecision.java | 7 ++ .../myinpulse/api/datatypes/Report.java | 6 ++ 8 files changed, 242 insertions(+) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java new file mode 100644 index 0000000..da33b73 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java @@ -0,0 +1,78 @@ +package enseirb.myinpulse.api; + +import enseirb.myinpulse.api.datatypes.Project; +import enseirb.myinpulse.api.datatypes.ProjectDecision; + +import enseirb.myinpulse.api.datatypes.Report; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.*; + +@SpringBootApplication +@RestController +public class AdminApi { + + /** + * TODO + * + * @return a list of all project managed by the current admin user + */ + @GetMapping("/admin/projects") + public void getProjects() {} + + /** + * TODO: Why in admin instead of shared ? + * + * @return a list of upcoming appointments for the current user + */ + @GetMapping("/admin/appointments/upcoming") + public void getUpcomingAppointments() {} + + /** + * TODO + * + * @return a list of current unvalidated projects, waiting to be accepted + */ + @GetMapping("/admin/projects/pending") + public void getPendingProjects() {} + + /** + * TODO + * + *

Endpoint used to make a decision about a project. + * + * @return the status code of the request + */ + @PostMapping("/admin/projects/decision") + public void validateProject(@RequestBody ProjectDecision decision) {} + + /** + * TODO + * + *

Endpoint used to manually add a project by an admin + * + * @return the status code of the request + */ + @PostMapping("/admin/project/add") + public void addNewProject(@RequestBody Project project) {} + + /** + * TODO: shouldn't it be an UPDATE request ? + * + *

Endpoint used to add a new report to an appointment + * + * @return the status code of the request + */ + @PostMapping("/admin/appoitements/report/{appointmentId}") + public void createAppointmentReport( + @PathVariable String appointmentId, @RequestBody Report report) {} + + /** + * TODO: Shouldn't a project be kept in history ? 2 different endpoints ? + * + *

Endpoint used to completely remove a project. + * + * @return the status code of the request + */ + @DeleteMapping("/admin/projects/remove/{projectId}") + public void deleteProject(@PathVariable String projectId) {} +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java new file mode 100644 index 0000000..4f1eef2 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java @@ -0,0 +1,51 @@ +package enseirb.myinpulse.api; + +import enseirb.myinpulse.api.datatypes.LCSection; +import enseirb.myinpulse.api.datatypes.Project; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.*; + +@SpringBootApplication +@RestController +public class EntrepreneurApi { + /** + * TODO + * + *

Endpoint used to update a LC section. + * + * @return status code + */ + @PutMapping("/entrepreneur/lcsection/modify/{sectionId}") + public void editLCSection(@PathVariable String sectionId, @RequestBody LCSection section) {} + + /** + * TODO + * + *

Endpoint used to delete a LC section + * + * @return status code + */ + @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") + public void removeLCSection(@PathVariable String sectionId) {} + + /** + * TODO + * + *

Endpoint used to create a new LC section + * + * @return status code + */ + @PostMapping("/entrepreneur/lcsection/add/{sectionId}") + public void addLCSection(@PathVariable String sectionId, @RequestBody LCSection section) {} + + /** + * TODO + * + *

Endpoint used to request the creation of a new project + * + * @return status code + */ + @PostMapping("/entrepreneur/project/request") + public void requestNewProject(@RequestBody Project project) {} +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java new file mode 100644 index 0000000..c71b5b5 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java @@ -0,0 +1,78 @@ +package enseirb.myinpulse.api; + +import enseirb.myinpulse.api.datatypes.Appointment; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.*; + +@SpringBootApplication +@RestController +public class SharedApi { + + /** + * TODO: It does not looks like a good id to have the title and the date in the url. What even + * TODO: is the title btw ? if this is the LC section, wouldn't it be better to use an ID ? + * TODO: choose return type, cf comment in LCSection + * + *

Endpoint used to get the data inside the lean canvas + * + * @return a list of lean canvas sections + */ + @GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}") + public void getLCSection( + @PathVariable("projectId") String projectId, + @PathVariable("title") String title, + @PathVariable("date") String date) {} + + /** + * TODO + * + *

Endpoint used to get entrepreneurs details + * + * @return a list of all entrepreneurs in a project + */ + @GetMapping("/shared/entrepreneurs/{projectId}") + public void getEntrepreneursByProjectId(@PathVariable int projectId) {} + + /** + * TODO: is it really useful for the admin ? We can already get all the project of the current + * administrator. + * + *

Endpoint used to get the administrator of a project. + * + * @return a list of all project managed by the current admin user + */ + @GetMapping("/shared/projects/admin/{projectId}") + public void getAdminByProjectId(@PathVariable int projectId) {} + + /** + * TODO: Should it really be all appointments? all future appointments ? a flag to choose \\ + * TODO: between both ? + * + *

Endpoint used to get all appointments of a single project. + * + * @return a list of all appointments. + */ + @GetMapping("/shared/projects/appointments/{projectId}") + public void getAppointmentsByProjectId(@PathVariable int projectId) {} + + /** + * TODO: Shouldn't the last two parameters be swapped ? + * + *

Endpoint used to generate a PDF report + * + * @return a PDF file? TODO: how does that works ? + */ + @GetMapping("/shared/projects/appointments/report/{appointmentId}") + public void getPDFReport(@PathVariable int appointmentId) {} + + /** + * TODO + * + *

+ * + * @return a list of all project managed by the current admin user + */ + @PostMapping("/shared/appointment/request") + public void createAppointmentRequest(@RequestBody Appointment appointment) {} +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java new file mode 100644 index 0000000..ba2187e --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java @@ -0,0 +1,8 @@ +package enseirb.myinpulse.api.datatypes; + +public class Appointment { + int validated; + int[] akserId; + int[] destId; + String date; // TODO: date type ? +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java new file mode 100644 index 0000000..0af17e3 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.api.datatypes; + +// TODO: is this redundant with the Section class from the database ? +// TODO: In the one hand it represent the same data, and on the other it should be much lighter. +// TODO: btw why does a LC section have an administrator ? + +public class LCSection {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java new file mode 100644 index 0000000..a6ab98f --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.api.datatypes; + +public class Project { + int projectId; + String projectName; + String projectDescription; +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java new file mode 100644 index 0000000..ab3387b --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.api.datatypes; + +public class ProjectDecision { + int projectId; + int adminId; + int isAccepted; +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java new file mode 100644 index 0000000..3656014 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java @@ -0,0 +1,6 @@ +package enseirb.myinpulse.api.datatypes; + +public class Report { + int projectId; + String reportContent; +} -- 2.47.2 From 6235fe7e6811b6f89ed2d662791cc1d6a04d12e2 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 18 Feb 2025 12:07:07 +0100 Subject: [PATCH 39/97] feat: separated class definition --- .../enseirb/myinpulse/utils/KeycloakApi.java | 77 ------------------- .../datatypes/RoleRepresentation.java | 7 ++ .../datatypes/UserRepresentation.java | 6 ++ 3 files changed, 13 insertions(+), 77 deletions(-) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java deleted file mode 100644 index e91e9e1..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/KeycloakApi.java +++ /dev/null @@ -1,77 +0,0 @@ -package enseirb.myinpulse.utils; - -import enseirb.myinpulse.exceptions.UserNotFoundException; -import org.springframework.web.client.RestClient; - -import javax.management.relation.RoleNotFoundException; - -import static org.springframework.http.MediaType.APPLICATION_JSON; - -public class KeycloakApi { - - static final String keycloakUrl = "http://localhost:7080"; - static final String realmName = "test"; - - /** - * Uses Keycloak API to retrieve a role representation of a role by its name - * @param roleName name of the role - * @param bearer authorization header used by the client to authenticate to keycloak - */ - static public RoleRepresentation getRoleRepresentationByName(String roleName, String bearer) throws RoleNotFoundException { - RoleRepresentation[] response = RestClient.builder().baseUrl(keycloakUrl) - .defaultHeader("Authorization", bearer) - .build() - .get() - .uri("/admin/realms/{realmName}/roles/{roleName}", realmName, roleName) - .retrieve() - .body(RoleRepresentation[].class); - - if (response == null || response.length == 0) { - throw new RoleNotFoundException("Role not found"); - } - return response[0]; - } - - static public String getUserIdByName(String username, String bearer) throws UserNotFoundException { - UserRepresentation[] response = RestClient.builder().baseUrl(keycloakUrl) - .defaultHeader("Authorization", bearer) - .build() - .get() - .uri("/admin/realms/{realmName}/users?username={username}", realmName, username) - .retrieve() - .body(UserRepresentation[].class); - - if (response == null || response.length == 0) { - throw new UserNotFoundException("User not found"); - } - return response[0].id; - } - - static public void setRoleToUser(String username, String roleName, String bearer) throws RoleNotFoundException, UserNotFoundException { - RoleRepresentation roleRepresentation = getRoleRepresentationByName(roleName, bearer); - String userId = getUserIdByName(username, bearer); - - - RestClient.builder().baseUrl(keycloakUrl) - .defaultHeader("Authorization", bearer) - .build() - .post() - .uri("/admin/realms/${realmName}/users/${userId}/role-mappings/realm", realmName, userId) - .body(roleRepresentation) - .contentType(APPLICATION_JSON) - .retrieve(); - } -} - - -class RoleRepresentation { - public String id; - public String name; - public String description; -} - -class UserRepresentation { - public String id; - public String name; -} - diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java new file mode 100644 index 0000000..a6252a9 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.utils.keycloak.datatypes; + +public class RoleRepresentation { + public String id; + public String name; + public String description; +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java new file mode 100644 index 0000000..f2c3522 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java @@ -0,0 +1,6 @@ +package enseirb.myinpulse.utils.keycloak.datatypes; + +public class UserRepresentation { + public String id; + public String name; +} -- 2.47.2 From 86e7dc7c757412cc22be9f055887992f06b7b76a Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 18 Feb 2025 16:37:55 +0100 Subject: [PATCH 40/97] fix: removed the test file that was causing the linter to fail --- front/MyINPulse-front/src/views/test.vue | 73 ------------------------ 1 file changed, 73 deletions(-) delete mode 100644 front/MyINPulse-front/src/views/test.vue diff --git a/front/MyINPulse-front/src/views/test.vue b/front/MyINPulse-front/src/views/test.vue deleted file mode 100644 index 9d98958..0000000 --- a/front/MyINPulse-front/src/views/test.vue +++ /dev/null @@ -1,73 +0,0 @@ - - - - - -- 2.47.2 From 5e8e875a37c26bb7672b27801b6ad5ff2fb2bb02 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 18 Feb 2025 16:45:41 +0100 Subject: [PATCH 41/97] feat: added user deletion and custom api call in the frontend --- .../myinpulse/utils/keycloak/KeycloakApi.java | 135 ++++++++++++++++++ .../src/views/testComponent.vue | 11 ++ 2 files changed, 146 insertions(+) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java new file mode 100644 index 0000000..ff6dde2 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java @@ -0,0 +1,135 @@ +package enseirb.myinpulse.utils.keycloak; + +import static org.springframework.http.MediaType.APPLICATION_JSON; + +import enseirb.myinpulse.exceptions.UserNotFoundException; +import enseirb.myinpulse.utils.keycloak.datatypes.RoleRepresentation; +import enseirb.myinpulse.utils.keycloak.datatypes.UserRepresentation; + +import org.springframework.web.client.RestClient; + +import javax.management.relation.RoleNotFoundException; + +public class KeycloakApi { + + static final String keycloakUrl; + static final String realmName; + + static { + if (System.getenv("VITE_KEYCLOAK_URL") == null) { + System.exit(-1); + } + keycloakUrl = System.getenv("VITE_KEYCLOAK_URL"); + } + + static { + if (System.getenv("VITE_KEYCLOAK_REALM") == null) { + System.exit(-1); + } + realmName = System.getenv("VITE_KEYCLOAK_REALM"); + } + + /** + * Uses Keycloak API to retrieve a role representation of a role by its name + * + * @param roleName name of the role + * @param bearer authorization header used by the client to authenticate to keycloak + */ + public static RoleRepresentation getRoleRepresentationByName(String roleName, String bearer) + throws RoleNotFoundException { + RoleRepresentation[] response = + RestClient.builder() + .baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .get() + .uri("/admin/realms/{realmName}/roles/{roleName}", realmName, roleName) + .retrieve() + .body(RoleRepresentation[].class); + + if (response == null || response.length == 0) { + throw new RoleNotFoundException("Role not found"); + } + return response[0]; + } + + /** + * Use keycloak API to to retreive a userID via his name or email. + * + * @param username username or mail of the user + * @param bearer bearer of the user, allowing access to database + * @return the userid, as a String + * @throws UserNotFoundException + */ + public static String getUserIdByName(String username, String bearer) + throws UserNotFoundException { + UserRepresentation[] response = + RestClient.builder() + .baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .get() + .uri( + "/admin/realms/{realmName}/users?username={username}", + realmName, + username) + .retrieve() + .body(UserRepresentation[].class); + + if (response == null || response.length == 0) { + throw new UserNotFoundException("User not found"); + } + return response[0].id; + } + + /** + * TODO: check for error + * + *

Set a keycloak role to a keycloak user. + * + *

Usual roles should be `MyINPulse-admin` and `MyINPulse-entrepreneur` + * + * @param username + * @param roleName + * @param bearer + * @throws RoleNotFoundException + * @throws UserNotFoundException + */ + public static void setRoleToUser(String username, String roleName, String bearer) + throws RoleNotFoundException, UserNotFoundException { + RoleRepresentation roleRepresentation = getRoleRepresentationByName(roleName, bearer); + String userId = getUserIdByName(username, bearer); + + RestClient.builder() + .baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .post() + .uri( + "/admin/realms/${realmName}/users/${userId}/role-mappings/realm", + realmName, + userId) + .body(roleRepresentation) + .contentType(APPLICATION_JSON) + .retrieve(); + } + + /** + * Delete a user from Keycloak database. TODO: check the bearer permission. + * + * @param username + * @param bearer + * @throws UserNotFoundException + */ + public static void deleteUser(String username, String bearer) throws UserNotFoundException { + String userId = getUserIdByName(username, bearer); + + RestClient.builder() + .baseUrl(keycloakUrl) + .defaultHeader("Authorization", bearer) + .build() + .delete() + .uri("/admin/realms/${realmName}/users/${userId}", realmName, userId) + .retrieve(); + } +} diff --git a/front/MyINPulse-front/src/views/testComponent.vue b/front/MyINPulse-front/src/views/testComponent.vue index 9ba1d5a..a73d879 100644 --- a/front/MyINPulse-front/src/views/testComponent.vue +++ b/front/MyINPulse-front/src/views/testComponent.vue @@ -1,6 +1,9 @@ -- 2.47.2 From 820757c836aaf568633700b8b81c5b3ec4f80ba2 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 18 Feb 2025 16:59:19 +0100 Subject: [PATCH 42/97] fix: corrected formatter error --- .../enseirb/myinpulse/api/GetUserInfo.java | 6 +- .../security/KeycloakJwtRolesConverter.java | 80 ++++++++++--------- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java index 7baea8e..694532f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java @@ -3,13 +3,12 @@ package enseirb.myinpulse.api; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; - -import javax.management.relation.RoleNotFoundException; -import java.security.Principal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import java.security.Principal; +import javax.management.relation.RoleNotFoundException; @SpringBootApplication @RestController @@ -26,7 +25,6 @@ public class GetUserInfo { @GetMapping("/unauth/random") public boolean rand(@RequestHeader("Authorization") String token) throws RoleNotFoundException { System.err.println(token); - System.err.println("HELLO"); return Math.random() > 0.5; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java index 08c5cab..743b765 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java @@ -4,6 +4,8 @@ */ package enseirb.myinpulse.security; +import static java.util.stream.Collectors.toSet; + import org.springframework.core.convert.converter.Converter; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; @@ -18,41 +20,35 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.stream.Collectors.toSet; - - public class KeycloakJwtRolesConverter implements Converter { - /** - * Prefix used for realm level roles. - */ + /** Prefix used for realm level roles. */ public static final String PREFIX_REALM_ROLE = "ROLE_REALM_"; - /** - * Prefix used in combination with the resource (client) name for resource level roles. - */ + + /** Prefix used in combination with the resource (client) name for resource level roles. */ public static final String PREFIX_RESOURCE_ROLE = "ROLE_"; - /** - * Name of the claim containing the realm level roles - */ + /** Name of the claim containing the realm level roles */ private static final String CLAIM_REALM_ACCESS = "realm_access"; - /** - * Name of the claim containing the resources (clients) the user has access to. - */ + + /** Name of the claim containing the resources (clients) the user has access to. */ private static final String CLAIM_RESOURCE_ACCESS = "resource_access"; - /** - * Name of the claim containing roles. (Applicable to realm and resource level.) - */ + + /** Name of the claim containing roles. (Applicable to realm and resource level.) */ private static final String CLAIM_ROLES = "roles"; @Override public AbstractAuthenticationToken convert(Jwt source) { - return new JwtAuthenticationToken(source, Stream.concat(new JwtGrantedAuthoritiesConverter().convert(source) - .stream(), tokenRolesExtractor(source).stream()) - .collect(toSet())); + return new JwtAuthenticationToken( + source, + Stream.concat( + new JwtGrantedAuthoritiesConverter().convert(source).stream(), + tokenRolesExtractor(source).stream()) + .collect(toSet())); } /** - * Extracts the realm and resource level roles from a JWT token distinguishing between them using prefixes. + * Extracts the realm and resource level roles from a JWT token distinguishing between them + * using prefixes. */ public Collection tokenRolesExtractor(Jwt jwt) { // Collection that will hold the extracted roles @@ -69,33 +65,43 @@ public class KeycloakJwtRolesConverter implements Converter realmRoles = roles.stream() - // Prefix all realm roles with "ROLE_realm_" - .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role)) - .collect(Collectors.toList()); + Collection realmRoles = + roles.stream() + // Prefix all realm roles with "ROLE_realm_" + .map(role -> new SimpleGrantedAuthority(PREFIX_REALM_ROLE + role)) + .collect(Collectors.toList()); grantedAuthorities.addAll(realmRoles); } } // Resource (client) roles - // A user might have access to multiple resources all containing their own roles. Therefore, it is a map of + // A user might have access to multiple resources all containing their own roles. Therefore, + // it is a map of // resource each possibly containing a "roles" property. - Map>> resourceAccess = jwt.getClaim(CLAIM_RESOURCE_ACCESS); + Map>> resourceAccess = + jwt.getClaim(CLAIM_RESOURCE_ACCESS); // Check if resources are assigned if (resourceAccess != null && !resourceAccess.isEmpty()) { // Iterate of all the resources - resourceAccess.forEach((resource, resourceClaims) -> { - // Iterate of the "roles" claim inside the resource claims - resourceClaims.get(CLAIM_ROLES).forEach( - // Add the role to the granted authority prefixed with ROLE_ and the name of the resource - role -> grantedAuthorities.add(new SimpleGrantedAuthority(PREFIX_RESOURCE_ROLE + resource + "_" + role)) - ); - }); + resourceAccess.forEach( + (resource, resourceClaims) -> { + // Iterate of the "roles" claim inside the resource claims + resourceClaims + .get(CLAIM_ROLES) + .forEach( + // Add the role to the granted authority prefixed with ROLE_ + // and the name of the resource + role -> + grantedAuthorities.add( + new SimpleGrantedAuthority( + PREFIX_RESOURCE_ROLE + + resource + + "_" + + role))); + }); } return grantedAuthorities; } - - } -- 2.47.2 From 04a73073c1fb92c8ba5244da9c0a4673ab59ee52 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 18 Feb 2025 22:15:14 +0100 Subject: [PATCH 43/97] feat: switch to a service layer architecture --- .../enseirb/myinpulse/api/GetUserInfo.java | 40 ---- .../KeycloakJwtRolesConverter.java | 2 +- .../WebSecurityCustomConfiguration.java | 6 +- .../{api => controller}/AdminApi.java | 59 +++-- .../{api => controller}/EntrepreneurApi.java | 40 +++- .../{api => controller}/SharedApi.java | 54 +++-- .../RoleNotFoudException.java | 2 +- .../UserNotFoundException.java | 2 +- .../model/Administrateurs.java | 86 +++---- .../{api/datatypes => model}/Appointment.java | 2 +- .../model/ComptesRendus.java | 92 ++++---- .../model/Entrepreneurs.java | 160 ++++++------- .../{api/datatypes => model}/LCSection.java | 2 +- .../{api/datatypes => model}/Project.java | 2 +- .../datatypes => model}/ProjectDecision.java | 2 +- .../{postgres_db => }/model/Projets.java | 196 ++++++++-------- .../{postgres_db => }/model/RendezVous.java | 222 +++++++++--------- .../{api/datatypes => model}/Report.java | 2 +- .../RoleRepresentation.java | 2 +- .../{postgres_db => }/model/Sections.java | 162 ++++++------- .../UserRepresentation.java | 2 +- .../{postgres_db => }/model/Utilisateurs.java | 190 +++++++-------- .../controller/ComptesRendusController.java | 52 ---- .../repository/AdministrateursRepository.java | 28 +-- .../repository/ComptesRendusRepository.java | 18 +- .../repository/EntrepreneursRepository.java | 28 +-- .../repository/ProjetsRepository.java | 18 +- .../repository/RendezVousRepository.java | 18 +- .../repository/SectionsRepository.java | 18 +- .../repository/UtilisateursRepository.java | 28 +-- .../myinpulse/service/AdminApiService.java | 46 ++++ .../service/EntrepreneurApiService.java | 29 +++ .../keycloak => service}/KeycloakApi.java | 8 +- .../myinpulse/service/SharedApiService.java | 36 +++ .../service/database/CompteRenduService.java | 34 +++ .../AdministrateursController.java | 76 +++--- .../ComptesRendusController.java | 43 ++++ .../EntrepreneursController.java | 116 ++++----- .../ProjetsController.java | 128 +++++----- .../RendezVousController.java | 136 +++++------ .../SectionsController.java | 120 +++++----- .../UtilisateursController.java | 134 +++++------ 42 files changed, 1295 insertions(+), 1146 deletions(-) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/{security => config}/KeycloakJwtRolesConverter.java (99%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api => controller}/AdminApi.java (51%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api => controller}/EntrepreneurApi.java (55%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api => controller}/SharedApi.java (55%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{exceptions => exception}/RoleNotFoudException.java (79%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{exceptions => exception}/UserNotFoundException.java (79%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/Administrateurs.java (93%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api/datatypes => model}/Appointment.java (75%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/ComptesRendus.java (92%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/Entrepreneurs.java (94%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api/datatypes => model}/LCSection.java (86%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api/datatypes => model}/Project.java (70%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api/datatypes => model}/ProjectDecision.java (68%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/Projets.java (94%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/RendezVous.java (94%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{api/datatypes => model}/Report.java (63%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{utils/keycloak/datatypes => model}/RoleRepresentation.java (68%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/Sections.java (93%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{utils/keycloak/datatypes => model}/UserRepresentation.java (61%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/model/Utilisateurs.java (94%) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/AdministrateursRepository.java (74%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/ComptesRendusRepository.java (62%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/EntrepreneursRepository.java (74%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/ProjetsRepository.java (68%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/RendezVousRepository.java (68%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/SectionsRepository.java (68%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db => }/repository/UtilisateursRepository.java (73%) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/{utils/keycloak => service}/KeycloakApi.java (94%) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db/controller => service/database/old_controllers_to_convert_to_services}/AdministrateursController.java (84%) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db/controller => service/database/old_controllers_to_convert_to_services}/EntrepreneursController.java (89%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db/controller => service/database/old_controllers_to_convert_to_services}/ProjetsController.java (89%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db/controller => service/database/old_controllers_to_convert_to_services}/RendezVousController.java (89%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db/controller => service/database/old_controllers_to_convert_to_services}/SectionsController.java (88%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/{postgres_db/controller => service/database/old_controllers_to_convert_to_services}/UtilisateursController.java (90%) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java deleted file mode 100644 index bbf9f85..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/GetUserInfo.java +++ /dev/null @@ -1,40 +0,0 @@ -package enseirb.myinpulse.api; - -import enseirb.myinpulse.postgres_db.controller.ComptesRendusController; -import enseirb.myinpulse.postgres_db.model.ComptesRendus; -import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.management.relation.RoleNotFoundException; - -@SpringBootApplication -@RestController -public class GetUserInfo { - @GetMapping("/unauth/random") - public boolean rand(@RequestHeader("Authorization") String token) throws RoleNotFoundException { - System.err.println(token); - return Math.random() > 0.5; - } - - @GetMapping("/admin/random") - public boolean rand2() { - return Math.random() > 0.5; - } - - @GetMapping("/entrepreneur/random") - public boolean rand3() { - return Math.random() > 0.5; - } - - @Autowired - @GetMapping("/unauth/dev") - public ComptesRendus testApi(ComptesRendusRepository repository) { - ComptesRendusController comptesRendusController = new ComptesRendusController(repository); - return comptesRendusController.getComptesRendusById((long) 1); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/KeycloakJwtRolesConverter.java similarity index 99% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/config/KeycloakJwtRolesConverter.java index 743b765..5a95ef6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/security/KeycloakJwtRolesConverter.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/KeycloakJwtRolesConverter.java @@ -2,7 +2,7 @@ * Source: https://github.com/ChristianHuff-DEV/secure-spring-rest-api-using-keycloak/blob/main/src/main/java/io/betweendata/RestApi/security/oauth2/KeycloakJwtRolesConverter.java * edited by Pierre Tellier */ -package enseirb.myinpulse.security; +package enseirb.myinpulse.config; import static java.util.stream.Collectors.toSet; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java index b8f0e4f..81f1dd8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/config/WebSecurityCustomConfiguration.java @@ -2,8 +2,6 @@ package enseirb.myinpulse.config; import static org.springframework.security.authorization.AuthorityAuthorizationManager.hasRole; -import enseirb.myinpulse.security.KeycloakJwtRolesConverter; - import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -58,9 +56,9 @@ public class WebSecurityCustomConfiguration { http.authorizeHttpRequests( authorize -> authorize - .requestMatchers("/entrepreneur/**") + .requestMatchers("/entrepreneur/**", "/shared/**") .access(hasRole("REALM_MyINPulse-entrepreneur")) - .requestMatchers("/admin/**") + .requestMatchers("/admin/**", "/shared/**") .access(hasRole("REALM_MyINPulse-admin")) .requestMatchers("/unauth/**") .permitAll() diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java similarity index 51% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java index da33b73..1a2a12a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/AdminApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java @@ -1,9 +1,9 @@ -package enseirb.myinpulse.api; +package enseirb.myinpulse.controller; -import enseirb.myinpulse.api.datatypes.Project; -import enseirb.myinpulse.api.datatypes.ProjectDecision; +import enseirb.myinpulse.model.*; +import enseirb.myinpulse.service.AdminApiService; -import enseirb.myinpulse.api.datatypes.Report; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.*; @@ -11,52 +11,65 @@ import org.springframework.web.bind.annotation.*; @RestController public class AdminApi { + private final AdminApiService adminApiService; + + @Autowired + AdminApi(AdminApiService adminApiService) { + this.adminApiService = adminApiService; + } + /** - * TODO + * TODO: description * * @return a list of all project managed by the current admin user */ @GetMapping("/admin/projects") - public void getProjects() {} + public Iterable getProjects() { + return adminApiService.getProjects(); + } /** - * TODO: Why in admin instead of shared ? + * TODO: Why in admin instead of shared ? + desc * * @return a list of upcoming appointments for the current user */ @GetMapping("/admin/appointments/upcoming") - public void getUpcomingAppointments() {} + public Iterable getUpcomingAppointments() { + return adminApiService.getUpcomingAppointments(); + } /** - * TODO + * TODO: description * * @return a list of current unvalidated projects, waiting to be accepted */ @GetMapping("/admin/projects/pending") - public void getPendingProjects() {} + public Iterable getPendingProjects() { + return adminApiService.getPendingProjects(); + } /** - * TODO - * - *

Endpoint used to make a decision about a project. + * Endpoint used to make a decision about a project. * * @return the status code of the request */ @PostMapping("/admin/projects/decision") - public void validateProject(@RequestBody ProjectDecision decision) {} + public void validateProject(@RequestBody ProjectDecision decision) { + adminApiService.validateProject(decision); + } /** - * TODO - * - *

Endpoint used to manually add a project by an admin + * Endpoint used to manually add a project by an admin * * @return the status code of the request */ @PostMapping("/admin/project/add") - public void addNewProject(@RequestBody Project project) {} + public void addNewProject(@RequestBody Project project) { + adminApiService.addNewProject(project); + } /** - * TODO: shouldn't it be an UPDATE request ? + * TODO: shouldn't it be an PUT request ? / What is the rerun type * *

Endpoint used to add a new report to an appointment * @@ -64,7 +77,9 @@ public class AdminApi { */ @PostMapping("/admin/appoitements/report/{appointmentId}") public void createAppointmentReport( - @PathVariable String appointmentId, @RequestBody Report report) {} + @PathVariable String appointmentId, @RequestBody Report report) { + adminApiService.createAppointmentReport(appointmentId, report); + } /** * TODO: Shouldn't a project be kept in history ? 2 different endpoints ? @@ -74,5 +89,7 @@ public class AdminApi { * @return the status code of the request */ @DeleteMapping("/admin/projects/remove/{projectId}") - public void deleteProject(@PathVariable String projectId) {} + public void deleteProject(@PathVariable String projectId) { + adminApiService.deleteProject(projectId); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java similarity index 55% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java index 4f1eef2..0071c61 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/EntrepreneurApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java @@ -1,51 +1,69 @@ -package enseirb.myinpulse.api; +package enseirb.myinpulse.controller; -import enseirb.myinpulse.api.datatypes.LCSection; -import enseirb.myinpulse.api.datatypes.Project; +import enseirb.myinpulse.model.LCSection; +import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.service.EntrepreneurApiService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.*; @SpringBootApplication @RestController public class EntrepreneurApi { + + private final EntrepreneurApiService entrepreneurApiService; + + @Autowired + EntrepreneurApi(EntrepreneurApiService entrepreneurApiService) { + this.entrepreneurApiService = entrepreneurApiService; + } + /** - * TODO + * TODO: check return type * *

Endpoint used to update a LC section. * * @return status code */ @PutMapping("/entrepreneur/lcsection/modify/{sectionId}") - public void editLCSection(@PathVariable String sectionId, @RequestBody LCSection section) {} + public void editLCSection(@PathVariable String sectionId, @RequestBody LCSection section) { + entrepreneurApiService.editLCSection(sectionId, section); + } /** - * TODO + * TODO: checkReturn Type * *

Endpoint used to delete a LC section * * @return status code */ @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") - public void removeLCSection(@PathVariable String sectionId) {} + public void removeLCSection(@PathVariable String sectionId) { + entrepreneurApiService.removeLCSection(sectionId); + } /** - * TODO + * TODO: check return type * *

Endpoint used to create a new LC section * * @return status code */ @PostMapping("/entrepreneur/lcsection/add/{sectionId}") - public void addLCSection(@PathVariable String sectionId, @RequestBody LCSection section) {} + public void addLCSection(@PathVariable String sectionId, @RequestBody LCSection section) { + entrepreneurApiService.addLCSection(sectionId, section); + } /** - * TODO + * TODO: check return type * *

Endpoint used to request the creation of a new project * * @return status code */ @PostMapping("/entrepreneur/project/request") - public void requestNewProject(@RequestBody Project project) {} + public void requestNewProject(@RequestBody Project project) { + entrepreneurApiService.requestNewProject(project); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java similarity index 55% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index c71b5b5..038a083 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -1,7 +1,12 @@ -package enseirb.myinpulse.api; +package enseirb.myinpulse.controller; -import enseirb.myinpulse.api.datatypes.Appointment; +import enseirb.myinpulse.model.Administrateurs; +import enseirb.myinpulse.model.Appointment; +import enseirb.myinpulse.model.Entrepreneurs; +import enseirb.myinpulse.model.Sections; +import enseirb.myinpulse.service.SharedApiService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.*; @@ -9,6 +14,13 @@ import org.springframework.web.bind.annotation.*; @RestController public class SharedApi { + private final SharedApiService sharedApiService; + + @Autowired + SharedApi(SharedApiService sharedApiService) { + this.sharedApiService = sharedApiService; + } + /** * TODO: It does not looks like a good id to have the title and the date in the url. What even * TODO: is the title btw ? if this is the LC section, wouldn't it be better to use an ID ? @@ -19,20 +31,22 @@ public class SharedApi { * @return a list of lean canvas sections */ @GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}") - public void getLCSection( + public Iterable getLCSection( @PathVariable("projectId") String projectId, @PathVariable("title") String title, - @PathVariable("date") String date) {} + @PathVariable("date") String date) { + return sharedApiService.getLCSection(projectId, title, date); + } /** - * TODO - * - *

Endpoint used to get entrepreneurs details + * Endpoint used to get entrepreneurs details * * @return a list of all entrepreneurs in a project */ @GetMapping("/shared/entrepreneurs/{projectId}") - public void getEntrepreneursByProjectId(@PathVariable int projectId) {} + public Iterable getEntrepreneursByProjectId(@PathVariable int projectId) { + return sharedApiService.getEntrepreneursByProjectId(projectId); + } /** * TODO: is it really useful for the admin ? We can already get all the project of the current @@ -43,7 +57,9 @@ public class SharedApi { * @return a list of all project managed by the current admin user */ @GetMapping("/shared/projects/admin/{projectId}") - public void getAdminByProjectId(@PathVariable int projectId) {} + public Iterable getAdminByProjectId(@PathVariable int projectId) { + return sharedApiService.getAdminByProjectId(projectId); + } /** * TODO: Should it really be all appointments? all future appointments ? a flag to choose \\ @@ -54,25 +70,27 @@ public class SharedApi { * @return a list of all appointments. */ @GetMapping("/shared/projects/appointments/{projectId}") - public void getAppointmentsByProjectId(@PathVariable int projectId) {} + public Iterable getAppointmentsByProjectId(@PathVariable int projectId) { + return sharedApiService.getAppointmentsByProjectId(projectId); + } /** - * TODO: Shouldn't the last two parameters be swapped ? - * - *

Endpoint used to generate a PDF report + * Endpoint used to generate a PDF report * * @return a PDF file? TODO: how does that works ? */ @GetMapping("/shared/projects/appointments/report/{appointmentId}") - public void getPDFReport(@PathVariable int appointmentId) {} + public void getPDFReport(@PathVariable int appointmentId) { + sharedApiService.getPDFReport(appointmentId); + } /** * TODO * - *

- * - * @return a list of all project managed by the current admin user + * @return TODO */ @PostMapping("/shared/appointment/request") - public void createAppointmentRequest(@RequestBody Appointment appointment) {} + public void createAppointmentRequest(@RequestBody Appointment appointment) { + sharedApiService.createAppointmentRequest(appointment); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/exception/RoleNotFoudException.java similarity index 79% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/exception/RoleNotFoudException.java index 22e4c23..6bc4f62 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/RoleNotFoudException.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/exception/RoleNotFoudException.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.exceptions; +package enseirb.myinpulse.exception; public class RoleNotFoudException extends RuntimeException { public RoleNotFoudException(String message) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/exception/UserNotFoundException.java similarity index 79% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/exception/UserNotFoundException.java index 983e766..531be69 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/exceptions/UserNotFoundException.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/exception/UserNotFoundException.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.exceptions; +package enseirb.myinpulse.exception; public class UserNotFoundException extends RuntimeException { public UserNotFoundException(String message) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java similarity index 93% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java index dbf2ea9..0ff00e1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Administrateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java @@ -1,43 +1,43 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.persistence.PrimaryKeyJoinColumn; -import jakarta.persistence.Table; - -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "administrateurs") -@PrimaryKeyJoinColumn(name = "id_administrateur", referencedColumnName = "id_utilisateur") -public class Administrateurs extends Utilisateurs { - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet") - private Projets projetsAdministrateurs; - - @OneToMany(mappedBy = "administrateursSections", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousAdministrateurs; - - public Administrateurs() {} - - public Administrateurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - super( - nom_utilisateur, - id_utilisateur, - prenom_utilisateur, - mail_principal, - mail_secondaire, - numero_telephone); - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.persistence.PrimaryKeyJoinColumn; +import jakarta.persistence.Table; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "administrateurs") +@PrimaryKeyJoinColumn(name = "id_administrateur", referencedColumnName = "id_utilisateur") +public class Administrateurs extends Utilisateurs { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet") + private Projets projetsAdministrateurs; + + @OneToMany(mappedBy = "administrateursSections", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousAdministrateurs; + + public Administrateurs() {} + + public Administrateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java similarity index 75% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index ba2187e..53727c1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.api.datatypes; +package enseirb.myinpulse.model; public class Appointment { int validated; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java similarity index 92% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java index 74c97ec..617b31a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/ComptesRendus.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java @@ -1,46 +1,46 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; - -@Entity -@Table(name = "comptes_rendus") -public class ComptesRendus { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_compte_rendu; - - private String contenu_compte_rendu; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousComptesRendus; - - public ComptesRendus() {} - - public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - this.contenu_compte_rendu = contenu_compte_rendu; - } - - public Long getId_compte_rendu() { - return id_compte_rendu; - } - - public void setId_compte_rendu(Long id_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - } - - public String getContenu_compte_rendu() { - return contenu_compte_rendu; - } - - public void setContenu_compte_rendu(String contenu_compte_rendu) { - this.contenu_compte_rendu = contenu_compte_rendu; - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "comptes_rendus") +public class ComptesRendus { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_compte_rendu; + + private String contenu_compte_rendu; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousComptesRendus; + + public ComptesRendus() {} + + public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + this.contenu_compte_rendu = contenu_compte_rendu; + } + + public Long getId_compte_rendu() { + return id_compte_rendu; + } + + public void setId_compte_rendu(Long id_compte_rendu) { + this.id_compte_rendu = id_compte_rendu; + } + + public String getContenu_compte_rendu() { + return contenu_compte_rendu; + } + + public void setContenu_compte_rendu(String contenu_compte_rendu) { + this.contenu_compte_rendu = contenu_compte_rendu; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java similarity index 94% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java index dbe9a81..ef605ea 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Entrepreneurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java @@ -1,80 +1,80 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -@Entity -@Table(name = "entrepreneurs") -@PrimaryKeyJoinColumn(name = "id_entrepreneur", referencedColumnName = "id_utilisateur") -public class Entrepreneurs extends Utilisateurs { - - @Column(length = 255) - private String ecole; - - @Column(length = 255) - private String filiere; - - private boolean status_snee; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet_participation", referencedColumnName = "id_projet") - private Projets projetsParticipation; - - // @Column(insertable=false, updatable=false) - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet_propose", referencedColumnName = "id_projet") - private Projets projetsPropose; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousEntrepreneurs; - - public Entrepreneurs() {} - - public Entrepreneurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone, - String ecole, - boolean status_snee, - String filiere) { - super( - nom_utilisateur, - id_utilisateur, - prenom_utilisateur, - mail_principal, - mail_secondaire, - numero_telephone); - this.ecole = ecole; - this.status_snee = status_snee; - this.filiere = filiere; - } - - public String getEcole() { - return ecole; - } - - public void setEcole(String ecole) { - this.ecole = ecole; - } - - public String getFiliere() { - return filiere; - } - - public void setFiliere(String filiere) { - this.filiere = filiere; - } - - public boolean isStatus_snee() { - return status_snee; - } - - public void setStatus_snee(boolean status_snee) { - this.status_snee = status_snee; - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "entrepreneurs") +@PrimaryKeyJoinColumn(name = "id_entrepreneur", referencedColumnName = "id_utilisateur") +public class Entrepreneurs extends Utilisateurs { + + @Column(length = 255) + private String ecole; + + @Column(length = 255) + private String filiere; + + private boolean status_snee; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet_participation", referencedColumnName = "id_projet") + private Projets projetsParticipation; + + // @Column(insertable=false, updatable=false) + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet_propose", referencedColumnName = "id_projet") + private Projets projetsPropose; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_rdv") + private RendezVous rendezVousEntrepreneurs; + + public Entrepreneurs() {} + + public Entrepreneurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone, + String ecole, + boolean status_snee, + String filiere) { + super( + nom_utilisateur, + id_utilisateur, + prenom_utilisateur, + mail_principal, + mail_secondaire, + numero_telephone); + this.ecole = ecole; + this.status_snee = status_snee; + this.filiere = filiere; + } + + public String getEcole() { + return ecole; + } + + public void setEcole(String ecole) { + this.ecole = ecole; + } + + public String getFiliere() { + return filiere; + } + + public void setFiliere(String filiere) { + this.filiere = filiere; + } + + public boolean isStatus_snee() { + return status_snee; + } + + public void setStatus_snee(boolean status_snee) { + this.status_snee = status_snee; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java similarity index 86% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java index 0af17e3..4fd6ec4 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/LCSection.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.api.datatypes; +package enseirb.myinpulse.model; // TODO: is this redundant with the Section class from the database ? // TODO: In the one hand it represent the same data, and on the other it should be much lighter. diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java similarity index 70% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index a6ab98f..99c562a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.api.datatypes; +package enseirb.myinpulse.model; public class Project { int projectId; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java similarity index 68% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java index ab3387b..8eb9976 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/ProjectDecision.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.api.datatypes; +package enseirb.myinpulse.model; public class ProjectDecision { int projectId; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java similarity index 94% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java index e543549..2cc6a81 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Projets.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java @@ -1,98 +1,98 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "projets") -public class Projets { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_projet; - - @Column(length = 255) - private String nom_projet; - - private byte[] logo; - - private LocalDate date_creation; - - @Column(length = 255) - private String status_projet; - - @OneToMany(mappedBy = "projetsAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List listAdministrateurs = new ArrayList<>(); - - @OneToMany(mappedBy = "projetsParticipation", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneursParticipation = new ArrayList<>(); - - @OneToOne(mappedBy = "projetsPropose", fetch = FetchType.LAZY, orphanRemoval = true) - private Entrepreneurs entrepreneursPropose; - - @OneToMany(mappedBy = "projetsSections", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); - - // Hibernate expects entities to have a no-arg constructor, - // though it does not necessarily have to be public. - - public Projets() {} - - public Projets( - Long id_projet, - String nom_projet, - byte[] logo, - LocalDate date_creation, - String status_projet) { - this.id_projet = id_projet; - this.nom_projet = nom_projet; - this.logo = logo; - this.date_creation = date_creation; - this.status_projet = status_projet; - } - - public Long getId_projet() { - return id_projet; - } - - public void setId_projet(Long id_projet) { - this.id_projet = id_projet; - } - - public String getNom_projet() { - return nom_projet; - } - - public void setNom_projet(String nom_projet) { - this.nom_projet = nom_projet; - } - - public byte[] getLogo() { - return logo; - } - - public void setLogo(byte[] logo) { - this.logo = logo; - } - - public LocalDate getDate_creation() { - return date_creation; - } - - public void setDate_creation(LocalDate date_creation) { - this.date_creation = date_creation; - } - - public String getStatus_projet() { - return status_projet; - } - - public void setStatus_projet(String status_projet) { - this.status_projet = status_projet; - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "projets") +public class Projets { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_projet; + + @Column(length = 255) + private String nom_projet; + + private byte[] logo; + + private LocalDate date_creation; + + @Column(length = 255) + private String status_projet; + + @OneToMany(mappedBy = "projetsAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private List listAdministrateurs = new ArrayList<>(); + + @OneToMany(mappedBy = "projetsParticipation", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListEntrepreneursParticipation = new ArrayList<>(); + + @OneToOne(mappedBy = "projetsPropose", fetch = FetchType.LAZY, orphanRemoval = true) + private Entrepreneurs entrepreneursPropose; + + @OneToMany(mappedBy = "projetsSections", fetch = FetchType.LAZY, orphanRemoval = true) + private List ListSections = new ArrayList<>(); + + // Hibernate expects entities to have a no-arg constructor, + // though it does not necessarily have to be public. + + public Projets() {} + + public Projets( + Long id_projet, + String nom_projet, + byte[] logo, + LocalDate date_creation, + String status_projet) { + this.id_projet = id_projet; + this.nom_projet = nom_projet; + this.logo = logo; + this.date_creation = date_creation; + this.status_projet = status_projet; + } + + public Long getId_projet() { + return id_projet; + } + + public void setId_projet(Long id_projet) { + this.id_projet = id_projet; + } + + public String getNom_projet() { + return nom_projet; + } + + public void setNom_projet(String nom_projet) { + this.nom_projet = nom_projet; + } + + public byte[] getLogo() { + return logo; + } + + public void setLogo(byte[] logo) { + this.logo = logo; + } + + public LocalDate getDate_creation() { + return date_creation; + } + + public void setDate_creation(LocalDate date_creation) { + this.date_creation = date_creation; + } + + public String getStatus_projet() { + return status_projet; + } + + public void setStatus_projet(String status_projet) { + this.status_projet = status_projet; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java similarity index 94% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java index 2763bbb..ac25b96 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/RendezVous.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java @@ -1,111 +1,111 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "rendez_vous") -public class RendezVous { - - @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) - private final List ListEntrepreneurs = new ArrayList<>(); - - @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private final List ListAdministrateurs = new ArrayList<>(); - - @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) - private final List ListComptesRendus = new ArrayList<>(); - - @ManyToMany( - fetch = FetchType.LAZY, - cascade = {CascadeType.ALL}) - @JoinTable( - name = "concerner", - joinColumns = @JoinColumn(name = "id_rdv"), - inverseJoinColumns = @JoinColumn(name = "id_section")) - List ListSections = new ArrayList<>(); - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_rdv; - - private LocalDate date_rdv; - private LocalTime heure_rdv; - private LocalTime duree_rdv; - - @Column(length = 255) - private String lieu_rdv; - - private String sujet_rdv; - - public RendezVous() {} - - public RendezVous( - Long id_rdv, - LocalDate date_rdv, - LocalTime heure_rdv, - LocalTime duree_rdv, - String lieu_rdv, - String sujet_rdv) { - this.id_rdv = id_rdv; - this.date_rdv = date_rdv; - this.heure_rdv = heure_rdv; - this.duree_rdv = duree_rdv; - this.lieu_rdv = lieu_rdv; - this.sujet_rdv = sujet_rdv; - } - - public Long getId_rdv() { - return id_rdv; - } - - public void setId_rdv(Long id_rdv) { - this.id_rdv = id_rdv; - } - - public LocalDate getDate_rdv() { - return date_rdv; - } - - public void setDate_rdv(LocalDate date_rdv) { - this.date_rdv = date_rdv; - } - - public LocalTime getHeure_rdv() { - return heure_rdv; - } - - public void setHeure_rdv(LocalTime heure_rdv) { - this.heure_rdv = heure_rdv; - } - - public LocalTime getDuree_rdv() { - return duree_rdv; - } - - public void setDuree_rdv(LocalTime duree_rdv) { - this.duree_rdv = duree_rdv; - } - - public String getLieu_rdv() { - return lieu_rdv; - } - - public void setLieu_rdv(String lieu_rdv) { - this.lieu_rdv = lieu_rdv; - } - - public String getSujet_rdv() { - return sujet_rdv; - } - - public void setSujet_rdv(String sujet_rdv) { - this.sujet_rdv = sujet_rdv; - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "rendez_vous") +public class RendezVous { + + @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) + private final List ListEntrepreneurs = new ArrayList<>(); + + @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) + private final List ListAdministrateurs = new ArrayList<>(); + + @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) + private final List ListComptesRendus = new ArrayList<>(); + + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.ALL}) + @JoinTable( + name = "concerner", + joinColumns = @JoinColumn(name = "id_rdv"), + inverseJoinColumns = @JoinColumn(name = "id_section")) + List ListSections = new ArrayList<>(); + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_rdv; + + private LocalDate date_rdv; + private LocalTime heure_rdv; + private LocalTime duree_rdv; + + @Column(length = 255) + private String lieu_rdv; + + private String sujet_rdv; + + public RendezVous() {} + + public RendezVous( + Long id_rdv, + LocalDate date_rdv, + LocalTime heure_rdv, + LocalTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { + this.id_rdv = id_rdv; + this.date_rdv = date_rdv; + this.heure_rdv = heure_rdv; + this.duree_rdv = duree_rdv; + this.lieu_rdv = lieu_rdv; + this.sujet_rdv = sujet_rdv; + } + + public Long getId_rdv() { + return id_rdv; + } + + public void setId_rdv(Long id_rdv) { + this.id_rdv = id_rdv; + } + + public LocalDate getDate_rdv() { + return date_rdv; + } + + public void setDate_rdv(LocalDate date_rdv) { + this.date_rdv = date_rdv; + } + + public LocalTime getHeure_rdv() { + return heure_rdv; + } + + public void setHeure_rdv(LocalTime heure_rdv) { + this.heure_rdv = heure_rdv; + } + + public LocalTime getDuree_rdv() { + return duree_rdv; + } + + public void setDuree_rdv(LocalTime duree_rdv) { + this.duree_rdv = duree_rdv; + } + + public String getLieu_rdv() { + return lieu_rdv; + } + + public void setLieu_rdv(String lieu_rdv) { + this.lieu_rdv = lieu_rdv; + } + + public String getSujet_rdv() { + return sujet_rdv; + } + + public void setSujet_rdv(String sujet_rdv) { + this.sujet_rdv = sujet_rdv; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java similarity index 63% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java index 3656014..7270115 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/api/datatypes/Report.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.api.datatypes; +package enseirb.myinpulse.model; public class Report { int projectId; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RoleRepresentation.java similarity index 68% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/RoleRepresentation.java index a6252a9..472c25b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/RoleRepresentation.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RoleRepresentation.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.utils.keycloak.datatypes; +package enseirb.myinpulse.model; public class RoleRepresentation { public String id; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java similarity index 93% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java index 6e56fce..6aef759 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Sections.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java @@ -1,81 +1,81 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "sections") -public class Sections { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_section; - - @Column(length = 255) - private String titre; - - private String contenu_section; - - private LocalDateTime date_modification; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet") - private Projets projetsSections; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_admnistrateur") - private Administrateurs administrateursSections; - - @ManyToMany(mappedBy = "ListSections") - private List rendezVous = new ArrayList<>(); - - public Sections() {} - - public Sections( - Long id_section, - String titre, - String contenu_section, - LocalDateTime date_modification) { - this.id_section = id_section; - this.titre = titre; - this.contenu_section = contenu_section; - this.date_modification = date_modification; - } - - public String getTitre() { - return titre; - } - - public void setTitre(String titre) { - this.titre = titre; - } - - public Long getId_section() { - return id_section; - } - - public void setId_section(Long id_section) { - this.id_section = id_section; - } - - public String getContenu_section() { - return contenu_section; - } - - public void setContenu_section(String contenu_section) { - this.contenu_section = contenu_section; - } - - public LocalDateTime getDate_modification() { - return date_modification; - } - - public void setDate_modification(LocalDateTime date_modification) { - this.date_modification = date_modification; - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "sections") +public class Sections { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_section; + + @Column(length = 255) + private String titre; + + private String contenu_section; + + private LocalDateTime date_modification; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_projet") + private Projets projetsSections; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id_admnistrateur") + private Administrateurs administrateursSections; + + @ManyToMany(mappedBy = "ListSections") + private List rendezVous = new ArrayList<>(); + + public Sections() {} + + public Sections( + Long id_section, + String titre, + String contenu_section, + LocalDateTime date_modification) { + this.id_section = id_section; + this.titre = titre; + this.contenu_section = contenu_section; + this.date_modification = date_modification; + } + + public String getTitre() { + return titre; + } + + public void setTitre(String titre) { + this.titre = titre; + } + + public Long getId_section() { + return id_section; + } + + public void setId_section(Long id_section) { + this.id_section = id_section; + } + + public String getContenu_section() { + return contenu_section; + } + + public void setContenu_section(String contenu_section) { + this.contenu_section = contenu_section; + } + + public LocalDateTime getDate_modification() { + return date_modification; + } + + public void setDate_modification(LocalDateTime date_modification) { + this.date_modification = date_modification; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/UserRepresentation.java similarity index 61% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/UserRepresentation.java index f2c3522..995b417 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/datatypes/UserRepresentation.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/UserRepresentation.java @@ -1,4 +1,4 @@ -package enseirb.myinpulse.utils.keycloak.datatypes; +package enseirb.myinpulse.model; public class UserRepresentation { public String id; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java similarity index 94% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java index 478b9ef..11dd163 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/model/Utilisateurs.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java @@ -1,95 +1,95 @@ -package enseirb.myinpulse.postgres_db.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -@Entity -@Table(name = "utilisateurs") -@Inheritance(strategy = InheritanceType.JOINED) -public class Utilisateurs { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_utilisateur; - - @Column(length = 255) - private String nom_utilisateur; - - @Column(length = 255) - private String prenom_utilisateur; - - @Column(length = 255) - private String mail_principal; - - @Column(length = 255) - private String mail_secondaire; - - @Column(length = 20) - private String numero_telephone; - - public Utilisateurs() {} - - public Utilisateurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - this.nom_utilisateur = nom_utilisateur; - this.id_utilisateur = id_utilisateur; - this.prenom_utilisateur = prenom_utilisateur; - this.mail_principal = mail_principal; - this.mail_secondaire = mail_secondaire; - this.numero_telephone = numero_telephone; - } - - public Long getId_utilisateur() { - return id_utilisateur; - } - - public void setId_utilisateur(Long id_utilisateur) { - this.id_utilisateur = id_utilisateur; - } - - public String getNom_utilisateur() { - return nom_utilisateur; - } - - public void setNom_utilisateur(String nom_utilisateur) { - this.nom_utilisateur = nom_utilisateur; - } - - public String getPrenom_utilisateur() { - return prenom_utilisateur; - } - - public void setPrenom_utilisateur(String prenom_utilisateur) { - this.prenom_utilisateur = prenom_utilisateur; - } - - public String getMail_principal() { - return mail_principal; - } - - public void setMail_principal(String mail_principal) { - this.mail_principal = mail_principal; - } - - public String getMail_secondaire() { - return mail_secondaire; - } - - public void setMail_secondaire(String mail_secondaire) { - this.mail_secondaire = mail_secondaire; - } - - public String getNumero_telephone() { - return numero_telephone; - } - - public void setNumero_telephone(String numero_telephone) { - this.numero_telephone = numero_telephone; - } -} +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "utilisateurs") +@Inheritance(strategy = InheritanceType.JOINED) +public class Utilisateurs { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id_utilisateur; + + @Column(length = 255) + private String nom_utilisateur; + + @Column(length = 255) + private String prenom_utilisateur; + + @Column(length = 255) + private String mail_principal; + + @Column(length = 255) + private String mail_secondaire; + + @Column(length = 20) + private String numero_telephone; + + public Utilisateurs() {} + + public Utilisateurs( + String nom_utilisateur, + Long id_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + this.nom_utilisateur = nom_utilisateur; + this.id_utilisateur = id_utilisateur; + this.prenom_utilisateur = prenom_utilisateur; + this.mail_principal = mail_principal; + this.mail_secondaire = mail_secondaire; + this.numero_telephone = numero_telephone; + } + + public Long getId_utilisateur() { + return id_utilisateur; + } + + public void setId_utilisateur(Long id_utilisateur) { + this.id_utilisateur = id_utilisateur; + } + + public String getNom_utilisateur() { + return nom_utilisateur; + } + + public void setNom_utilisateur(String nom_utilisateur) { + this.nom_utilisateur = nom_utilisateur; + } + + public String getPrenom_utilisateur() { + return prenom_utilisateur; + } + + public void setPrenom_utilisateur(String prenom_utilisateur) { + this.prenom_utilisateur = prenom_utilisateur; + } + + public String getMail_principal() { + return mail_principal; + } + + public void setMail_principal(String mail_principal) { + this.mail_principal = mail_principal; + } + + public String getMail_secondaire() { + return mail_secondaire; + } + + public void setMail_secondaire(String mail_secondaire) { + this.mail_secondaire = mail_secondaire; + } + + public String getNumero_telephone() { + return numero_telephone; + } + + public void setNumero_telephone(String numero_telephone) { + this.numero_telephone = numero_telephone; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java deleted file mode 100644 index 21358f3..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ComptesRendusController.java +++ /dev/null @@ -1,52 +0,0 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.ComptesRendus; -import enseirb.myinpulse.postgres_db.repository.ComptesRendusRepository; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class ComptesRendusController { - - private final ComptesRendusRepository comptesRendusRepository; - - public ComptesRendusController(ComptesRendusRepository comptesRendusRepository) { - this.comptesRendusRepository = comptesRendusRepository; - } - - @GetMapping("/ComptesRendus") - @ResponseBody - public Iterable allComptesRendus() { - return this.comptesRendusRepository.findAll(); - } - - @GetMapping("/ComptesRendus/{id}") - public ComptesRendus getComptesRendusById(@PathVariable Long id) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - return compteRendu.get(); - } - - @PostMapping("/ComptesRendus") - public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { - return this.comptesRendusRepository.save(comptesRendus); - } - - @PostMapping("/ComptesRendus/{id}") - public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - if (contenu_compte_rendu != null) { - compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); - } - return this.comptesRendusRepository.save(compteRendu.get()); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java similarity index 74% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java index 0454e64..543778e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/AdministrateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java @@ -1,14 +1,14 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.Administrateurs; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface AdministrateursRepository extends JpaRepository { - - /* @Query("SELECT a from Administrateurs a") - Administrateurs findAllAdministrateurs(); */ - -} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Administrateurs; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface AdministrateursRepository extends JpaRepository { + + /* @Query("SELECT a from Administrateurs a") + Administrateurs findAllAdministrateurs(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ComptesRendusRepository.java similarity index 62% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ComptesRendusRepository.java index 168fd87..60e0017 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ComptesRendusRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ComptesRendusRepository.java @@ -1,9 +1,9 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.ComptesRendus; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface ComptesRendusRepository extends JpaRepository {} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.ComptesRendus; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface ComptesRendusRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java similarity index 74% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java index fc288f5..6a957f6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/EntrepreneursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java @@ -1,14 +1,14 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.Entrepreneurs; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface EntrepreneursRepository extends JpaRepository { - - /* @Query("SELECT e from Entrepreneurs e") - Entrepreneurs findAllEntrepreneurs(); */ - -} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Entrepreneurs; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface EntrepreneursRepository extends JpaRepository { + + /* @Query("SELECT e from Entrepreneurs e") + Entrepreneurs findAllEntrepreneurs(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjetsRepository.java similarity index 68% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjetsRepository.java index d9d2e59..9d045d6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/ProjetsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjetsRepository.java @@ -1,9 +1,9 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.Projets; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface ProjetsRepository extends JpaRepository {} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Projets; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface ProjetsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/RendezVousRepository.java similarity index 68% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/RendezVousRepository.java index 2856de3..127c2cb 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/RendezVousRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/RendezVousRepository.java @@ -1,9 +1,9 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.RendezVous; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface RendezVousRepository extends JpaRepository {} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.RendezVous; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface RendezVousRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionsRepository.java similarity index 68% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionsRepository.java index 4d68027..2ccff00 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/SectionsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionsRepository.java @@ -1,9 +1,9 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.Sections; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface SectionsRepository extends JpaRepository {} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Sections; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface SectionsRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java similarity index 73% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java index de8371c..16f04c7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/repository/UtilisateursRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java @@ -1,14 +1,14 @@ -package enseirb.myinpulse.postgres_db.repository; - -import enseirb.myinpulse.postgres_db.model.Utilisateurs; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface UtilisateursRepository extends JpaRepository { - - /* @Query("SELECT u from Utilisateurs u") - Utilisateurs findAllUtilisateurs(); */ - -} +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Utilisateurs; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface UtilisateursRepository extends JpaRepository { + + /* @Query("SELECT u from Utilisateurs u") + Utilisateurs findAllUtilisateurs(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java new file mode 100644 index 0000000..273e9cb --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -0,0 +1,46 @@ +package enseirb.myinpulse.service; + +import enseirb.myinpulse.model.*; + +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +@Service +public class AdminApiService { + // TODO + public Iterable getProjects() { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + // TODO + public Iterable getUpcomingAppointments() { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + // TODO + public Iterable getPendingProjects() { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + // TODO + public void validateProject(ProjectDecision decision) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + // TODO + public void addNewProject(Project project) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + // TODO + public void createAppointmentReport(String appointmentId, Report report) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + // TODO + public void deleteProject(String projectId) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java new file mode 100644 index 0000000..adb17e6 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -0,0 +1,29 @@ +package enseirb.myinpulse.service; + +import enseirb.myinpulse.model.LCSection; +import enseirb.myinpulse.model.Project; + +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +@Service +public class EntrepreneurApiService { + + public void editLCSection(String sectionId, LCSection section) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public void removeLCSection(String sectionId) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public void addLCSection(String sectionId, LCSection section) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public void requestNewProject(Project project) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/KeycloakApi.java similarity index 94% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/KeycloakApi.java index ff6dde2..fb97c70 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/utils/keycloak/KeycloakApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/KeycloakApi.java @@ -1,10 +1,10 @@ -package enseirb.myinpulse.utils.keycloak; +package enseirb.myinpulse.service; import static org.springframework.http.MediaType.APPLICATION_JSON; -import enseirb.myinpulse.exceptions.UserNotFoundException; -import enseirb.myinpulse.utils.keycloak.datatypes.RoleRepresentation; -import enseirb.myinpulse.utils.keycloak.datatypes.UserRepresentation; +import enseirb.myinpulse.exception.UserNotFoundException; +import enseirb.myinpulse.model.RoleRepresentation; +import enseirb.myinpulse.model.UserRepresentation; import org.springframework.web.client.RestClient; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java new file mode 100644 index 0000000..f750a59 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -0,0 +1,36 @@ +package enseirb.myinpulse.service; + +import enseirb.myinpulse.model.*; + +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +@Service +public class SharedApiService { + + public Iterable getLCSection(String projectId, String title, String date) { + + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public Iterable getEntrepreneursByProjectId(int projectId) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public Iterable getAdminByProjectId(int projectId) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public Iterable getAppointmentsByProjectId(int projectId) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public void getPDFReport(int appointmentId) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } + + public void createAppointmentRequest(Appointment appointment) { + throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java new file mode 100644 index 0000000..7355099 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java @@ -0,0 +1,34 @@ +package enseirb.myinpulse.service.database; + +import enseirb.myinpulse.model.ComptesRendus; +import enseirb.myinpulse.repository.ComptesRendusRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@Service +public class CompteRenduService { + private final ComptesRendusRepository comptesRendusRepository; + + @Autowired + CompteRenduService(ComptesRendusRepository comptesRendusRepository) { + this.comptesRendusRepository = comptesRendusRepository; + } + + ComptesRendus getComptesRendusById(int id) { + Optional compteRendu = comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + return compteRendu.get(); + } + + // TODO: do some validation + void saveCompteRendu(ComptesRendus compteRendu) { + comptesRendusRepository.save(compteRendu); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java similarity index 84% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java index b9a8259..8a96924 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/AdministrateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java @@ -1,38 +1,38 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.Administrateurs; -import enseirb.myinpulse.postgres_db.repository.AdministrateursRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class AdministrateursController { - - @Autowired AdministrateursRepository administrateursRepository; - - @GetMapping("/Administrateurs") - @ResponseBody - public Iterable allAdministrateurs() { - return this.administrateursRepository.findAll(); - } - - @GetMapping("/Administrateurs/{id}") - public Administrateurs getAdministrateursById(@PathVariable Long id) { - Optional administrateur = this.administrateursRepository.findById(id); - if (administrateur.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); - } - return administrateur.get(); - } - - @PostMapping("/Administrateurs") - public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { - return this.administrateursRepository.save(administrateurs); - } -} +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Administrateurs; +import enseirb.myinpulse.repository.AdministrateursRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class AdministrateursController { + + @Autowired AdministrateursRepository administrateursRepository; + + @GetMapping("/Administrateurs") + @ResponseBody + public Iterable allAdministrateurs() { + return this.administrateursRepository.findAll(); + } + + @GetMapping("/Administrateurs/{id}") + public Administrateurs getAdministrateursById(@PathVariable Long id) { + Optional administrateur = this.administrateursRepository.findById(id); + if (administrateur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + return administrateur.get(); + } + + @PostMapping("/Administrateurs") + public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { + return this.administrateursRepository.save(administrateurs); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java new file mode 100644 index 0000000..1567b6d --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java @@ -0,0 +1,43 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import org.springframework.web.bind.annotation.*; + +@RestController +public class ComptesRendusController { + /* + private final ComptesRendusRepository comptesRendusRepository; + + @Autowired + public ComptesRendusController(ComptesRendusRepository comptesRendusRepository) { + this.comptesRendusRepository = comptesRendusRepository; + } + + @GetMapping("/ComptesRendus") + @ResponseBody + public Iterable allComptesRendus() { + System.out.println("\n\n"); + System.out.println(comptesRendusRepository); + System.out.println("\n\n"); + return this.comptesRendusRepository.findAll(); + } + + + @PostMapping("/ComptesRendus") + public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { + return this.comptesRendusRepository.save(comptesRendus); + } + + @PostMapping("/ComptesRendus/{id}") + public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { + Optional compteRendu = this.comptesRendusRepository.findById(id); + if (compteRendu.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + if (contenu_compte_rendu != null) { + compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); + } + return this.comptesRendusRepository.save(compteRendu.get()); + } + + */ +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java similarity index 89% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java index d97298c..4a21078 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/EntrepreneursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java @@ -1,58 +1,58 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.Entrepreneurs; -import enseirb.myinpulse.postgres_db.repository.EntrepreneursRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class EntrepreneursController { - - @Autowired EntrepreneursRepository entrepreneursRepository; - - @GetMapping("/Entrepreneurs") - @ResponseBody - public Iterable allEntrepreneurs() { - return this.entrepreneursRepository.findAll(); - } - - @GetMapping("/Entrepreneurs/{id}") - public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); - } - return entrepreneur.get(); - } - - @PostMapping("/Entrepreneurs") - public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { - return this.entrepreneursRepository.save(entrepreneurs); - } - - @PostMapping("/Entrepreneurs/{id}") - public Entrepreneurs updateEntrepreneurs( - @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); - } - if (ecole != null) { - entrepreneur.get().setEcole(ecole); - } - if (filiere != null) { - entrepreneur.get().setFiliere(filiere); - } - if (status_snee != null) { - entrepreneur.get().setStatus_snee(status_snee); - } - return this.entrepreneursRepository.save(entrepreneur.get()); - } -} +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Entrepreneurs; +import enseirb.myinpulse.repository.EntrepreneursRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class EntrepreneursController { + + @Autowired EntrepreneursRepository entrepreneursRepository; + + @GetMapping("/Entrepreneurs") + @ResponseBody + public Iterable allEntrepreneurs() { + return this.entrepreneursRepository.findAll(); + } + + @GetMapping("/Entrepreneurs/{id}") + public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + return entrepreneur.get(); + } + + @PostMapping("/Entrepreneurs") + public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { + return this.entrepreneursRepository.save(entrepreneurs); + } + + @PostMapping("/Entrepreneurs/{id}") + public Entrepreneurs updateEntrepreneurs( + @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { + Optional entrepreneur = entrepreneursRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + if (ecole != null) { + entrepreneur.get().setEcole(ecole); + } + if (filiere != null) { + entrepreneur.get().setFiliere(filiere); + } + if (status_snee != null) { + entrepreneur.get().setStatus_snee(status_snee); + } + return this.entrepreneursRepository.save(entrepreneur.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java similarity index 89% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java index b6bb230..f33edbc 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/ProjetsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java @@ -1,64 +1,64 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.Projets; -import enseirb.myinpulse.postgres_db.repository.ProjetsRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDate; -import java.util.Optional; - -@RestController -public class ProjetsController { - - @Autowired ProjetsRepository projetsRepository; - - @GetMapping("/Projets") - @ResponseBody - public Iterable allProjets() { - return this.projetsRepository.findAll(); - } - - @GetMapping("/Projets/{id}") - public Projets getProjetsById(@PathVariable Long id) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); - } - return projet.get(); - } - - @PostMapping("/Projets") - public Projets addProjets(@RequestBody Projets projet) { - return this.projetsRepository.save(projet); - } - - @PostMapping("/Projets/{id}") - public Projets updateProjets( - @PathVariable Long id, - String nom_projet, - byte[] logo, - LocalDate date_creation, - String status_projet) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); - } - if (nom_projet != null) { - projet.get().setNom_projet(nom_projet); - } - if (logo != null) { - projet.get().setLogo(logo); - } - if (date_creation != null) { - projet.get().setDate_creation(date_creation); - } - if (status_projet != null) { - projet.get().setStatus_projet(status_projet); - } - return this.projetsRepository.save(projet.get()); - } -} +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Projets; +import enseirb.myinpulse.repository.ProjetsRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.util.Optional; + +@RestController +public class ProjetsController { + + @Autowired ProjetsRepository projetsRepository; + + @GetMapping("/Projets") + @ResponseBody + public Iterable allProjets() { + return this.projetsRepository.findAll(); + } + + @GetMapping("/Projets/{id}") + public Projets getProjetsById(@PathVariable Long id) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + return projet.get(); + } + + @PostMapping("/Projets") + public Projets addProjets(@RequestBody Projets projet) { + return this.projetsRepository.save(projet); + } + + @PostMapping("/Projets/{id}") + public Projets updateProjets( + @PathVariable Long id, + String nom_projet, + byte[] logo, + LocalDate date_creation, + String status_projet) { + Optional projet = this.projetsRepository.findById(id); + if (projet.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + if (nom_projet != null) { + projet.get().setNom_projet(nom_projet); + } + if (logo != null) { + projet.get().setLogo(logo); + } + if (date_creation != null) { + projet.get().setDate_creation(date_creation); + } + if (status_projet != null) { + projet.get().setStatus_projet(status_projet); + } + return this.projetsRepository.save(projet.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java similarity index 89% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java index 9761fd9..522db14 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/RendezVousController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java @@ -1,67 +1,69 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.RendezVous; -import enseirb.myinpulse.postgres_db.repository.RendezVousRepository; -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.Optional; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -@RestController -public class RendezVousController { - - @Autowired RendezVousRepository rendezVousRepository; - - @GetMapping("/RendezVous") - @ResponseBody - public Iterable allRendezVous() { - return this.rendezVousRepository.findAll(); - } - - @GetMapping("/RendezVous/{id}") - public RendezVous getRendezVousById(@PathVariable Long id) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - return rendezVous.get(); - } - - @PostMapping("/RendezVous") - public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { - return this.rendezVousRepository.save(rendezVous); - } - - @PostMapping("/RendezVous/{id}") - public RendezVous updateRendezVous( - @PathVariable Long id, - LocalDate date_rdv, - LocalTime heure_rdv, - LocalTime duree_rdv, - String lieu_rdv, - String sujet_rdv) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - if (date_rdv != null) { - rendezVous.get().setDate_rdv(date_rdv); - } - if (heure_rdv != null) { - rendezVous.get().setHeure_rdv(heure_rdv); - } - if (duree_rdv != null) { - rendezVous.get().setDuree_rdv(duree_rdv); - } - if (lieu_rdv != null) { - rendezVous.get().setLieu_rdv(lieu_rdv); - } - if (sujet_rdv != null) { - rendezVous.get().setSujet_rdv(sujet_rdv); - } - return this.rendezVousRepository.save(rendezVous.get()); - } -} +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.RendezVous; +import enseirb.myinpulse.repository.RendezVousRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Optional; + +@RestController +public class RendezVousController { + + @Autowired RendezVousRepository rendezVousRepository; + + @GetMapping("/RendezVous") + @ResponseBody + public Iterable allRendezVous() { + return this.rendezVousRepository.findAll(); + } + + @GetMapping("/RendezVous/{id}") + public RendezVous getRendezVousById(@PathVariable Long id) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + return rendezVous.get(); + } + + @PostMapping("/RendezVous") + public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { + return this.rendezVousRepository.save(rendezVous); + } + + @PostMapping("/RendezVous/{id}") + public RendezVous updateRendezVous( + @PathVariable Long id, + LocalDate date_rdv, + LocalTime heure_rdv, + LocalTime duree_rdv, + String lieu_rdv, + String sujet_rdv) { + Optional rendezVous = this.rendezVousRepository.findById(id); + if (rendezVous.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + if (date_rdv != null) { + rendezVous.get().setDate_rdv(date_rdv); + } + if (heure_rdv != null) { + rendezVous.get().setHeure_rdv(heure_rdv); + } + if (duree_rdv != null) { + rendezVous.get().setDuree_rdv(duree_rdv); + } + if (lieu_rdv != null) { + rendezVous.get().setLieu_rdv(lieu_rdv); + } + if (sujet_rdv != null) { + rendezVous.get().setSujet_rdv(sujet_rdv); + } + return this.rendezVousRepository.save(rendezVous.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java similarity index 88% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java index 716d434..d3009c6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/SectionsController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java @@ -1,60 +1,60 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.Sections; -import enseirb.myinpulse.postgres_db.repository.SectionsRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDateTime; -import java.util.Optional; - -@RestController -public class SectionsController { - - @Autowired SectionsRepository sectionsRepository; - - @GetMapping("/Sections") - @ResponseBody - public Iterable allSections() { - return this.sectionsRepository.findAll(); - } - - @GetMapping("/Sections/{id}") - public Sections getSectionsById(@PathVariable Long id) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); - } - return section.get(); - } - - @PostMapping("/Sections") - public Sections addSections(@RequestBody Sections sections) { - return this.sectionsRepository.save(sections); - } - - @PostMapping("/Sections/{id}") - public Sections updateSections( - @PathVariable Long id, - String titre, - String contenu_section, - LocalDateTime date_modification) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); - } - if (titre != null) { - section.get().setTitre(titre); - } - if (contenu_section != null) { - section.get().setContenu_section(contenu_section); - } - if (date_modification != null) { - section.get().setDate_modification(date_modification); - } - return this.sectionsRepository.save(section.get()); - } -} +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Sections; +import enseirb.myinpulse.repository.SectionsRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDateTime; +import java.util.Optional; + +@RestController +public class SectionsController { + + @Autowired SectionsRepository sectionsRepository; + + @GetMapping("/Sections") + @ResponseBody + public Iterable allSections() { + return this.sectionsRepository.findAll(); + } + + @GetMapping("/Sections/{id}") + public Sections getSectionsById(@PathVariable Long id) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + } + return section.get(); + } + + @PostMapping("/Sections") + public Sections addSections(@RequestBody Sections sections) { + return this.sectionsRepository.save(sections); + } + + @PostMapping("/Sections/{id}") + public Sections updateSections( + @PathVariable Long id, + String titre, + String contenu_section, + LocalDateTime date_modification) { + Optional section = this.sectionsRepository.findById(id); + if (section.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); + } + if (titre != null) { + section.get().setTitre(titre); + } + if (contenu_section != null) { + section.get().setContenu_section(contenu_section); + } + if (date_modification != null) { + section.get().setDate_modification(date_modification); + } + return this.sectionsRepository.save(section.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java similarity index 90% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java index 410b5b5..ce0a66a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/postgres_db/controller/UtilisateursController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java @@ -1,67 +1,67 @@ -package enseirb.myinpulse.postgres_db.controller; - -import enseirb.myinpulse.postgres_db.model.Utilisateurs; -import enseirb.myinpulse.postgres_db.repository.UtilisateursRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class UtilisateursController { - - @Autowired UtilisateursRepository utilisateursRepository; - - @GetMapping("/Utilisateurs") - @ResponseBody - public Iterable allUtilisateurs() { - return this.utilisateursRepository.findAll(); - } - - @GetMapping("/Utilisateurs/{id}") - public Utilisateurs getUtilisateursById(@PathVariable Long id) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - return utilisateur.get(); - } - - @PostMapping("/Utilisateurs") - public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { - return this.utilisateursRepository.save(utilisateurs); - } - - @PostMapping("/Utilisateurs/{id}") - public Utilisateurs updateUtilisateurs( - @PathVariable Long id, - String nom_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - if (nom_utilisateur != null) { - utilisateur.get().setNom_utilisateur(nom_utilisateur); - } - if (prenom_utilisateur != null) { - utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); - } - if (mail_principal != null) { - utilisateur.get().setMail_principal(mail_principal); - } - if (mail_secondaire != null) { - utilisateur.get().setMail_secondaire(mail_secondaire); - } - if (numero_telephone != null) { - utilisateur.get().setNumero_telephone(numero_telephone); - } - return this.utilisateursRepository.save(utilisateur.get()); - } -} +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Utilisateurs; +import enseirb.myinpulse.repository.UtilisateursRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class UtilisateursController { + + @Autowired UtilisateursRepository utilisateursRepository; + + @GetMapping("/Utilisateurs") + @ResponseBody + public Iterable allUtilisateurs() { + return this.utilisateursRepository.findAll(); + } + + @GetMapping("/Utilisateurs/{id}") + public Utilisateurs getUtilisateursById(@PathVariable Long id) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + return utilisateur.get(); + } + + @PostMapping("/Utilisateurs") + public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { + return this.utilisateursRepository.save(utilisateurs); + } + + @PostMapping("/Utilisateurs/{id}") + public Utilisateurs updateUtilisateurs( + @PathVariable Long id, + String nom_utilisateur, + String prenom_utilisateur, + String mail_principal, + String mail_secondaire, + String numero_telephone) { + Optional utilisateur = utilisateursRepository.findById(id); + if (utilisateur.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + if (nom_utilisateur != null) { + utilisateur.get().setNom_utilisateur(nom_utilisateur); + } + if (prenom_utilisateur != null) { + utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); + } + if (mail_principal != null) { + utilisateur.get().setMail_principal(mail_principal); + } + if (mail_secondaire != null) { + utilisateur.get().setMail_secondaire(mail_secondaire); + } + if (numero_telephone != null) { + utilisateur.get().setNumero_telephone(numero_telephone); + } + return this.utilisateursRepository.save(utilisateur.get()); + } +} -- 2.47.2 From 4698aa549f5f575a293ec1d850bae8a960b0c838 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 19 Feb 2025 12:09:37 +0100 Subject: [PATCH 44/97] feat: frontend call now include the token and send the email from the token to backen servie --- .../myinpulse/controller/AdminApi.java | 19 +++++--- .../myinpulse/controller/EntrepreneurApi.java | 28 +++++++---- .../myinpulse/controller/SharedApi.java | 47 ++++++++++--------- .../myinpulse/service/AdminApiService.java | 6 +-- .../service/EntrepreneurApiService.java | 8 ++-- .../myinpulse/service/SharedApiService.java | 14 +++--- 6 files changed, 72 insertions(+), 50 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java index 1a2a12a..76186b7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java @@ -5,6 +5,8 @@ import enseirb.myinpulse.service.AdminApiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.*; @SpringBootApplication @@ -24,8 +26,8 @@ public class AdminApi { * @return a list of all project managed by the current admin user */ @GetMapping("/admin/projects") - public Iterable getProjects() { - return adminApiService.getProjects(); + public Iterable getProjects(@AuthenticationPrincipal Jwt principal) { + return adminApiService.getProjects(principal.getClaimAsString("email")); } /** @@ -34,8 +36,8 @@ public class AdminApi { * @return a list of upcoming appointments for the current user */ @GetMapping("/admin/appointments/upcoming") - public Iterable getUpcomingAppointments() { - return adminApiService.getUpcomingAppointments(); + public Iterable getUpcomingAppointments(@AuthenticationPrincipal Jwt principal) { + return adminApiService.getUpcomingAppointments(principal.getClaimAsString("email")); } /** @@ -51,6 +53,8 @@ public class AdminApi { /** * Endpoint used to make a decision about a project. * + *

The decision must contains the administrator + * * @return the status code of the request */ @PostMapping("/admin/projects/decision") @@ -77,8 +81,11 @@ public class AdminApi { */ @PostMapping("/admin/appoitements/report/{appointmentId}") public void createAppointmentReport( - @PathVariable String appointmentId, @RequestBody Report report) { - adminApiService.createAppointmentReport(appointmentId, report); + @PathVariable String appointmentId, + @RequestBody Report report, + @AuthenticationPrincipal Jwt principal) { + adminApiService.createAppointmentReport( + appointmentId, report, principal.getClaimAsString("email")); } /** diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java index 0071c61..2ace1c7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java @@ -6,6 +6,8 @@ import enseirb.myinpulse.service.EntrepreneurApiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.*; @SpringBootApplication @@ -27,8 +29,12 @@ public class EntrepreneurApi { * @return status code */ @PutMapping("/entrepreneur/lcsection/modify/{sectionId}") - public void editLCSection(@PathVariable String sectionId, @RequestBody LCSection section) { - entrepreneurApiService.editLCSection(sectionId, section); + public void editLCSection( + @PathVariable String sectionId, + @RequestBody LCSection section, + @AuthenticationPrincipal Jwt principal) { + entrepreneurApiService.editLCSection( + sectionId, section, principal.getClaimAsString("email")); } /** @@ -39,8 +45,9 @@ public class EntrepreneurApi { * @return status code */ @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") - public void removeLCSection(@PathVariable String sectionId) { - entrepreneurApiService.removeLCSection(sectionId); + public void removeLCSection( + @PathVariable String sectionId, @AuthenticationPrincipal Jwt principal) { + entrepreneurApiService.removeLCSection(sectionId, principal.getClaimAsString("email")); } /** @@ -51,8 +58,12 @@ public class EntrepreneurApi { * @return status code */ @PostMapping("/entrepreneur/lcsection/add/{sectionId}") - public void addLCSection(@PathVariable String sectionId, @RequestBody LCSection section) { - entrepreneurApiService.addLCSection(sectionId, section); + public void addLCSection( + @PathVariable String sectionId, + @RequestBody LCSection section, + @AuthenticationPrincipal Jwt principal) { + entrepreneurApiService.addLCSection( + sectionId, section, principal.getClaimAsString("email")); } /** @@ -63,7 +74,8 @@ public class EntrepreneurApi { * @return status code */ @PostMapping("/entrepreneur/project/request") - public void requestNewProject(@RequestBody Project project) { - entrepreneurApiService.requestNewProject(project); + public void requestNewProject( + @RequestBody Project project, @AuthenticationPrincipal Jwt principal) { + entrepreneurApiService.requestNewProject(project, principal.getClaimAsString("email")); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index 038a083..bf14ca9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -8,6 +8,8 @@ import enseirb.myinpulse.service.SharedApiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.*; @SpringBootApplication @@ -34,8 +36,10 @@ public class SharedApi { public Iterable getLCSection( @PathVariable("projectId") String projectId, @PathVariable("title") String title, - @PathVariable("date") String date) { - return sharedApiService.getLCSection(projectId, title, date); + @PathVariable("date") String date, + @AuthenticationPrincipal Jwt principal) { + return sharedApiService.getLCSection( + projectId, title, date, principal.getClaimAsString("email")); } /** @@ -44,34 +48,33 @@ public class SharedApi { * @return a list of all entrepreneurs in a project */ @GetMapping("/shared/entrepreneurs/{projectId}") - public Iterable getEntrepreneursByProjectId(@PathVariable int projectId) { - return sharedApiService.getEntrepreneursByProjectId(projectId); + public Iterable getEntrepreneursByProjectId( + @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) { + return sharedApiService.getEntrepreneursByProjectId( + projectId, principal.getClaimAsString("email")); } /** - * TODO: is it really useful for the admin ? We can already get all the project of the current - * administrator. - * - *

Endpoint used to get the administrator of a project. + * Endpoint used to get the administrator of a project. * * @return a list of all project managed by the current admin user */ @GetMapping("/shared/projects/admin/{projectId}") - public Iterable getAdminByProjectId(@PathVariable int projectId) { - return sharedApiService.getAdminByProjectId(projectId); + public Iterable getAdminByProjectId( + @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) { + return sharedApiService.getAdminByProjectId(projectId, principal.getClaimAsString("email")); } /** - * TODO: Should it really be all appointments? all future appointments ? a flag to choose \\ - * TODO: between both ? - * - *

Endpoint used to get all appointments of a single project. + * Endpoint used to get all appointments of a single project. * * @return a list of all appointments. */ @GetMapping("/shared/projects/appointments/{projectId}") - public Iterable getAppointmentsByProjectId(@PathVariable int projectId) { - return sharedApiService.getAppointmentsByProjectId(projectId); + public Iterable getAppointmentsByProjectId( + @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) { + return sharedApiService.getAppointmentsByProjectId( + projectId, principal.getClaimAsString("email")); } /** @@ -80,17 +83,17 @@ public class SharedApi { * @return a PDF file? TODO: how does that works ? */ @GetMapping("/shared/projects/appointments/report/{appointmentId}") - public void getPDFReport(@PathVariable int appointmentId) { - sharedApiService.getPDFReport(appointmentId); + public void getPDFReport( + @PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) { + sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); } /** - * TODO - * * @return TODO */ @PostMapping("/shared/appointment/request") - public void createAppointmentRequest(@RequestBody Appointment appointment) { - sharedApiService.createAppointmentRequest(appointment); + public void createAppointmentRequest( + @RequestBody Appointment appointment, @AuthenticationPrincipal Jwt principal) { + sharedApiService.createAppointmentRequest(appointment, principal.getClaimAsString("email")); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 273e9cb..b30d928 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -10,12 +10,12 @@ import org.springframework.web.server.ResponseStatusException; @Service public class AdminApiService { // TODO - public Iterable getProjects() { + public Iterable getProjects(String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } // TODO - public Iterable getUpcomingAppointments() { + public Iterable getUpcomingAppointments(String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } @@ -35,7 +35,7 @@ public class AdminApiService { } // TODO - public void createAppointmentReport(String appointmentId, Report report) { + public void createAppointmentReport(String appointmentId, Report report, String email) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index adb17e6..80d06ba 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -11,19 +11,19 @@ import org.springframework.web.server.ResponseStatusException; @Service public class EntrepreneurApiService { - public void editLCSection(String sectionId, LCSection section) { + public void editLCSection(String sectionId, LCSection section, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void removeLCSection(String sectionId) { + public void removeLCSection(String sectionId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void addLCSection(String sectionId, LCSection section) { + public void addLCSection(String sectionId, LCSection section, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void requestNewProject(Project project) { + public void requestNewProject(Project project, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index f750a59..0536420 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -9,28 +9,28 @@ import org.springframework.web.server.ResponseStatusException; @Service public class SharedApiService { - public Iterable getLCSection(String projectId, String title, String date) { - + public Iterable getLCSection( + String projectId, String title, String date, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getEntrepreneursByProjectId(int projectId) { + public Iterable getEntrepreneursByProjectId(int projectId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getAdminByProjectId(int projectId) { + public Iterable getAdminByProjectId(int projectId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getAppointmentsByProjectId(int projectId) { + public Iterable getAppointmentsByProjectId(int projectId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void getPDFReport(int appointmentId) { + public void getPDFReport(int appointmentId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void createAppointmentRequest(Appointment appointment) { + public void createAppointmentRequest(Appointment appointment, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } } -- 2.47.2 From 40afde89b715c1313955f1487263ce71ddf69804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 19 Feb 2025 18:41:37 +0100 Subject: [PATCH 45/97] Fix: renamed all the tables, with repo and controller associated to them (might have missed some), and fix some key dependency issues --- .../myinpulse/controller/AdminApi.java | 10 +- .../myinpulse/controller/EntrepreneurApi.java | 4 +- .../myinpulse/controller/SharedApi.java | 18 +-- .../myinpulse/model/Administrateurs.java | 43 ------- .../myinpulse/model/Administrator.java | 43 +++++++ .../enseirb/myinpulse/model/Annotation.java | 39 ++++++ .../enseirb/myinpulse/model/Appointment.java | 112 +++++++++++++++++- .../myinpulse/model/ComptesRendus.java | 46 ------- .../myinpulse/model/DelAppointment.java | 8 ++ .../enseirb/myinpulse/model/DelProject.java | 7 ++ .../enseirb/myinpulse/model/DelReport.java | 6 + .../enseirb/myinpulse/model/Entrepreneur.java | 78 ++++++++++++ .../myinpulse/model/Entrepreneurs.java | 80 ------------- .../myinpulse/model/MakeAppointment.java | 28 +++++ .../java/enseirb/myinpulse/model/Project.java | 95 ++++++++++++++- .../java/enseirb/myinpulse/model/Projets.java | 98 --------------- .../enseirb/myinpulse/model/RendezVous.java | 111 ----------------- .../java/enseirb/myinpulse/model/Report.java | 36 +++++- .../enseirb/myinpulse/model/SectionCell.java | 85 +++++++++++++ .../enseirb/myinpulse/model/Sections.java | 81 ------------- .../java/enseirb/myinpulse/model/User.java | 95 +++++++++++++++ .../enseirb/myinpulse/model/Utilisateurs.java | 95 --------------- .../repository/AdministrateursRepository.java | 14 --- .../repository/AdministratorRepository.java | 14 +++ ...sitory.java => AppointmentRepository.java} | 4 +- .../repository/EntrepreneurRepository.java | 14 +++ .../repository/EntrepreneursRepository.java | 14 --- ...Repository.java => ProjectRepository.java} | 4 +- ...sRepository.java => ReportRepository.java} | 4 +- ...sitory.java => SectionCellRepository.java} | 4 +- .../myinpulse/repository/UserRepository.java | 14 +++ .../repository/UtilisateursRepository.java | 14 --- .../myinpulse/service/AdminApiService.java | 11 +- .../service/EntrepreneurApiService.java | 5 +- .../myinpulse/service/SharedApiService.java | 10 +- .../service/database/CompteRenduService.java | 34 ------ .../service/database/ReportService.java | 34 ++++++ .../AdministrateursController.java | 38 ------ .../AdministratorController.java | 38 ++++++ .../AppointmentController.java | 69 +++++++++++ .../ComptesRendusController.java | 43 ------- .../EntrepreneurController.java | 58 +++++++++ .../EntrepreneursController.java | 58 --------- .../ProjectController.java | 64 ++++++++++ .../ProjetsController.java | 64 ---------- .../RendezVousController.java | 69 ----------- .../ReportController.java | 43 +++++++ .../SectionCellController.java | 62 ++++++++++ .../SectionsController.java | 60 ---------- .../UserController.java | 67 +++++++++++ .../UtilisateursController.java | 67 ----------- MyINPulse-back/src/main/resources/data.sql | 8 +- MyINPulse-back/src/main/resources/delete.sql | 2 +- MyINPulse-back/src/main/resources/schema.sql | 40 +++---- 54 files changed, 1161 insertions(+), 1101 deletions(-) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/repository/{RendezVousRepository.java => AppointmentRepository.java} (61%) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java rename MyINPulse-back/src/main/java/enseirb/myinpulse/repository/{ProjetsRepository.java => ProjectRepository.java} (67%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/repository/{SectionsRepository.java => ReportRepository.java} (63%) rename MyINPulse-back/src/main/java/enseirb/myinpulse/repository/{ComptesRendusRepository.java => SectionCellRepository.java} (60%) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneurController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java index 1a2a12a..466865e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java @@ -24,7 +24,7 @@ public class AdminApi { * @return a list of all project managed by the current admin user */ @GetMapping("/admin/projects") - public Iterable getProjects() { + public Iterable getProjects() { return adminApiService.getProjects(); } @@ -34,7 +34,7 @@ public class AdminApi { * @return a list of upcoming appointments for the current user */ @GetMapping("/admin/appointments/upcoming") - public Iterable getUpcomingAppointments() { + public Iterable getUpcomingAppointments() { return adminApiService.getUpcomingAppointments(); } @@ -44,7 +44,7 @@ public class AdminApi { * @return a list of current unvalidated projects, waiting to be accepted */ @GetMapping("/admin/projects/pending") - public Iterable getPendingProjects() { + public Iterable getPendingProjects() { return adminApiService.getPendingProjects(); } @@ -64,7 +64,7 @@ public class AdminApi { * @return the status code of the request */ @PostMapping("/admin/project/add") - public void addNewProject(@RequestBody Project project) { + public void addNewProject(@RequestBody DelProject project) { adminApiService.addNewProject(project); } @@ -77,7 +77,7 @@ public class AdminApi { */ @PostMapping("/admin/appoitements/report/{appointmentId}") public void createAppointmentReport( - @PathVariable String appointmentId, @RequestBody Report report) { + @PathVariable String appointmentId, @RequestBody DelReport report) { adminApiService.createAppointmentReport(appointmentId, report); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java index 0071c61..96966a8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java @@ -1,7 +1,7 @@ package enseirb.myinpulse.controller; import enseirb.myinpulse.model.LCSection; -import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.DelProject; import enseirb.myinpulse.service.EntrepreneurApiService; import org.springframework.beans.factory.annotation.Autowired; @@ -63,7 +63,7 @@ public class EntrepreneurApi { * @return status code */ @PostMapping("/entrepreneur/project/request") - public void requestNewProject(@RequestBody Project project) { + public void requestNewProject(@RequestBody DelProject project) { entrepreneurApiService.requestNewProject(project); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index 038a083..b509cb3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -1,9 +1,9 @@ package enseirb.myinpulse.controller; -import enseirb.myinpulse.model.Administrateurs; -import enseirb.myinpulse.model.Appointment; -import enseirb.myinpulse.model.Entrepreneurs; -import enseirb.myinpulse.model.Sections; +import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.model.DelAppointment; +import enseirb.myinpulse.model.Entrepreneur; +import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.service.SharedApiService; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +31,7 @@ public class SharedApi { * @return a list of lean canvas sections */ @GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}") - public Iterable getLCSection( + public Iterable getLCSection( @PathVariable("projectId") String projectId, @PathVariable("title") String title, @PathVariable("date") String date) { @@ -44,7 +44,7 @@ public class SharedApi { * @return a list of all entrepreneurs in a project */ @GetMapping("/shared/entrepreneurs/{projectId}") - public Iterable getEntrepreneursByProjectId(@PathVariable int projectId) { + public Iterable getEntrepreneursByProjectId(@PathVariable int projectId) { return sharedApiService.getEntrepreneursByProjectId(projectId); } @@ -57,7 +57,7 @@ public class SharedApi { * @return a list of all project managed by the current admin user */ @GetMapping("/shared/projects/admin/{projectId}") - public Iterable getAdminByProjectId(@PathVariable int projectId) { + public Iterable getAdminByProjectId(@PathVariable int projectId) { return sharedApiService.getAdminByProjectId(projectId); } @@ -70,7 +70,7 @@ public class SharedApi { * @return a list of all appointments. */ @GetMapping("/shared/projects/appointments/{projectId}") - public Iterable getAppointmentsByProjectId(@PathVariable int projectId) { + public Iterable getAppointmentsByProjectId(@PathVariable int projectId) { return sharedApiService.getAppointmentsByProjectId(projectId); } @@ -90,7 +90,7 @@ public class SharedApi { * @return TODO */ @PostMapping("/shared/appointment/request") - public void createAppointmentRequest(@RequestBody Appointment appointment) { + public void createAppointmentRequest(@RequestBody DelAppointment appointment) { sharedApiService.createAppointmentRequest(appointment); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java deleted file mode 100644 index 0ff00e1..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrateurs.java +++ /dev/null @@ -1,43 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.persistence.PrimaryKeyJoinColumn; -import jakarta.persistence.Table; - -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "administrateurs") -@PrimaryKeyJoinColumn(name = "id_administrateur", referencedColumnName = "id_utilisateur") -public class Administrateurs extends Utilisateurs { - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet") - private Projets projetsAdministrateurs; - - @OneToMany(mappedBy = "administrateursSections", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousAdministrateurs; - - public Administrateurs() {} - - public Administrateurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - super( - nom_utilisateur, - id_utilisateur, - prenom_utilisateur, - mail_principal, - mail_secondaire, - numero_telephone); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java new file mode 100644 index 0000000..d90e3aa --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java @@ -0,0 +1,43 @@ +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.persistence.PrimaryKeyJoinColumn; +import jakarta.persistence.Table; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "administrator") +@PrimaryKeyJoinColumn(name = "idAdministrator", referencedColumnName = "idUser") +public class Administrator extends User { + + @OneToMany(mappedBy = "projectAdministrator", fetch = FetchType.LAZY, orphanRemoval = true) + private List listProject = new ArrayList<>(); + + /*@OneToMany(mappedBy = "administratorSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) + private List listSectionCell = new ArrayList<>();*/ + // should now be useless + + @OneToMany(mappedBy = "administratorAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) + private List listAnnotation = new ArrayList<>(); + + /*@OneToMany(mappedBy = "administratorAppointment", fetch = FetchType.LAZY, orphanRemoval = true) + private final List listAppointment = new ArrayList<>();*/ + // should now be useless + + @OneToOne(mappedBy = "administratorAppointment", fetch = FetchType.LAZY, orphanRemoval = true) + private MakeAppointment makeAppointment; + + public Administrator() {} + + public Administrator( + Long idUser, + String userSurname, + String username, + String mainMail, + String secondaryMail, + String phoneNumber) { + super(idUser, userSurname, username, mainMail, secondaryMail, phoneNumber); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java new file mode 100644 index 0000000..e7e9b3e --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java @@ -0,0 +1,39 @@ +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "annotation") +public class Annotation { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idAnnotation; + + private String comment; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idSectionCell") + private SectionCell sectionCellAnnotation; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAdministrator") + private Administrator administratorAnnotation; + + public Annotation() {} + + public Annotation(Long idAnnotation, String commentary) { + this.idAnnotation = idAnnotation; + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public void setCommentary(String comment) { + this.comment = comment; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index 53727c1..91cf332 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -1,8 +1,112 @@ package enseirb.myinpulse.model; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "appointment") public class Appointment { - int validated; - int[] akserId; - int[] destId; - String date; // TODO: date type ? + + /*@OneToMany(mappedBy = "appointmentEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) + private final List listEntrepreneur = + new ArrayList<>(); */ + // should now be useless + + @OneToMany(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) + private final List listReport = new ArrayList<>(); + + @ManyToMany( + fetch = FetchType.LAZY, + cascade = {CascadeType.ALL}) + @JoinTable( + name = "concern", + joinColumns = @JoinColumn(name = "idAppointment"), + inverseJoinColumns = @JoinColumn(name = "idSectionCell")) + List listSectionCell = new ArrayList<>(); + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idAppointment; + + private LocalDate appointmentDate; + + private LocalTime appointmentTime; + + private LocalTime appointmentDuration; + + @Column(length = 255) + private String appointmentPlace; + + private String appointmentSubject; + + public Appointment() {} + + public Appointment( + Long idAppointment, + LocalDate appointmentDate, + LocalTime appointmentTime, + LocalTime appointmentDuration, + String appointmentPlace, + String appointmentSubject) { + this.idAppointment = idAppointment; + this.appointmentDate = appointmentDate; + this.appointmentTime = appointmentTime; + this.appointmentDuration = appointmentDuration; + this.appointmentPlace = appointmentPlace; + this.appointmentSubject = appointmentSubject; + } + + public Long getIdAppointment() { + return idAppointment; + } + + public void setIdAppointment(Long idAppointment) { + this.idAppointment = idAppointment; + } + + public LocalDate getAppointmentDate() { + return appointmentDate; + } + + public void setAppointmentDate(LocalDate appointmentDate) { + this.appointmentDate = appointmentDate; + } + + public LocalTime getAppointmentTime() { + return appointmentTime; + } + + public void setAppointmentTime(LocalTime appointmentTime) { + this.appointmentTime = appointmentTime; + } + + public LocalTime getAppointmentDuration() { + return appointmentDuration; + } + + public void setAppointmentDuration(LocalTime appointmentDuration) { + this.appointmentDuration = appointmentDuration; + } + + public String getAppointmentPlace() { + return appointmentPlace; + } + + public void setAppointmentPlace(String appointmentPlace) { + this.appointmentPlace = appointmentPlace; + } + + public String getAppointmentSubject() { + return appointmentSubject; + } + + public void setAppointmentSubject(String appointmentSubject) { + this.appointmentSubject = appointmentSubject; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java deleted file mode 100644 index 617b31a..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ComptesRendus.java +++ /dev/null @@ -1,46 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; - -@Entity -@Table(name = "comptes_rendus") -public class ComptesRendus { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_compte_rendu; - - private String contenu_compte_rendu; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousComptesRendus; - - public ComptesRendus() {} - - public ComptesRendus(Long id_compte_rendu, String contenu_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - this.contenu_compte_rendu = contenu_compte_rendu; - } - - public Long getId_compte_rendu() { - return id_compte_rendu; - } - - public void setId_compte_rendu(Long id_compte_rendu) { - this.id_compte_rendu = id_compte_rendu; - } - - public String getContenu_compte_rendu() { - return contenu_compte_rendu; - } - - public void setContenu_compte_rendu(String contenu_compte_rendu) { - this.contenu_compte_rendu = contenu_compte_rendu; - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java new file mode 100644 index 0000000..f29a2eb --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java @@ -0,0 +1,8 @@ +package enseirb.myinpulse.model; + +public class DelAppointment { + int validated; + int[] akserId; + int[] destId; + String date; // TODO: date type ? +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java new file mode 100644 index 0000000..25a21f9 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java @@ -0,0 +1,7 @@ +package enseirb.myinpulse.model; + +public class DelProject { + int projectId; + String projectName; + String projectDescription; +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java new file mode 100644 index 0000000..bbdbae8 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java @@ -0,0 +1,6 @@ +package enseirb.myinpulse.model; + +public class DelReport { + int projectId; + String reportContent; +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java new file mode 100644 index 0000000..3773cea --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java @@ -0,0 +1,78 @@ +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "entrepreneur") +@PrimaryKeyJoinColumn(name = "idEntrepreneur", referencedColumnName = "idUser") +public class Entrepreneur extends User { + + @Column(length = 255) + private String school; + + @Column(length = 255) + private String course; + + private boolean sneeStatus; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idProjectParticipation", referencedColumnName = "idProject") + private Project projectParticipation; + + // @Column(insertable=false, updatable=false) + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idProjectProposed", referencedColumnName = "idProject") + private Project projectProposed; + + /*@ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAppointment") + private Appointment appointmentEntrepreneur;*/ + // should now be useless + + @OneToOne(mappedBy = "entrepreneurAppointment", fetch = FetchType.LAZY, orphanRemoval = true) + private MakeAppointment makeAppointment; + + public Entrepreneur() {} + + public Entrepreneur( + Long idUser, + String userSurname, + String username, + String mainMail, + String secondaryMail, + String phoneNumber, + String school, + String course, + boolean sneeStatus) { + super(idUser, userSurname, username, mainMail, secondaryMail, phoneNumber); + this.school = school; + this.course = course; + this.sneeStatus = sneeStatus; + } + + public String getSchool() { + return school; + } + + public void setSchool(String school) { + this.school = school; + } + + public String getCourse() { + return course; + } + + public void setCourse(String course) { + this.course = course; + } + + public boolean isSneeStatus() { + return sneeStatus; + } + + public void setSneeStatus(boolean statusSnee) { + this.sneeStatus = sneeStatus; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java deleted file mode 100644 index ef605ea..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneurs.java +++ /dev/null @@ -1,80 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -@Entity -@Table(name = "entrepreneurs") -@PrimaryKeyJoinColumn(name = "id_entrepreneur", referencedColumnName = "id_utilisateur") -public class Entrepreneurs extends Utilisateurs { - - @Column(length = 255) - private String ecole; - - @Column(length = 255) - private String filiere; - - private boolean status_snee; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet_participation", referencedColumnName = "id_projet") - private Projets projetsParticipation; - - // @Column(insertable=false, updatable=false) - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet_propose", referencedColumnName = "id_projet") - private Projets projetsPropose; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_rdv") - private RendezVous rendezVousEntrepreneurs; - - public Entrepreneurs() {} - - public Entrepreneurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone, - String ecole, - boolean status_snee, - String filiere) { - super( - nom_utilisateur, - id_utilisateur, - prenom_utilisateur, - mail_principal, - mail_secondaire, - numero_telephone); - this.ecole = ecole; - this.status_snee = status_snee; - this.filiere = filiere; - } - - public String getEcole() { - return ecole; - } - - public void setEcole(String ecole) { - this.ecole = ecole; - } - - public String getFiliere() { - return filiere; - } - - public void setFiliere(String filiere) { - this.filiere = filiere; - } - - public boolean isStatus_snee() { - return status_snee; - } - - public void setStatus_snee(boolean status_snee) { - this.status_snee = status_snee; - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java new file mode 100644 index 0000000..2e08724 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java @@ -0,0 +1,28 @@ +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "make_apppointment") +public class MakeAppointment { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idMakeAppointment; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAdministrator") + private Administrator administratorAppointment; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idEntrepreneur") + private Entrepreneur entrepreneurAppointment; + + public MakeAppointment() {} + + public MakeAppointment(Long idMakeAppointment) { + this.idMakeAppointment = idMakeAppointment; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index 99c562a..824de16 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -1,7 +1,96 @@ package enseirb.myinpulse.model; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "project") public class Project { - int projectId; - String projectName; - String projectDescription; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idProject; + + @Column(length = 255) + private String projectName; + + private byte[] logo; + + private LocalDate creationDate; + + @Column(length = 255) + private String projectStatus; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAdministrator") + private Administrator projectAdministrator; + + @OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true) + private List listEntrepreneurParticipation = new ArrayList<>(); + + @OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true) + private Entrepreneur entrepreneurProposed; + + @OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) + private List listSectionCell = new ArrayList<>(); + + public Project() {} + + public Project( + Long idProject, + String projectName, + byte[] logo, + LocalDate creationDate, + String projectStatus) { + this.idProject = idProject; + this.projectName = projectName; + this.logo = logo; + this.creationDate = creationDate; + this.projectStatus = projectStatus; + } + + public Long getIdProject() { + return idProject; + } + + public void setIdProject(Long idProject) { + this.idProject = idProject; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public byte[] getLogo() { + return logo; + } + + public void setLogo(byte[] logo) { + this.logo = logo; + } + + public LocalDate getCreationDate() { + return creationDate; + } + + public void setCreationDate(LocalDate creationDate) { + this.creationDate = creationDate; + } + + public String getProjectStatus() { + return projectStatus; + } + + public void setProjectStatus(String projectStatus) { + this.projectStatus = projectStatus; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java deleted file mode 100644 index 2cc6a81..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Projets.java +++ /dev/null @@ -1,98 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "projets") -public class Projets { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_projet; - - @Column(length = 255) - private String nom_projet; - - private byte[] logo; - - private LocalDate date_creation; - - @Column(length = 255) - private String status_projet; - - @OneToMany(mappedBy = "projetsAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private List listAdministrateurs = new ArrayList<>(); - - @OneToMany(mappedBy = "projetsParticipation", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListEntrepreneursParticipation = new ArrayList<>(); - - @OneToOne(mappedBy = "projetsPropose", fetch = FetchType.LAZY, orphanRemoval = true) - private Entrepreneurs entrepreneursPropose; - - @OneToMany(mappedBy = "projetsSections", fetch = FetchType.LAZY, orphanRemoval = true) - private List ListSections = new ArrayList<>(); - - // Hibernate expects entities to have a no-arg constructor, - // though it does not necessarily have to be public. - - public Projets() {} - - public Projets( - Long id_projet, - String nom_projet, - byte[] logo, - LocalDate date_creation, - String status_projet) { - this.id_projet = id_projet; - this.nom_projet = nom_projet; - this.logo = logo; - this.date_creation = date_creation; - this.status_projet = status_projet; - } - - public Long getId_projet() { - return id_projet; - } - - public void setId_projet(Long id_projet) { - this.id_projet = id_projet; - } - - public String getNom_projet() { - return nom_projet; - } - - public void setNom_projet(String nom_projet) { - this.nom_projet = nom_projet; - } - - public byte[] getLogo() { - return logo; - } - - public void setLogo(byte[] logo) { - this.logo = logo; - } - - public LocalDate getDate_creation() { - return date_creation; - } - - public void setDate_creation(LocalDate date_creation) { - this.date_creation = date_creation; - } - - public String getStatus_projet() { - return status_projet; - } - - public void setStatus_projet(String status_projet) { - this.status_projet = status_projet; - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java deleted file mode 100644 index ac25b96..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/RendezVous.java +++ /dev/null @@ -1,111 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "rendez_vous") -public class RendezVous { - - @OneToMany(mappedBy = "rendezVousEntrepreneurs", fetch = FetchType.LAZY, orphanRemoval = true) - private final List ListEntrepreneurs = new ArrayList<>(); - - @OneToMany(mappedBy = "rendezVousAdministrateurs", fetch = FetchType.LAZY, orphanRemoval = true) - private final List ListAdministrateurs = new ArrayList<>(); - - @OneToMany(mappedBy = "rendezVousComptesRendus", fetch = FetchType.LAZY, orphanRemoval = true) - private final List ListComptesRendus = new ArrayList<>(); - - @ManyToMany( - fetch = FetchType.LAZY, - cascade = {CascadeType.ALL}) - @JoinTable( - name = "concerner", - joinColumns = @JoinColumn(name = "id_rdv"), - inverseJoinColumns = @JoinColumn(name = "id_section")) - List ListSections = new ArrayList<>(); - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_rdv; - - private LocalDate date_rdv; - private LocalTime heure_rdv; - private LocalTime duree_rdv; - - @Column(length = 255) - private String lieu_rdv; - - private String sujet_rdv; - - public RendezVous() {} - - public RendezVous( - Long id_rdv, - LocalDate date_rdv, - LocalTime heure_rdv, - LocalTime duree_rdv, - String lieu_rdv, - String sujet_rdv) { - this.id_rdv = id_rdv; - this.date_rdv = date_rdv; - this.heure_rdv = heure_rdv; - this.duree_rdv = duree_rdv; - this.lieu_rdv = lieu_rdv; - this.sujet_rdv = sujet_rdv; - } - - public Long getId_rdv() { - return id_rdv; - } - - public void setId_rdv(Long id_rdv) { - this.id_rdv = id_rdv; - } - - public LocalDate getDate_rdv() { - return date_rdv; - } - - public void setDate_rdv(LocalDate date_rdv) { - this.date_rdv = date_rdv; - } - - public LocalTime getHeure_rdv() { - return heure_rdv; - } - - public void setHeure_rdv(LocalTime heure_rdv) { - this.heure_rdv = heure_rdv; - } - - public LocalTime getDuree_rdv() { - return duree_rdv; - } - - public void setDuree_rdv(LocalTime duree_rdv) { - this.duree_rdv = duree_rdv; - } - - public String getLieu_rdv() { - return lieu_rdv; - } - - public void setLieu_rdv(String lieu_rdv) { - this.lieu_rdv = lieu_rdv; - } - - public String getSujet_rdv() { - return sujet_rdv; - } - - public void setSujet_rdv(String sujet_rdv) { - this.sujet_rdv = sujet_rdv; - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java index 7270115..410cd7c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java @@ -1,6 +1,38 @@ package enseirb.myinpulse.model; +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "report") public class Report { - int projectId; - String reportContent; + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idReport; + + private String reportContent; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAppointment") + private Appointment appointmentReport; + + public Report() {} + + public Report(Long idReport, String reportContent) { + this.idReport = idReport; + this.reportContent = reportContent; + } + + public String getReportContent() { + return reportContent; + } + + public void setReportContent(String reportContent) { + this.reportContent = reportContent; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java new file mode 100644 index 0000000..aec0a0e --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -0,0 +1,85 @@ +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "section_cell") +public class SectionCell { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idSectionCell; + + @Column(length = 255) + private String title; + + private String contentSectionCell; + + private LocalDateTime modificationDate; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idProject") + private Project projectSectionCell; + + /*@ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAdministrator") + private Administrator administratorSectionCell;*/ + // should now be useless + + @ManyToMany(mappedBy = "listSectionCell") + private List appointment = new ArrayList<>(); + + @OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) + private List listAnnotation = new ArrayList<>(); + + public SectionCell() {} + + public SectionCell( + Long idSectionCell, + String title, + String contentSectionCell, + LocalDateTime modificationDate) { + this.idSectionCell = idSectionCell; + this.title = title; + this.contentSectionCell = contentSectionCell; + this.modificationDate = modificationDate; + } + + public Long getIdSectionCell() { + return idSectionCell; + } + + public void setIdSectionCell(Long idSectionCell) { + this.idSectionCell = idSectionCell; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContentSectionCell() { + return contentSectionCell; + } + + public void setContentSectionCell(String contentSectionCell) { + this.contentSectionCell = contentSectionCell; + } + + public LocalDateTime getModificationDate() { + return modificationDate; + } + + public void setModificationDate(LocalDateTime modificationDate) { + this.modificationDate = modificationDate; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java deleted file mode 100644 index 6aef759..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Sections.java +++ /dev/null @@ -1,81 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "sections") -public class Sections { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_section; - - @Column(length = 255) - private String titre; - - private String contenu_section; - - private LocalDateTime date_modification; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_projet") - private Projets projetsSections; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "id_admnistrateur") - private Administrateurs administrateursSections; - - @ManyToMany(mappedBy = "ListSections") - private List rendezVous = new ArrayList<>(); - - public Sections() {} - - public Sections( - Long id_section, - String titre, - String contenu_section, - LocalDateTime date_modification) { - this.id_section = id_section; - this.titre = titre; - this.contenu_section = contenu_section; - this.date_modification = date_modification; - } - - public String getTitre() { - return titre; - } - - public void setTitre(String titre) { - this.titre = titre; - } - - public Long getId_section() { - return id_section; - } - - public void setId_section(Long id_section) { - this.id_section = id_section; - } - - public String getContenu_section() { - return contenu_section; - } - - public void setContenu_section(String contenu_section) { - this.contenu_section = contenu_section; - } - - public LocalDateTime getDate_modification() { - return date_modification; - } - - public void setDate_modification(LocalDateTime date_modification) { - this.date_modification = date_modification; - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java new file mode 100644 index 0000000..4a1578b --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java @@ -0,0 +1,95 @@ +package enseirb.myinpulse.model; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; + +@Entity +@Table(name = "user") +@Inheritance(strategy = InheritanceType.JOINED) +public class User { + + @Id + @NotNull + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long idUser; + + @Column(length = 255) + private String UserSurname; + + @Column(length = 255) + private String UserName; + + @Column(length = 255) + private String mainMail; + + @Column(length = 255) + private String secondaryMail; + + @Column(length = 20) + private String phoneNumber; + + public User() {} + + public User( + Long idUser, + String userSurname, + String userName, + String mainMail, + String secondaryMail, + String phoneNumber) { + this.idUser = idUser; + this.UserSurname = userSurname; + this.UserName = userName; + this.mainMail = mainMail; + this.secondaryMail = secondaryMail; + this.phoneNumber = phoneNumber; + } + + public Long getIdUser() { + return idUser; + } + + public void setIdUser(Long idUser) { + this.idUser = idUser; + } + + public String getUserSurname() { + return UserSurname; + } + + public void setUserSurname(String userSurname) { + UserSurname = userSurname; + } + + public String getUserName() { + return UserName; + } + + public void setUserName(String userName) { + UserName = userName; + } + + public String getMainMail() { + return mainMail; + } + + public void setMainMail(String mainMail) { + this.mainMail = mainMail; + } + + public String getSecondaryMail() { + return secondaryMail; + } + + public void setSecondaryMail(String secondaryMail) { + this.secondaryMail = secondaryMail; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + phoneNumber = phoneNumber; + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java deleted file mode 100644 index 11dd163..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Utilisateurs.java +++ /dev/null @@ -1,95 +0,0 @@ -package enseirb.myinpulse.model; - -import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; - -@Entity -@Table(name = "utilisateurs") -@Inheritance(strategy = InheritanceType.JOINED) -public class Utilisateurs { - - @Id - @NotNull - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id_utilisateur; - - @Column(length = 255) - private String nom_utilisateur; - - @Column(length = 255) - private String prenom_utilisateur; - - @Column(length = 255) - private String mail_principal; - - @Column(length = 255) - private String mail_secondaire; - - @Column(length = 20) - private String numero_telephone; - - public Utilisateurs() {} - - public Utilisateurs( - String nom_utilisateur, - Long id_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - this.nom_utilisateur = nom_utilisateur; - this.id_utilisateur = id_utilisateur; - this.prenom_utilisateur = prenom_utilisateur; - this.mail_principal = mail_principal; - this.mail_secondaire = mail_secondaire; - this.numero_telephone = numero_telephone; - } - - public Long getId_utilisateur() { - return id_utilisateur; - } - - public void setId_utilisateur(Long id_utilisateur) { - this.id_utilisateur = id_utilisateur; - } - - public String getNom_utilisateur() { - return nom_utilisateur; - } - - public void setNom_utilisateur(String nom_utilisateur) { - this.nom_utilisateur = nom_utilisateur; - } - - public String getPrenom_utilisateur() { - return prenom_utilisateur; - } - - public void setPrenom_utilisateur(String prenom_utilisateur) { - this.prenom_utilisateur = prenom_utilisateur; - } - - public String getMail_principal() { - return mail_principal; - } - - public void setMail_principal(String mail_principal) { - this.mail_principal = mail_principal; - } - - public String getMail_secondaire() { - return mail_secondaire; - } - - public void setMail_secondaire(String mail_secondaire) { - this.mail_secondaire = mail_secondaire; - } - - public String getNumero_telephone() { - return numero_telephone; - } - - public void setNumero_telephone(String numero_telephone) { - this.numero_telephone = numero_telephone; - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java deleted file mode 100644 index 543778e..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministrateursRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package enseirb.myinpulse.repository; - -import enseirb.myinpulse.model.Administrateurs; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface AdministrateursRepository extends JpaRepository { - - /* @Query("SELECT a from Administrateurs a") - Administrateurs findAllAdministrateurs(); */ - -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java new file mode 100644 index 0000000..34431fd --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java @@ -0,0 +1,14 @@ +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Administrator; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface AdministratorRepository extends JpaRepository { + + /* @Query("SELECT a from Administrators a") + Administrator findAllAdministrator(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/RendezVousRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AppointmentRepository.java similarity index 61% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/repository/RendezVousRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AppointmentRepository.java index 127c2cb..11b0c00 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/RendezVousRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AppointmentRepository.java @@ -1,9 +1,9 @@ package enseirb.myinpulse.repository; -import enseirb.myinpulse.model.RendezVous; +import enseirb.myinpulse.model.Appointment; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface RendezVousRepository extends JpaRepository {} +public interface AppointmentRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java new file mode 100644 index 0000000..eee1020 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java @@ -0,0 +1,14 @@ +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Entrepreneur; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface EntrepreneurRepository extends JpaRepository { + + /* @Query("SELECT e from Entrepreneur e") + Entrepreneur findAllEntrepreneurl(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java deleted file mode 100644 index 6a957f6..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneursRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package enseirb.myinpulse.repository; - -import enseirb.myinpulse.model.Entrepreneurs; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface EntrepreneursRepository extends JpaRepository { - - /* @Query("SELECT e from Entrepreneurs e") - Entrepreneurs findAllEntrepreneurs(); */ - -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjetsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java similarity index 67% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjetsRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java index 9d045d6..0da05d7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjetsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java @@ -1,9 +1,9 @@ package enseirb.myinpulse.repository; -import enseirb.myinpulse.model.Projets; +import enseirb.myinpulse.model.Project; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ProjetsRepository extends JpaRepository {} +public interface ProjectRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionsRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java similarity index 63% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionsRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java index 2ccff00..e228003 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionsRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java @@ -1,9 +1,9 @@ package enseirb.myinpulse.repository; -import enseirb.myinpulse.model.Sections; +import enseirb.myinpulse.model.Report; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface SectionsRepository extends JpaRepository {} +public interface ReportRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ComptesRendusRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java similarity index 60% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ComptesRendusRepository.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java index 60e0017..66ce004 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ComptesRendusRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java @@ -1,9 +1,9 @@ package enseirb.myinpulse.repository; -import enseirb.myinpulse.model.ComptesRendus; +import enseirb.myinpulse.model.SectionCell; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ComptesRendusRepository extends JpaRepository {} +public interface SectionCellRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java new file mode 100644 index 0000000..7dd3089 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java @@ -0,0 +1,14 @@ +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.User; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface UserRepository extends JpaRepository { + + /* @Query("SELECT u from User u") + User findAllUser(); */ + +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java deleted file mode 100644 index 16f04c7..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UtilisateursRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package enseirb.myinpulse.repository; - -import enseirb.myinpulse.model.Utilisateurs; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource -public interface UtilisateursRepository extends JpaRepository { - - /* @Query("SELECT u from Utilisateurs u") - Utilisateurs findAllUtilisateurs(); */ - -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 273e9cb..70b4c5a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -4,23 +4,22 @@ import enseirb.myinpulse.model.*; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; @Service public class AdminApiService { // TODO - public Iterable getProjects() { + public Iterable getProjects() { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } // TODO - public Iterable getUpcomingAppointments() { + public Iterable getUpcomingAppointments() { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } // TODO - public Iterable getPendingProjects() { + public Iterable getPendingProjects() { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } @@ -30,12 +29,12 @@ public class AdminApiService { } // TODO - public void addNewProject(Project project) { + public void addNewProject(DelProject project) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } // TODO - public void createAppointmentReport(String appointmentId, Report report) { + public void createAppointmentReport(String appointmentId, DelReport report) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index adb17e6..2641ff7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -1,11 +1,10 @@ package enseirb.myinpulse.service; import enseirb.myinpulse.model.LCSection; -import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.DelProject; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; @Service @@ -23,7 +22,7 @@ public class EntrepreneurApiService { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void requestNewProject(Project project) { + public void requestNewProject(DelProject project) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index f750a59..cf5de12 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -9,20 +9,20 @@ import org.springframework.web.server.ResponseStatusException; @Service public class SharedApiService { - public Iterable getLCSection(String projectId, String title, String date) { + public Iterable getLCSection(String projectId, String title, String date) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getEntrepreneursByProjectId(int projectId) { + public Iterable getEntrepreneursByProjectId(int projectId) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getAdminByProjectId(int projectId) { + public Iterable getAdminByProjectId(int projectId) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getAppointmentsByProjectId(int projectId) { + public Iterable getAppointmentsByProjectId(int projectId) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } @@ -30,7 +30,7 @@ public class SharedApiService { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public void createAppointmentRequest(Appointment appointment) { + public void createAppointmentRequest(DelAppointment appointment) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java deleted file mode 100644 index 7355099..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/CompteRenduService.java +++ /dev/null @@ -1,34 +0,0 @@ -package enseirb.myinpulse.service.database; - -import enseirb.myinpulse.model.ComptesRendus; -import enseirb.myinpulse.repository.ComptesRendusRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@Service -public class CompteRenduService { - private final ComptesRendusRepository comptesRendusRepository; - - @Autowired - CompteRenduService(ComptesRendusRepository comptesRendusRepository) { - this.comptesRendusRepository = comptesRendusRepository; - } - - ComptesRendus getComptesRendusById(int id) { - Optional compteRendu = comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - return compteRendu.get(); - } - - // TODO: do some validation - void saveCompteRendu(ComptesRendus compteRendu) { - comptesRendusRepository.save(compteRendu); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java new file mode 100644 index 0000000..e9d8d27 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java @@ -0,0 +1,34 @@ +package enseirb.myinpulse.service.database; + +import enseirb.myinpulse.model.Report; +import enseirb.myinpulse.repository.ReportRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@Service +public class ReportService { + private final ReportRepository reportRepository; + + @Autowired + ReportService(ReportRepository reportRepository) { + this.reportRepository = reportRepository; + } + + Report getReportById(int id) { + Optional report = reportRepository.findById(id); + if (report.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + return report.get(); + } + + // TODO: do some validation + void saveReport(Report report) { + reportRepository.save(report); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java deleted file mode 100644 index 8a96924..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministrateursController.java +++ /dev/null @@ -1,38 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Administrateurs; -import enseirb.myinpulse.repository.AdministrateursRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class AdministrateursController { - - @Autowired AdministrateursRepository administrateursRepository; - - @GetMapping("/Administrateurs") - @ResponseBody - public Iterable allAdministrateurs() { - return this.administrateursRepository.findAll(); - } - - @GetMapping("/Administrateurs/{id}") - public Administrateurs getAdministrateursById(@PathVariable Long id) { - Optional administrateur = this.administrateursRepository.findById(id); - if (administrateur.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); - } - return administrateur.get(); - } - - @PostMapping("/Administrateurs") - public Administrateurs addAdministrateurs(@RequestBody Administrateurs administrateurs) { - return this.administrateursRepository.save(administrateurs); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java new file mode 100644 index 0000000..7e2706a --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java @@ -0,0 +1,38 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.repository.AdministratorRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class AdministratorController { + + @Autowired AdministratorRepository administratorRepository; + + @GetMapping("/Administrator") + @ResponseBody + public Iterable allAdministrators() { + return this.administratorRepository.findAll(); + } + + @GetMapping("/Administrator/{id}") + public Administrator getAdministratorById(@PathVariable Long id) { + Optional administrator = this.administratorRepository.findById(id); + if (administrator.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + return administrator.get(); + } + + @PostMapping("/Administrateurs") + public Administrator addAdministrator(@RequestBody Administrator administrator) { + return this.administratorRepository.save(administrator); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java new file mode 100644 index 0000000..3761d51 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java @@ -0,0 +1,69 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Appointment; +import enseirb.myinpulse.repository.AppointmentRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Optional; + +@RestController +public class AppointmentController { + + @Autowired AppointmentRepository appointmentRepository; + + @GetMapping("/Appointment") + @ResponseBody + public Iterable allAppointments() { + return this.appointmentRepository.findAll(); + } + + @GetMapping("/Appointment/{id}") + public Appointment getAppointmentById(@PathVariable Long id) { + Optional appointment = this.appointmentRepository.findById(id); + if (appointment.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + return appointment.get(); + } + + @PostMapping("/Appointment") + public Appointment addAppointment(@RequestBody Appointment appointment) { + return this.appointmentRepository.save(appointment); + } + + @PostMapping("/Appointment/{id}") + public Appointment updateAppointment( + @PathVariable Long id, + LocalDate appointmentDate, + LocalTime appointmentTime, + LocalTime appointmentDuration, + String appointmentPlace, + String appointmentSubject) { + Optional appointment = this.appointmentRepository.findById(id); + if (appointment.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + if (appointmentDate != null) { + appointment.get().setAppointmentDate(appointmentDate); + } + if (appointmentTime != null) { + appointment.get().setAppointmentTime(appointmentTime); + } + if (appointmentDuration != null) { + appointment.get().setAppointmentDuration(appointmentDuration); + } + if (appointmentPlace != null) { + appointment.get().setAppointmentPlace(appointmentPlace); + } + if (appointmentSubject != null) { + appointment.get().setAppointmentSubject(appointmentSubject); + } + return this.appointmentRepository.save(appointment.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java deleted file mode 100644 index 1567b6d..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ComptesRendusController.java +++ /dev/null @@ -1,43 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import org.springframework.web.bind.annotation.*; - -@RestController -public class ComptesRendusController { - /* - private final ComptesRendusRepository comptesRendusRepository; - - @Autowired - public ComptesRendusController(ComptesRendusRepository comptesRendusRepository) { - this.comptesRendusRepository = comptesRendusRepository; - } - - @GetMapping("/ComptesRendus") - @ResponseBody - public Iterable allComptesRendus() { - System.out.println("\n\n"); - System.out.println(comptesRendusRepository); - System.out.println("\n\n"); - return this.comptesRendusRepository.findAll(); - } - - - @PostMapping("/ComptesRendus") - public ComptesRendus addComptesRendus(@RequestBody ComptesRendus comptesRendus) { - return this.comptesRendusRepository.save(comptesRendus); - } - - @PostMapping("/ComptesRendus/{id}") - public ComptesRendus updateProjets(@PathVariable Long id, String contenu_compte_rendu) { - Optional compteRendu = this.comptesRendusRepository.findById(id); - if (compteRendu.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - if (contenu_compte_rendu != null) { - compteRendu.get().setContenu_compte_rendu(contenu_compte_rendu); - } - return this.comptesRendusRepository.save(compteRendu.get()); - } - - */ -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneurController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneurController.java new file mode 100644 index 0000000..3e72159 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneurController.java @@ -0,0 +1,58 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Entrepreneur; +import enseirb.myinpulse.repository.EntrepreneurRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class EntrepreneurController { + + @Autowired EntrepreneurRepository entrepreneurRepository; + + @GetMapping("/Entrepreneur") + @ResponseBody + public Iterable allEntrepreneurs() { + return this.entrepreneurRepository.findAll(); + } + + @GetMapping("/Entrepreneur/{id}") + public Entrepreneur getEntrepreneurById(@PathVariable Long id) { + Optional entrepreneur = entrepreneurRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + return entrepreneur.get(); + } + + @PostMapping("/Entrepreneur") + public Entrepreneur addEntrepreneur(@RequestBody Entrepreneur entrepreneur) { + return this.entrepreneurRepository.save(entrepreneur); + } + + @PostMapping("/Entrepreneur/{id}") + public Entrepreneur updateEntrepreneur( + @PathVariable Long id, String school, String course, Boolean sneeStatus) { + Optional entrepreneur = entrepreneurRepository.findById(id); + if (entrepreneur.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); + } + if (school != null) { + entrepreneur.get().setSchool(school); + } + if (course != null) { + entrepreneur.get().setCourse(course); + } + if (sneeStatus != null) { + entrepreneur.get().setSneeStatus(sneeStatus); + } + return this.entrepreneurRepository.save(entrepreneur.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java deleted file mode 100644 index 4a21078..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneursController.java +++ /dev/null @@ -1,58 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Entrepreneurs; -import enseirb.myinpulse.repository.EntrepreneursRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class EntrepreneursController { - - @Autowired EntrepreneursRepository entrepreneursRepository; - - @GetMapping("/Entrepreneurs") - @ResponseBody - public Iterable allEntrepreneurs() { - return this.entrepreneursRepository.findAll(); - } - - @GetMapping("/Entrepreneurs/{id}") - public Entrepreneurs getEntrepreneursById(@PathVariable Long id) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); - } - return entrepreneur.get(); - } - - @PostMapping("/Entrepreneurs") - public Entrepreneurs addEntrepreneurs(@RequestBody Entrepreneurs entrepreneurs) { - return this.entrepreneursRepository.save(entrepreneurs); - } - - @PostMapping("/Entrepreneurs/{id}") - public Entrepreneurs updateEntrepreneurs( - @PathVariable Long id, String ecole, String filiere, Boolean status_snee) { - Optional entrepreneur = entrepreneursRepository.findById(id); - if (entrepreneur.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); - } - if (ecole != null) { - entrepreneur.get().setEcole(ecole); - } - if (filiere != null) { - entrepreneur.get().setFiliere(filiere); - } - if (status_snee != null) { - entrepreneur.get().setStatus_snee(status_snee); - } - return this.entrepreneursRepository.save(entrepreneur.get()); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java new file mode 100644 index 0000000..ffbc8e4 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java @@ -0,0 +1,64 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.repository.ProjectRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.util.Optional; + +@RestController +public class ProjectController { + + @Autowired ProjectRepository projectRepository; + + @GetMapping("/Project") + @ResponseBody + public Iterable allProjects() { + return this.projectRepository.findAll(); + } + + @GetMapping("/Project/{id}") + public Project getProjectById(@PathVariable Long id) { + Optional project = this.projectRepository.findById(id); + if (project.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + return project.get(); + } + + @PostMapping("/Project") + public Project addProject(@RequestBody Project project) { + return this.projectRepository.save(project); + } + + @PostMapping("/Project/{id}") + public Project updateProject( + @PathVariable Long id, + String projectName, + byte[] logo, + LocalDate creationDate, + String projectStatus) { + Optional project = this.projectRepository.findById(id); + if (project.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + if (projectName != null) { + project.get().setProjectName(projectName); + } + if (logo != null) { + project.get().setLogo(logo); + } + if (creationDate != null) { + project.get().setCreationDate(creationDate); + } + if (projectStatus != null) { + project.get().setProjectStatus(projectStatus); + } + return this.projectRepository.save(project.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java deleted file mode 100644 index f33edbc..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjetsController.java +++ /dev/null @@ -1,64 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Projets; -import enseirb.myinpulse.repository.ProjetsRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDate; -import java.util.Optional; - -@RestController -public class ProjetsController { - - @Autowired ProjetsRepository projetsRepository; - - @GetMapping("/Projets") - @ResponseBody - public Iterable allProjets() { - return this.projetsRepository.findAll(); - } - - @GetMapping("/Projets/{id}") - public Projets getProjetsById(@PathVariable Long id) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); - } - return projet.get(); - } - - @PostMapping("/Projets") - public Projets addProjets(@RequestBody Projets projet) { - return this.projetsRepository.save(projet); - } - - @PostMapping("/Projets/{id}") - public Projets updateProjets( - @PathVariable Long id, - String nom_projet, - byte[] logo, - LocalDate date_creation, - String status_projet) { - Optional projet = this.projetsRepository.findById(id); - if (projet.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); - } - if (nom_projet != null) { - projet.get().setNom_projet(nom_projet); - } - if (logo != null) { - projet.get().setLogo(logo); - } - if (date_creation != null) { - projet.get().setDate_creation(date_creation); - } - if (status_projet != null) { - projet.get().setStatus_projet(status_projet); - } - return this.projetsRepository.save(projet.get()); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java deleted file mode 100644 index 522db14..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/RendezVousController.java +++ /dev/null @@ -1,69 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.RendezVous; -import enseirb.myinpulse.repository.RendezVousRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.Optional; - -@RestController -public class RendezVousController { - - @Autowired RendezVousRepository rendezVousRepository; - - @GetMapping("/RendezVous") - @ResponseBody - public Iterable allRendezVous() { - return this.rendezVousRepository.findAll(); - } - - @GetMapping("/RendezVous/{id}") - public RendezVous getRendezVousById(@PathVariable Long id) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - return rendezVous.get(); - } - - @PostMapping("/RendezVous") - public RendezVous addRendezVous(@RequestBody RendezVous rendezVous) { - return this.rendezVousRepository.save(rendezVous); - } - - @PostMapping("/RendezVous/{id}") - public RendezVous updateRendezVous( - @PathVariable Long id, - LocalDate date_rdv, - LocalTime heure_rdv, - LocalTime duree_rdv, - String lieu_rdv, - String sujet_rdv) { - Optional rendezVous = this.rendezVousRepository.findById(id); - if (rendezVous.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - if (date_rdv != null) { - rendezVous.get().setDate_rdv(date_rdv); - } - if (heure_rdv != null) { - rendezVous.get().setHeure_rdv(heure_rdv); - } - if (duree_rdv != null) { - rendezVous.get().setDuree_rdv(duree_rdv); - } - if (lieu_rdv != null) { - rendezVous.get().setLieu_rdv(lieu_rdv); - } - if (sujet_rdv != null) { - rendezVous.get().setSujet_rdv(sujet_rdv); - } - return this.rendezVousRepository.save(rendezVous.get()); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java new file mode 100644 index 0000000..7b3458b --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java @@ -0,0 +1,43 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import org.springframework.web.bind.annotation.*; + +@RestController +public class ReportController { + /* + private final ReportRepository reportRepository; + + @Autowired + public ReportController(ReportRepository reportRepository) { + this.reportRepository = reportRepository; + } + + @GetMapping("/Report") + @ResponseBody + public Iterable allReports() { + System.out.println("\n\n"); + System.out.println(ReportRepository); + System.out.println("\n\n"); + return this.reportRepository.findAll(); + } + + + @PostMapping("/Report") + public Report addReport(@RequestBody Report report) { + return this.reportRepository.save(report); + } + + @PostMapping("/Report/{id}") + public Report updateProject(@PathVariable Long id, String reportContent) { + Optional report = this.reportRepository.findById(id); + if (report.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + if (reportContent != null) { + report.get().setReportContent(reportContent); + } + return this.reportRepository.save(report.get()); + } + + */ +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java new file mode 100644 index 0000000..519fd90 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java @@ -0,0 +1,62 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.SectionCell; +import enseirb.myinpulse.repository.SectionCellRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDateTime; +import java.util.Optional; + +@RestController +public class SectionCellController { + + @Autowired SectionCellRepository sectionCellRepository; + + @GetMapping("/SectionCell") + @ResponseBody + public Iterable allSectionCells() { + return this.sectionCellRepository.findAll(); + } + + @GetMapping("/SectionCell/{id}") + public SectionCell getSectionCellById(@PathVariable Long id) { + Optional sectionCell = this.sectionCellRepository.findById(id); + if (sectionCell.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); + } + return sectionCell.get(); + } + + @PostMapping("/SectionCell") + public SectionCell addSectionCell(@RequestBody SectionCell sectionCell) { + return this.sectionCellRepository.save(sectionCell); + } + + @PostMapping("/SectionCell/{id}") + public SectionCell updateSectionCell( + @PathVariable Long id, + String title, + String contentSectionCell, + LocalDateTime modificationDate) { + Optional sectionCell = this.sectionCellRepository.findById(id); + if (sectionCell.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); + } + if (title != null) { + sectionCell.get().setTitle(title); + } + if (contentSectionCell != null) { + sectionCell.get().setContentSectionCell(contentSectionCell); + } + if (modificationDate != null) { + sectionCell.get().setModificationDate(modificationDate); + } + return this.sectionCellRepository.save(sectionCell.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java deleted file mode 100644 index d3009c6..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionsController.java +++ /dev/null @@ -1,60 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Sections; -import enseirb.myinpulse.repository.SectionsRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDateTime; -import java.util.Optional; - -@RestController -public class SectionsController { - - @Autowired SectionsRepository sectionsRepository; - - @GetMapping("/Sections") - @ResponseBody - public Iterable allSections() { - return this.sectionsRepository.findAll(); - } - - @GetMapping("/Sections/{id}") - public Sections getSectionsById(@PathVariable Long id) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); - } - return section.get(); - } - - @PostMapping("/Sections") - public Sections addSections(@RequestBody Sections sections) { - return this.sectionsRepository.save(sections); - } - - @PostMapping("/Sections/{id}") - public Sections updateSections( - @PathVariable Long id, - String titre, - String contenu_section, - LocalDateTime date_modification) { - Optional section = this.sectionsRepository.findById(id); - if (section.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cette section n'extise pas"); - } - if (titre != null) { - section.get().setTitre(titre); - } - if (contenu_section != null) { - section.get().setContenu_section(contenu_section); - } - if (date_modification != null) { - section.get().setDate_modification(date_modification); - } - return this.sectionsRepository.save(section.get()); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java new file mode 100644 index 0000000..a9abc1f --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java @@ -0,0 +1,67 @@ +package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; + +import enseirb.myinpulse.model.User; +import enseirb.myinpulse.repository.UserRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@RestController +public class UserController { + + @Autowired UserRepository userRepository; + + @GetMapping("/User") + @ResponseBody + public Iterable allUsers() { + return this.userRepository.findAll(); + } + + @GetMapping("/User/{id}") + public User getUserById(@PathVariable Long id) { + Optional user = userRepository.findById(id); + if (user.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + return user.get(); + } + + @PostMapping("/User") + public User addUser(@RequestBody User user) { + return this.userRepository.save(user); + } + + @PostMapping("/User/{id}") + public User updateUser( + @PathVariable Long id, + String userSurname, + String userName, + String mainMail, + String secondaryMail, + String phoneNumber) { + Optional user = userRepository.findById(id); + if (user.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + if (userName != null) { + user.get().setUserName(userName); + } + if (userSurname != null) { + user.get().setUserSurname(userSurname); + } + if (mainMail != null) { + user.get().setMainMail(mainMail); + } + if (secondaryMail != null) { + user.get().setSecondaryMail(secondaryMail); + } + if (phoneNumber != null) { + user.get().setPhoneNumber(phoneNumber); + } + return this.userRepository.save(user.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java deleted file mode 100644 index ce0a66a..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UtilisateursController.java +++ /dev/null @@ -1,67 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Utilisateurs; -import enseirb.myinpulse.repository.UtilisateursRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class UtilisateursController { - - @Autowired UtilisateursRepository utilisateursRepository; - - @GetMapping("/Utilisateurs") - @ResponseBody - public Iterable allUtilisateurs() { - return this.utilisateursRepository.findAll(); - } - - @GetMapping("/Utilisateurs/{id}") - public Utilisateurs getUtilisateursById(@PathVariable Long id) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - return utilisateur.get(); - } - - @PostMapping("/Utilisateurs") - public Utilisateurs addUtilisateurs(@RequestBody Utilisateurs utilisateurs) { - return this.utilisateursRepository.save(utilisateurs); - } - - @PostMapping("/Utilisateurs/{id}") - public Utilisateurs updateUtilisateurs( - @PathVariable Long id, - String nom_utilisateur, - String prenom_utilisateur, - String mail_principal, - String mail_secondaire, - String numero_telephone) { - Optional utilisateur = utilisateursRepository.findById(id); - if (utilisateur.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - if (nom_utilisateur != null) { - utilisateur.get().setNom_utilisateur(nom_utilisateur); - } - if (prenom_utilisateur != null) { - utilisateur.get().setPrenom_utilisateur(prenom_utilisateur); - } - if (mail_principal != null) { - utilisateur.get().setMail_principal(mail_principal); - } - if (mail_secondaire != null) { - utilisateur.get().setMail_secondaire(mail_secondaire); - } - if (numero_telephone != null) { - utilisateur.get().setNumero_telephone(numero_telephone); - } - return this.utilisateursRepository.save(utilisateur.get()); - } -} diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index a94541b..c5ae489 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -1,4 +1,4 @@ -TRUNCATE projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus CASCADE; +TRUNCATE projets, user, entrepreneur, sectionCell, rendez_vous, comptes_rendus CASCADE; INSERT INTO projets (nom_projet, logo, date_creation, status_projet) VALUES ('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_DATE('01-OCT-2023', 'DD-MON-YYYY'), @@ -9,7 +9,7 @@ VALUES ('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_ ('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), 'Lancement'); -INSERT INTO utilisateurs (nom_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone) VALUES +INSERT INTO user (nom_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone) VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), ('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), @@ -18,7 +18,7 @@ INSERT INTO utilisateurs (nom_utilisateur, prenom_utilisateur, mail_principal, m ('Ducaillou', 'Pierre', 'maildefou@xyz.fr', 'maildefou2@xyz.fr', '06 54 78 12 62'); -INSERT INTO entrepreneurs (ecole, filiere, status_snee, id_entrepreneur) VALUES +INSERT INTO entrepreneur (ecole, filiere, status_snee, id_entrepreneur) VALUES ('ENSEIRB-MATMECA', 'INFO', TRUE, 1), ('ENSC', 'Cognitique', TRUE, 2), ('ENSEIRB-MATMECA', 'MATMECA', FALSE, 3), @@ -26,7 +26,7 @@ INSERT INTO entrepreneurs (ecole, filiere, status_snee, id_entrepreneur) VALUES ('ENSEGID', 'Géoscience', FALSE, 5), ('ENSMAC', 'Matériaux composites - Mécanique', FALSE, 6); -INSERT INTO sections (titre, contenu_section, date_modification) VALUES +INSERT INTO sectionCell (titre, contenu_section, date_modification) VALUES ('Problème', 'les problèmes...', TO_TIMESTAMP('15-JAN-2025 09:30:20', 'DD-MON-YYYY, HH24:MI:SS')), ('Segment de client', 'Le segment AB passant le client n°8 est de longueur 32mm. Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?', TO_TIMESTAMP('12-OCT-2022 17:47:38', 'DD-MON-YYYY, HH24:MI:SS')), diff --git a/MyINPulse-back/src/main/resources/delete.sql b/MyINPulse-back/src/main/resources/delete.sql index c494872..fb9e00a 100644 --- a/MyINPulse-back/src/main/resources/delete.sql +++ b/MyINPulse-back/src/main/resources/delete.sql @@ -1 +1 @@ -DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE; \ No newline at end of file +DROP TABLE IF EXISTS administrator, projets, user, entrepreneur, sectionCell, rendez_vous, comptes_rendus, concerner CASCADE; \ No newline at end of file diff --git a/MyINPulse-back/src/main/resources/schema.sql b/MyINPulse-back/src/main/resources/schema.sql index aae3f91..b7b4f87 100644 --- a/MyINPulse-back/src/main/resources/schema.sql +++ b/MyINPulse-back/src/main/resources/schema.sql @@ -1,8 +1,8 @@ DROP TABLE IF EXISTS projets CASCADE; -DROP TABLE IF EXISTS utilisateurs CASCADE; -DROP TABLE IF EXISTS entrepreneurs CASCADE; -DROP TABLE IF EXISTS administrateurs CASCADE; -DROP TABLE IF EXISTS sections CASCADE; +DROP TABLE IF EXISTS user CASCADE; +DROP TABLE IF EXISTS entrepreneur CASCADE; +DROP TABLE IF EXISTS administrator CASCADE; +DROP TABLE IF EXISTS sectionCell CASCADE; DROP TABLE IF EXISTS rendez_vous CASCADE; DROP TABLE IF EXISTS comptes_rendus CASCADE; DROP TABLE IF EXISTS concerner CASCADE; @@ -18,7 +18,7 @@ CREATE TABLE projets CONSTRAINT pk_projet PRIMARY KEY (id_projet) ); -CREATE TABLE utilisateurs +CREATE TABLE user ( id_utilisateur SERIAL NOT NULL, nom_utilisateur VARCHAR(255) , @@ -28,22 +28,22 @@ mail_secondaire VARCHAR(255) , numero_telephone VARCHAR(20) , CONSTRAINT pk_utilisateur PRIMARY KEY (id_utilisateur) ); -CREATE TABLE entrepreneurs +CREATE TABLE entrepreneur ( - id_entrepreneur SERIAL REFERENCES utilisateurs (id_utilisateur), + id_entrepreneur SERIAL REFERENCES user (id_utilisateur), ecole VARCHAR(255), filiere VARCHAR(255), status_snee BOOLEAN, CONSTRAINT pk_entrepreneur PRIMARY KEY (id_entrepreneur) ); -CREATE TABLE administrateurs +CREATE TABLE administrator ( - id_administrateur SERIAL REFERENCES utilisateurs (id_utilisateur), + id_administrateur SERIAL REFERENCES user (id_utilisateur), CONSTRAINT pk_administrateur PRIMARY KEY (id_administrateur) ); -CREATE TABLE sections +CREATE TABLE sectionCell ( id_section SERIAL NOT NULL, titre VARCHAR(255), @@ -72,47 +72,47 @@ CREATE TABLE comptes_rendus CREATE TABLE concerner ( - id_section SERIAL REFERENCES sections (id_section), - id_rdv SERIAL REFERENCES sections (id_rdv), + id_section SERIAL REFERENCES sectionCell (id_section), + id_rdv SERIAL REFERENCES sectionCell (id_rdv), CONSTRAINT pk_concerner PRIMARY KEY (id_section, id_rdv) ); ALTER TABLE projets ADD CONSTRAINT fk1_projet FOREIGN KEY (id_administrateur) - REFERENCES administrateurs (id_administrateur) + REFERENCES administrator (id_administrateur) ON DELETE CASCADE; ALTER TABLE projets ADD CONSTRAINT fk2_projet FOREIGN KEY (id_entrepreneur_participation) - REFERENCES entrepreneurs (id_entrepreneur) + REFERENCES entrepreneur (id_entrepreneur) ON DELETE CASCADE; -ALTER TABLE entrepreneurs +ALTER TABLE entrepreneur ADD CONSTRAINT fk1_entrepreneur FOREIGN KEY (id_projet_propose) REFERENCES projets (id_projet) ON DELETE CASCADE; -ALTER TABLE sections +ALTER TABLE sectionCell ADD CONSTRAINT fk1_section FOREIGN KEY (id_projet) REFERENCES projets (id_projet) ON DELETE CASCADE; -ALTER TABLE sections +ALTER TABLE sectionCell ADD CONSTRAINT fk2_section FOREIGN KEY (id_administrateur) - REFERENCES administrateurs (id_administrateur) + REFERENCES administrator (id_administrateur) ON DELETE CASCADE; ALTER TABLE rendez-vous ADD CONSTRAINT fk1_rdv FOREIGN KEY (id_entrepreneur) - REFERENCES entrepreneurs (id_entrepreneur) + REFERENCES entrepreneur (id_entrepreneur) ON DELETE CASCADE; ALTER TABLE rendez-vous ADD CONSTRAINT fk2_rdv FOREIGN KEY (id_administrateur) - REFERENCES administrateurs (id_administrateur) + REFERENCES administrator (id_administrateur) ON DELETE CASCADE; -- 2.47.2 From 27e70ee10904d10f4c21de16f20c3a3c7d0a81f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Mon, 24 Feb 2025 17:19:18 +0100 Subject: [PATCH 46/97] fix: naming issues with database and better data --- .../myinpulse/model/MakeAppointment.java | 2 +- .../java/enseirb/myinpulse/model/User.java | 18 +-- .../repository/AnnotationRepository.java | 9 ++ .../repository/MakeAppointmentRepository.java | 9 ++ MyINPulse-back/src/main/resources/data.sql | 121 ++++++++++------ MyINPulse-back/src/main/resources/delete.sql | 3 +- MyINPulse-back/src/main/resources/schema.sql | 134 ------------------ 7 files changed, 106 insertions(+), 190 deletions(-) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AnnotationRepository.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/repository/MakeAppointmentRepository.java delete mode 100644 MyINPulse-back/src/main/resources/schema.sql diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java index 2e08724..91c97d5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java @@ -4,7 +4,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @Entity -@Table(name = "make_apppointment") +@Table(name = "make_appointment") public class MakeAppointment { @Id diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java index 4a1578b..6ab965e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java @@ -4,7 +4,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; @Entity -@Table(name = "user") +@Table(name = "user_inpulse") @Inheritance(strategy = InheritanceType.JOINED) public class User { @@ -14,10 +14,10 @@ public class User { private Long idUser; @Column(length = 255) - private String UserSurname; + private String userSurname; @Column(length = 255) - private String UserName; + private String userName; @Column(length = 255) private String mainMail; @@ -38,8 +38,8 @@ public class User { String secondaryMail, String phoneNumber) { this.idUser = idUser; - this.UserSurname = userSurname; - this.UserName = userName; + this.userSurname = userSurname; + this.userName = userName; this.mainMail = mainMail; this.secondaryMail = secondaryMail; this.phoneNumber = phoneNumber; @@ -54,19 +54,19 @@ public class User { } public String getUserSurname() { - return UserSurname; + return userSurname; } public void setUserSurname(String userSurname) { - UserSurname = userSurname; + userSurname = userSurname; } public String getUserName() { - return UserName; + return userName; } public void setUserName(String userName) { - UserName = userName; + userName = userName; } public String getMainMail() { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AnnotationRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AnnotationRepository.java new file mode 100644 index 0000000..8be8adc --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AnnotationRepository.java @@ -0,0 +1,9 @@ +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.Annotation; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface AnnotationRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/MakeAppointmentRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/MakeAppointmentRepository.java new file mode 100644 index 0000000..c49ef05 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/MakeAppointmentRepository.java @@ -0,0 +1,9 @@ +package enseirb.myinpulse.repository; + +import enseirb.myinpulse.model.MakeAppointment; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface MakeAppointmentRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index c5ae489..975a07d 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -1,57 +1,88 @@ -TRUNCATE projets, user, entrepreneur, sectionCell, rendez_vous, comptes_rendus CASCADE; +TRUNCATE project, user_inpulse, entrepreneur, administrator, section_cell, appointment, report, annotation CASCADE; -INSERT INTO projets (nom_projet, logo, date_creation, status_projet) +SELECT setval('annotation_id_annotation_seq', 1, false); +SELECT setval('appointment_id_appointment_seq', 1, false); +SELECT setval('make_appointment_id_make_appointment_seq', 1, false); +SELECT setval('project_id_project_seq', 1, false); +SELECT setval('report_id_report_seq', 1, false); +SELECT setval('section_cell_id_section_cell_seq', 1, false); +SELECT setval('user_inpulse_id_user_seq', 1, false); + +INSERT INTO user_inpulse (user_surname, user_name, main_mail, secondary_mail, phone_number) +VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), + ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), + ('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), + ('Leguez', 'Theo', 'bof@mesmails.fr', 'bof2@mesmails.fr', '+33 6 78 14 25 29'), + ('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'), + ('Ducaillou', 'Pierre', 'maildefou@xyz.fr', 'maildefou2@xyz.fr', '06 54 78 12 62'), + ('Janine', 'Dave', 'janine@labri.fr', 'janine2@labri.fr', '06 87 12 45 95'); + +INSERT INTO administrator (id_administrator) +VALUES (7); + +INSERT INTO project (project_name, logo, creation_date, project_status, id_administrator) VALUES ('Eau du robinet', decode('013d7d16d7ad4fefb61bd95b765c8ceb', 'hex'), TO_DATE('01-OCT-2023', 'DD-MON-YYYY'), - 'En cours'), - ('Air oxygéné', decode('150647a0984e8f228cd14b54', 'hex'), TO_DATE('04-APR-2024', 'DD-MON-YYYY'), 'En cours'), + 'En cours', 7), + ('Air oxygéné', decode('150647a0984e8f228cd14b54', 'hex'), TO_DATE('04-APR-2024', 'DD-MON-YYYY'), 'En cours', 7), ('Débat concours', decode('022024abd5486e245c145dda65116f', 'hex'), TO_DATE('22-NOV-2023', 'DD-MON-YYYY'), - 'Suspendu'), + 'Suspendu', 7), ('HDeirbMI', decode('ab548d6c1d595a2975e6476f544d14c55a', 'hex'), TO_DATE('07-DEC-2024', 'DD-MON-YYYY'), - 'Lancement'); - -INSERT INTO user (nom_utilisateur, prenom_utilisateur, mail_principal, mail_secondaire, numero_telephone) VALUES -('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), -('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), -('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), -('Leguez', 'Theo', 'bof@mesmails.fr', 'bof2@mesmails.fr', '+33 6 78 14 25 29'), -('Kia', 'Bi', 'special@mail.fr', 'special2@mail.fr', '07 65 31 38 95'), -('Ducaillou', 'Pierre', 'maildefou@xyz.fr', 'maildefou2@xyz.fr', '06 54 78 12 62'); + 'Lancement', 7); -INSERT INTO entrepreneur (ecole, filiere, status_snee, id_entrepreneur) VALUES -('ENSEIRB-MATMECA', 'INFO', TRUE, 1), -('ENSC', 'Cognitique', TRUE, 2), -('ENSEIRB-MATMECA', 'MATMECA', FALSE, 3), -('SupOptique', 'Classique', TRUE, 4), -('ENSEGID', 'Géoscience', FALSE, 5), -('ENSMAC', 'Matériaux composites - Mécanique', FALSE, 6); +INSERT INTO entrepreneur (school, course, snee_status, id_entrepreneur, id_project_participation, id_project_proposed) +VALUES ('ENSEIRB-MATMECA', 'INFO', TRUE, 1, 4, 4), + ('ENSC', 'Cognitique', TRUE, 2, 2, null), + ('ENSEIRB-MATMECA', 'MATMECA', FALSE, 3, 3, 3), + ('SupOptique', 'Classique', TRUE, 4, 1, 1), + ('ENSEGID', 'Géoscience', FALSE, 5, 1, null), + ('ENSMAC', 'Matériaux composites - Mécanique', FALSE, 6, 2, 2); -INSERT INTO sectionCell (titre, contenu_section, date_modification) VALUES -('Problème', 'les problèmes...', TO_TIMESTAMP('15-JAN-2025 09:30:20', 'DD-MON-YYYY, HH24:MI:SS')), -('Segment de client', 'Le segment AB passant le client n°8 est de longueur 32mm. - Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?', TO_TIMESTAMP('12-OCT-2022 17:47:38', 'DD-MON-YYYY, HH24:MI:SS')), -('Proposition de valeur unique', '''Son prix est de 2594€'' ''Ah oui c''est unique en effet', TO_TIMESTAMP('25-MAY-2024 11:12:04', 'DD-MON-YYYY, HH24:MI:SS')), -('Solution', 'Un problème ? Une solution', TO_TIMESTAMP('08-FEB-2024 10:17:53', 'DD-MON-YYYY, HH24:MI:SS')), -('Canaux', 'Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez', TO_TIMESTAMP('19-JUL-2023 19:22:45', 'DD-MON-YYYY, HH24:MI:SS')), -('Sources de revenus', 'Y''en n''a pas on est pas payé. Enfin y''a du café quoi', TO_TIMESTAMP('12-JAN-2025 11:40:26', 'DD-MON-YYYY, HH24:MI:SS')), -('Structure des coûts', '''Ah oui là ça va faire au moins 1000€ par mois'', Eirbware', TO_TIMESTAMP('06-FEB-2025 13:04:06', 'DD-MON-YYYY, HH24:MI:SS')), -('Indicateurs clés', 'On apprend les clés comme des badges, ça se fait', TO_TIMESTAMP('05-FEB-2025 12:42:38', 'DD-MON-YYYY, HH24:MI:SS')), -('Avantages concurrentiel', 'On est meilleur', TO_TIMESTAMP('23-APR-2024 16:24:02', 'DD-MON-YYYY, HH24:MI:SS')); -INSERT INTO rendez_vous (date_rdv, heure_rdv, duree_rdv, lieu_rdv, sujet_rdv) VALUES -(TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', 'À la maison', 'Ouvrir les cadeaux'), -(TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', 'Sur les quais ou dans un champ probablement', 'BOUM BOUM les feux d''artifices (on fête quoi déjà ?)'), -(TO_DATE('28-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', 'Salle TD 15', 'Ah mince c''est pas une année bissextile !'), -(TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', 'Là où le vent nous porte', 'Journée la plus importante de l''année'), -(TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', 'Euh c''est par où l''amphi 56 ?', 'Rentrée scolaire (il fait trop froid c''est quoi ça on est en août)'); +INSERT INTO section_cell (title, content_section_cell, modification_date, id_project) +VALUES ('Problème', 'les problèmes...', TO_TIMESTAMP('15-JAN-2025 09:30:20', 'DD-MON-YYYY, HH24:MI:SS'), 2), + ('Segment de client', 'Le segment AB passant le client n°8 est de longueur 32mm. + Le segment BC a quant à lui un longueur de 28mm. Quelle la longueur du segment AC ?', + TO_TIMESTAMP('12-OCT-2022 17:47:38', 'DD-MON-YYYY, HH24:MI:SS'), 3), + ('Proposition de valeur unique', '''Son prix est de 2594€'' ''Ah oui c''est unique en effet', + TO_TIMESTAMP('25-MAY-2024 11:12:04', 'DD-MON-YYYY, HH24:MI:SS'), 2), + ('Solution', 'Un problème ? Une solution', TO_TIMESTAMP('08-FEB-2024 10:17:53', 'DD-MON-YYYY, HH24:MI:SS'), 1), + ('Canaux', 'Ici nous avons la Seine, là-bas le Rhin, oh et plus loin le canal de Suez', + TO_TIMESTAMP('19-JUL-2023 19:22:45', 'DD-MON-YYYY, HH24:MI:SS'), 4), + ('Sources de revenus', 'Y''en n''a pas on est pas payé. Enfin y''a du café quoi', + TO_TIMESTAMP('12-JAN-2025 11:40:26', 'DD-MON-YYYY, HH24:MI:SS'), 1), + ('Structure des coûts', '''Ah oui là ça va faire au moins 1000€ par mois'', Eirbware', + TO_TIMESTAMP('06-FEB-2025 13:04:06', 'DD-MON-YYYY, HH24:MI:SS'), 3), + ('Indicateurs clés', 'On apprend les clés comme des badges, ça se fait', + TO_TIMESTAMP('05-FEB-2025 12:42:38', 'DD-MON-YYYY, HH24:MI:SS'), 4), + ('Avantages concurrentiel', 'On est meilleur', TO_TIMESTAMP('23-APR-2024 16:24:02', 'DD-MON-YYYY, HH24:MI:SS'), + 2); -INSERT INTO comptes_rendus (contenu_compte_rendu) VALUES -('Ah oui ça c''est super, ah ouais j''aime bien, bien vu de penser à ça'), -('Bonne réunion'), -('Ouais, j''ai rien compris mais niquel on fait comme vous avez dit'), -('Non non ça va pas du tout ce que tu me proposes, faut tout refaire'), -('Réponse de la DSI : non'), -('Trop dommage qu''Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence'); +INSERT INTO appointment (appointment_date, appointment_time, appointment_duration, appointment_place, + appointment_subject) +VALUES (TO_DATE('24-DEC-2023', 'DD-MON-YYYY'), '00:00:00', '00:37:53', 'À la maison', 'Ouvrir les cadeaux'), + (TO_DATE('15-AUG-2024', 'DD-MON-YYYY'), '22:35:00', '00:12:36', 'Sur les quais ou dans un champ probablement', + 'BOUM BOUM les feux d''artifices (on fête quoi déjà ?)'), + (TO_DATE('28-FEB-2023', 'DD-MON-YYYY'), '14:20:00', '00:20:00', 'Salle TD 15', + 'Ah mince c''est pas une année bissextile !'), + (TO_DATE('23-JAN-2024', 'DD-MON-YYYY'), '12:56:27', '11:03:33', 'Là où le vent nous porte', + 'Journée la plus importante de l''année'), + (TO_DATE('25-AUG-2025', 'DD-MON-YYYY'), '00:09:00', '01:00:00', 'Euh c''est par où l''amphi 56 ?', + 'Rentrée scolaire (il fait trop froid c''est quoi ça on est en août)'); + +INSERT INTO report (report_content, id_appointment) +VALUES ('Ah oui ça c''est super, ah ouais j''aime bien, bien vu de penser à ça', 1), + ('Bonne réunion', 3), + ('Ouais, j''ai rien compris mais niquel on fait comme vous avez dit', 3), + ('Non non ça va pas du tout ce que tu me proposes, faut tout refaire', 4), + ('Réponse de la DSI : non', 2), + ('Trop dommage qu''Apple ait sorti leur logiciel avant nous, on avait la même idée et tout on aurait tellement pu leur faire de la concurrence', + 5); + +INSERT INTO annotation (comment, id_administrator, id_section_cell) +VALUES ('faut changer ça hein', 7, 5), + ('??? sérieusement, vous pensez que c''est une bonne idée ?', 7, 7), + ('ok donc ça c''est votre business plan, bah glhf la team', 7, 2); diff --git a/MyINPulse-back/src/main/resources/delete.sql b/MyINPulse-back/src/main/resources/delete.sql index fb9e00a..866a291 100644 --- a/MyINPulse-back/src/main/resources/delete.sql +++ b/MyINPulse-back/src/main/resources/delete.sql @@ -1 +1,2 @@ -DROP TABLE IF EXISTS administrator, projets, user, entrepreneur, sectionCell, rendez_vous, comptes_rendus, concerner CASCADE; \ No newline at end of file +DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE; +DROP TABLE IF EXISTS administrator, project, user_inpulse, entrepreneur, section_cell, appointment, make_appointment, report, annotation, concern CASCADE; \ No newline at end of file diff --git a/MyINPulse-back/src/main/resources/schema.sql b/MyINPulse-back/src/main/resources/schema.sql deleted file mode 100644 index b7b4f87..0000000 --- a/MyINPulse-back/src/main/resources/schema.sql +++ /dev/null @@ -1,134 +0,0 @@ -DROP TABLE IF EXISTS projets CASCADE; -DROP TABLE IF EXISTS user CASCADE; -DROP TABLE IF EXISTS entrepreneur CASCADE; -DROP TABLE IF EXISTS administrator CASCADE; -DROP TABLE IF EXISTS sectionCell CASCADE; -DROP TABLE IF EXISTS rendez_vous CASCADE; -DROP TABLE IF EXISTS comptes_rendus CASCADE; -DROP TABLE IF EXISTS concerner CASCADE; -DROP TABLE IF EXISTS formes CASCADE; - -CREATE TABLE projets -( - id_projet SERIAL NOT NULL, - nom_projet VARCHAR(255), - logo BYTEA, - date_creation DATE, - status_projet VARCHAR(255), - CONSTRAINT pk_projet PRIMARY KEY (id_projet) -); - -CREATE TABLE user -( -id_utilisateur SERIAL NOT NULL, -nom_utilisateur VARCHAR(255) , -prenom_utilisateur VARCHAR(255) , -mail_principal VARCHAR(255) , -mail_secondaire VARCHAR(255) , -numero_telephone VARCHAR(20) , -CONSTRAINT pk_utilisateur PRIMARY KEY (id_utilisateur) ); - -CREATE TABLE entrepreneur -( - id_entrepreneur SERIAL REFERENCES user (id_utilisateur), - ecole VARCHAR(255), - filiere VARCHAR(255), - status_snee BOOLEAN, - CONSTRAINT pk_entrepreneur PRIMARY KEY (id_entrepreneur) -); - -CREATE TABLE administrator -( - id_administrateur SERIAL REFERENCES user (id_utilisateur), - CONSTRAINT pk_administrateur PRIMARY KEY (id_administrateur) -); - -CREATE TABLE sectionCell -( - id_section SERIAL NOT NULL, - titre VARCHAR(255), - contenu_section TEXT, - date_modification TIMESTAMP, - CONSTRAINT pk_section PRIMARY KEY (id_section) -); - -CREATE TABLE rendez_vous -( - id_rdv SERIAL NOT NULL, - date_rdv DATE, - heure_rdv TIME, - duree_rdv TIME, - lieu_rdv VARCHAR(255), - sujet_rdv TEXT, - CONSTRAINT pk_rdv PRIMARY KEY (id_rdv) -); - -CREATE TABLE comptes_rendus -( - id_compte_rendu SERIAL NOT NULL, - contenu_compte_rendu TEXT, - CONSTRAINT pk_compte_rendu PRIMARY KEY (id_compte_rendu) -); - -CREATE TABLE concerner -( - id_section SERIAL REFERENCES sectionCell (id_section), - id_rdv SERIAL REFERENCES sectionCell (id_rdv), - CONSTRAINT pk_concerner PRIMARY KEY (id_section, id_rdv) -); - - -ALTER TABLE projets - ADD CONSTRAINT fk1_projet FOREIGN KEY (id_administrateur) - REFERENCES administrator (id_administrateur) - ON DELETE CASCADE; - -ALTER TABLE projets - ADD CONSTRAINT fk2_projet FOREIGN KEY (id_entrepreneur_participation) - REFERENCES entrepreneur (id_entrepreneur) - ON DELETE CASCADE; - -ALTER TABLE entrepreneur - ADD CONSTRAINT fk1_entrepreneur FOREIGN KEY (id_projet_propose) - REFERENCES projets (id_projet) - ON DELETE CASCADE; - -ALTER TABLE sectionCell - ADD CONSTRAINT fk1_section FOREIGN KEY (id_projet) - REFERENCES projets (id_projet) - ON DELETE CASCADE; - -ALTER TABLE sectionCell - ADD CONSTRAINT fk2_section FOREIGN KEY (id_administrateur) - REFERENCES administrator (id_administrateur) - ON DELETE CASCADE; - -ALTER TABLE rendez-vous - ADD CONSTRAINT fk1_rdv FOREIGN KEY (id_entrepreneur) - REFERENCES entrepreneur (id_entrepreneur) - ON -DELETE -CASCADE; - -ALTER TABLE rendez-vous - ADD CONSTRAINT fk2_rdv FOREIGN KEY (id_administrateur) - REFERENCES administrator (id_administrateur) - ON -DELETE -CASCADE; - -ALTER TABLE comptes-rendus - ADD CONSTRAINT fk1_compte_rendu FOREIGN KEY (id_rdv) - REFERENCES rendez_vous (id_rdv) - ON -DELETE -CASCADE; - - - - - - - - - -- 2.47.2 From e66fa3357784a3f26d7ea9f66d60f143fc4d9814 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 10:32:44 +0100 Subject: [PATCH 47/97] feat: added a new database service --- ...ectController.java => ProjectService.java} | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) rename MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/{old_controllers_to_convert_to_services/ProjectController.java => ProjectService.java} (72%) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java similarity index 72% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index ffbc8e4..c697a64 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ProjectController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -1,29 +1,32 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; +package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.ProjectRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; +import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; import java.time.LocalDate; import java.util.Optional; -@RestController -public class ProjectController { +@Service +public class ProjectService { - @Autowired ProjectRepository projectRepository; + private final ProjectRepository projectRepository; - @GetMapping("/Project") - @ResponseBody - public Iterable allProjects() { + @Autowired + ProjectService(ProjectRepository projectRepository) { + this.projectRepository = projectRepository; + } + + public Iterable getAllProjects() { return this.projectRepository.findAll(); } - @GetMapping("/Project/{id}") - public Project getProjectById(@PathVariable Long id) { + // TODO: change error + public Project getProjectById(Long id) { Optional project = this.projectRepository.findById(id); if (project.isEmpty()) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); @@ -31,14 +34,13 @@ public class ProjectController { return project.get(); } - @PostMapping("/Project") - public Project addProject(@RequestBody Project project) { + // TODO: validation + public Project addNewProject(Project project) { return this.projectRepository.save(project); } - @PostMapping("/Project/{id}") public Project updateProject( - @PathVariable Long id, + Long id, String projectName, byte[] logo, LocalDate creationDate, -- 2.47.2 From d8bc7cc9b6fce7dbad3695546053adb848007b0e Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 14:28:31 +0100 Subject: [PATCH 48/97] feat: added log4j. It's way better than System.stderr. --- MyINPulse-back/build.gradle | 34 +++++----- .../database/AdministratorService.java | 4 ++ .../service/database/UserService.java | 4 ++ .../AdministratorController.java | 38 ----------- .../UserController.java | 67 ------------------- MyINPulse-back/src/main/resources/log4j2.xml | 14 ++++ 6 files changed, 40 insertions(+), 121 deletions(-) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java create mode 100644 MyINPulse-back/src/main/resources/log4j2.xml diff --git a/MyINPulse-back/build.gradle b/MyINPulse-back/build.gradle index abb4635..367d3ec 100644 --- a/MyINPulse-back/build.gradle +++ b/MyINPulse-back/build.gradle @@ -1,33 +1,35 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.4.2' - id 'io.spring.dependency-management' version '1.1.7' + id 'java' + id 'org.springframework.boot' version '3.4.2' + id 'io.spring.dependency-management' version '1.1.7' } group = 'enseirb' version = '0.0.1-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-validation' - implementation 'org.springframework.boot:spring-boot-starter-data-rest' - implementation 'org.postgresql:postgresql' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-data-rest' + implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.16.0' + implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.16.0' + implementation 'org.postgresql:postgresql' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java new file mode 100644 index 0000000..de9f1ef --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java @@ -0,0 +1,4 @@ +package enseirb.myinpulse.service.database; + +public class AdministratorService { +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java new file mode 100644 index 0000000..5ddc9a5 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java @@ -0,0 +1,4 @@ +package enseirb.myinpulse.service.database; + +public class UserService { +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java deleted file mode 100644 index 7e2706a..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AdministratorController.java +++ /dev/null @@ -1,38 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Administrator; -import enseirb.myinpulse.repository.AdministratorRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class AdministratorController { - - @Autowired AdministratorRepository administratorRepository; - - @GetMapping("/Administrator") - @ResponseBody - public Iterable allAdministrators() { - return this.administratorRepository.findAll(); - } - - @GetMapping("/Administrator/{id}") - public Administrator getAdministratorById(@PathVariable Long id) { - Optional administrator = this.administratorRepository.findById(id); - if (administrator.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); - } - return administrator.get(); - } - - @PostMapping("/Administrateurs") - public Administrator addAdministrator(@RequestBody Administrator administrator) { - return this.administratorRepository.save(administrator); - } -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java deleted file mode 100644 index a9abc1f..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/UserController.java +++ /dev/null @@ -1,67 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.User; -import enseirb.myinpulse.repository.UserRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.util.Optional; - -@RestController -public class UserController { - - @Autowired UserRepository userRepository; - - @GetMapping("/User") - @ResponseBody - public Iterable allUsers() { - return this.userRepository.findAll(); - } - - @GetMapping("/User/{id}") - public User getUserById(@PathVariable Long id) { - Optional user = userRepository.findById(id); - if (user.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - return user.get(); - } - - @PostMapping("/User") - public User addUser(@RequestBody User user) { - return this.userRepository.save(user); - } - - @PostMapping("/User/{id}") - public User updateUser( - @PathVariable Long id, - String userSurname, - String userName, - String mainMail, - String secondaryMail, - String phoneNumber) { - Optional user = userRepository.findById(id); - if (user.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); - } - if (userName != null) { - user.get().setUserName(userName); - } - if (userSurname != null) { - user.get().setUserSurname(userSurname); - } - if (mainMail != null) { - user.get().setMainMail(mainMail); - } - if (secondaryMail != null) { - user.get().setSecondaryMail(secondaryMail); - } - if (phoneNumber != null) { - user.get().setPhoneNumber(phoneNumber); - } - return this.userRepository.save(user.get()); - } -} diff --git a/MyINPulse-back/src/main/resources/log4j2.xml b/MyINPulse-back/src/main/resources/log4j2.xml new file mode 100644 index 0000000..5616b9b --- /dev/null +++ b/MyINPulse-back/src/main/resources/log4j2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file -- 2.47.2 From 1cebebf1a5e8928fad2adac48be365980c87bc68 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 14:29:38 +0100 Subject: [PATCH 49/97] feat: implemented most of the backend api for administrator --- .../myinpulse/controller/AdminApi.java | 8 +-- .../java/enseirb/myinpulse/model/Project.java | 20 +++--- .../myinpulse/model/ProjectDecision.java | 6 +- .../java/enseirb/myinpulse/model/User.java | 14 ++-- .../repository/ProjectRepository.java | 7 +- .../myinpulse/repository/UserRepository.java | 3 + .../myinpulse/service/AdminApiService.java | 51 +++++++++---- .../database/AdministratorService.java | 39 ++++++++++ .../service/database/ProjectService.java | 43 ++++++++++- .../service/database/UserService.java | 72 +++++++++++++++++++ MyINPulse-back/src/main/resources/data.sql | 2 +- 11 files changed, 223 insertions(+), 42 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java index d409ffe..b5f3866 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java @@ -26,8 +26,8 @@ public class AdminApi { * @return a list of all project managed by the current admin user */ @GetMapping("/admin/projects") - public Iterable getProjects() { - return adminApiService.getProjects(); + public Iterable getProjects(@AuthenticationPrincipal Jwt principal) { + return adminApiService.getProjectsOfAdmin(principal.getClaimAsString("email")); } /** @@ -53,7 +53,7 @@ public class AdminApi { /** * Endpoint used to make a decision about a project. * - *

The decision must contains the administrator + *

The decision must contain the administrator * * @return the status code of the request */ @@ -96,7 +96,7 @@ public class AdminApi { * @return the status code of the request */ @DeleteMapping("/admin/projects/remove/{projectId}") - public void deleteProject(@PathVariable String projectId) { + public void deleteProject(@PathVariable long projectId) { adminApiService.deleteProject(projectId); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index 824de16..057b390 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -11,34 +11,26 @@ import java.util.List; @Table(name = "project") public class Project { + @OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true) + private final List listEntrepreneurParticipation = new ArrayList<>(); + @OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) + private final List listSectionCell = new ArrayList<>(); @Id @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idProject; - @Column(length = 255) private String projectName; - private byte[] logo; - private LocalDate creationDate; - @Column(length = 255) private String projectStatus; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idAdministrator") private Administrator projectAdministrator; - - @OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true) - private List listEntrepreneurParticipation = new ArrayList<>(); - @OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true) private Entrepreneur entrepreneurProposed; - @OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) - private List listSectionCell = new ArrayList<>(); - public Project() {} public Project( @@ -93,4 +85,8 @@ public class Project { public void setProjectStatus(String projectStatus) { this.projectStatus = projectStatus; } + + public void setAdministrator(Administrator administrator) { + this.projectAdministrator = administrator; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java index 8eb9976..a2d3575 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java @@ -1,7 +1,7 @@ package enseirb.myinpulse.model; public class ProjectDecision { - int projectId; - int adminId; - int isAccepted; + public long projectId; + public long adminId; + public long isAccepted; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java index 6ab965e..c23b285 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java @@ -20,7 +20,7 @@ public class User { private String userName; @Column(length = 255) - private String mainMail; + private String primaryMail; @Column(length = 255) private String secondaryMail; @@ -34,13 +34,13 @@ public class User { Long idUser, String userSurname, String userName, - String mainMail, + String primaryMail, String secondaryMail, String phoneNumber) { this.idUser = idUser; this.userSurname = userSurname; this.userName = userName; - this.mainMail = mainMail; + this.primaryMail = primaryMail; this.secondaryMail = secondaryMail; this.phoneNumber = phoneNumber; } @@ -69,12 +69,12 @@ public class User { userName = userName; } - public String getMainMail() { - return mainMail; + public String getPrimaryMail() { + return primaryMail; } - public void setMainMail(String mainMail) { - this.mainMail = mainMail; + public void setPrimaryMail(String mainMail) { + this.primaryMail = mainMail; } public String getSecondaryMail() { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java index 0da05d7..2911655 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java @@ -1,9 +1,14 @@ package enseirb.myinpulse.repository; +import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Project; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ProjectRepository extends JpaRepository {} +public interface ProjectRepository extends JpaRepository { + Iterable findByProjectAdministrator(Administrator administrator); + + Iterable findByProjectStatus(String status); +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java index 7dd3089..291a97d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java @@ -5,8 +5,11 @@ import enseirb.myinpulse.model.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import java.util.Optional; + @RepositoryRestResource public interface UserRepository extends JpaRepository { + Optional findByPrimaryMail(String email); /* @Query("SELECT u from User u") User findAllUser(); */ diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index e1df66b..6d5806b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -1,16 +1,37 @@ package enseirb.myinpulse.service; import enseirb.myinpulse.model.*; +import enseirb.myinpulse.service.database.AdministratorService; +import enseirb.myinpulse.service.database.ProjectService; +import enseirb.myinpulse.service.database.UserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; @Service public class AdminApiService { - // TODO - public Iterable getProjects() { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + + private final ProjectService projectService; + private final UserService userService; + private final AdministratorService administratorService; + + @Autowired + AdminApiService( + ProjectService projectService, + UserService userService, + AdministratorService administratorService) { + this.projectService = projectService; + this.userService = userService; + this.administratorService = administratorService; + } + + // TODO: test + public Iterable getProjectsOfAdmin(String email) { + return projectService.getProjectsByAdminId( + administratorService.getAdministratorById( + this.userService.getIdUserByEmail(email))); } // TODO @@ -18,19 +39,25 @@ public class AdminApiService { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - // TODO + // TODO: test public Iterable getPendingProjects() { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + return this.projectService.getPendingProjects(); } - // TODO + // TODO: test public void validateProject(ProjectDecision decision) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + projectService.updateProject( + decision.projectId, + null, + null, + null, + "ACTIVE", + this.administratorService.getAdministratorById(decision.projectId)); } - // TODO + // TODO: solve todo + test public void addNewProject(Project project) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + projectService.addNewProject(project); // TODO: how can the user know the ID ? } // TODO @@ -38,8 +65,8 @@ public class AdminApiService { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - // TODO - public void deleteProject(String projectId) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + // TODO: test + public void deleteProject(long projectId) { + this.projectService.deleteProjectById(projectId); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java index de9f1ef..645e00d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java @@ -1,4 +1,43 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.repository.AdministratorRepository; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@Service public class AdministratorService { + protected static final Logger logger = LogManager.getLogger(); + + private final AdministratorRepository administratorRepository; + + @Autowired + AdministratorService(AdministratorRepository administratorRepository) { + this.administratorRepository = administratorRepository; + } + + public Iterable allAdministrators() { + return this.administratorRepository.findAll(); + } + + public Administrator getAdministratorById(long id) { + Optional administrator = this.administratorRepository.findById(id); + if (administrator.isEmpty()) { + logger.error("No administrator found with id {}", id); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + return administrator.get(); + } + + public Administrator addAdministrator(Administrator administrator) { + return this.administratorRepository.save(administrator); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index c697a64..d073b26 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -1,19 +1,25 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.ProjectRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; import java.time.LocalDate; +import java.util.List; import java.util.Optional; @Service public class ProjectService { + protected static final Logger logger = LogManager.getLogger(); + private final ProjectRepository projectRepository; @Autowired @@ -25,15 +31,19 @@ public class ProjectService { return this.projectRepository.findAll(); } - // TODO: change error public Project getProjectById(Long id) { Optional project = this.projectRepository.findById(id); if (project.isEmpty()) { + System.err.println("Project with id " + id + " not found"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); } return project.get(); } + public Iterable getProjectsByAdminId(Administrator administrator) { + return this.projectRepository.findByProjectAdministrator(administrator); + } + // TODO: validation public Project addNewProject(Project project) { return this.projectRepository.save(project); @@ -44,23 +54,52 @@ public class ProjectService { String projectName, byte[] logo, LocalDate creationDate, - String projectStatus) { + String projectStatus, + Administrator administrator) { Optional project = this.projectRepository.findById(id); + if (project.isEmpty()) { + logger.error("Project with id {} not found.", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); } + if (projectName != null) { project.get().setProjectName(projectName); } + if (logo != null) { project.get().setLogo(logo); } + if (creationDate != null) { project.get().setCreationDate(creationDate); } + if (projectStatus != null) { + if (!validateStatus(projectStatus)) { + System.err.println("updateProjectStatus: Invalid status " + projectStatus); + throw new ResponseStatusException( + HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté"); + } project.get().setProjectStatus(projectStatus); } + + if (administrator != null) { + project.get().setAdministrator(administrator); + } + return this.projectRepository.save(project.get()); } + + public Boolean validateStatus(String status) { + return List.of("PENDING", "ACTIVE", "ENDED").contains(status); + } + + public Iterable getPendingProjects() { + return this.projectRepository.findByProjectStatus("PENDING"); + } + + public void deleteProjectById(Long id) { + this.projectRepository.deleteById(id); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java index 5ddc9a5..6c3f33f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java @@ -1,4 +1,76 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.User; +import enseirb.myinpulse.repository.UserRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@Service public class UserService { + private final UserRepository userRepository; + + @Autowired + UserService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + public Iterable getAllUsers() { + return this.userRepository.findAll(); + } + + // TODO + public long getIdUserByEmail(String email) { + Optional opt_user = this.userRepository.findByPrimaryMail(email); + + if (opt_user.isEmpty()) { + System.err.println("Couldn't find user with email " + email); + throw new ResponseStatusException(HttpStatus.NOT_FOUND); + } + User user = opt_user.get(); + return user.getIdUser(); + } + + public Iterable allUsers() { + return this.userRepository.findAll(); + } + + public User addUser(@RequestBody User user) { + return this.userRepository.save(user); + } + + public User updateUser( + @PathVariable Long id, + String userSurname, + String userName, + String mainMail, + String secondaryMail, + String phoneNumber) { + Optional user = userRepository.findById(id); + if (user.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + if (userName != null) { + user.get().setUserName(userName); + } + if (userSurname != null) { + user.get().setUserSurname(userSurname); + } + if (mainMail != null) { + user.get().setPrimaryMail(mainMail); + } + if (secondaryMail != null) { + user.get().setSecondaryMail(secondaryMail); + } + if (phoneNumber != null) { + user.get().setPhoneNumber(phoneNumber); + } + return this.userRepository.save(user.get()); + } } diff --git a/MyINPulse-back/src/main/resources/data.sql b/MyINPulse-back/src/main/resources/data.sql index 975a07d..444f8da 100644 --- a/MyINPulse-back/src/main/resources/data.sql +++ b/MyINPulse-back/src/main/resources/data.sql @@ -8,7 +8,7 @@ SELECT setval('report_id_report_seq', 1, false); SELECT setval('section_cell_id_section_cell_seq', 1, false); SELECT setval('user_inpulse_id_user_seq', 1, false); -INSERT INTO user_inpulse (user_surname, user_name, main_mail, secondary_mail, phone_number) +INSERT INTO user_inpulse (user_surname, user_name, primary_mail, secondary_mail, phone_number) VALUES ('Dupont', 'Dupond', 'super@mail.fr', 'super2@mail.fr', '06 45 72 45 98'), ('Martin', 'Matin', 'genial@mail.fr', 'genial2@mail.fr', '06 52 14 58 73'), ('Charvet', 'Lautre', 'mieux@tmail.fr', 'mieux2@tmail.fr', '07 49 82 16 35'), -- 2.47.2 From 024deeba418109e54d69923683884c1f518057cc Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 14:30:58 +0100 Subject: [PATCH 50/97] fix: linter - how did this append ? --- .../src/main/java/enseirb/myinpulse/model/Project.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index 057b390..96dcbb4 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -13,21 +13,28 @@ public class Project { @OneToMany(mappedBy = "projectParticipation", fetch = FetchType.LAZY, orphanRemoval = true) private final List listEntrepreneurParticipation = new ArrayList<>(); + @OneToMany(mappedBy = "projectSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) private final List listSectionCell = new ArrayList<>(); + @Id @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idProject; + @Column(length = 255) private String projectName; + private byte[] logo; private LocalDate creationDate; + @Column(length = 255) private String projectStatus; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idAdministrator") private Administrator projectAdministrator; + @OneToOne(mappedBy = "projectProposed", fetch = FetchType.LAZY, orphanRemoval = true) private Entrepreneur entrepreneurProposed; -- 2.47.2 From dd5ca2cbd74fea623afe95409797994190615173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 26 Feb 2025 14:51:02 +0100 Subject: [PATCH 51/97] feat: entrepreneur api and api service --- .../myinpulse/controller/EntrepreneurApi.java | 27 ++++---- .../enseirb/myinpulse/model/Annotation.java | 2 +- .../service/EntrepreneurApiService.java | 55 +++++++++++++--- .../service/database/AnnotationService.java | 54 ++++++++++++++++ .../service/database/SectionCellService.java | 63 +++++++++++++++++++ 5 files changed, 176 insertions(+), 25 deletions(-) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java index 2ace1c7..b0de5b7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/EntrepreneurApi.java @@ -1,6 +1,6 @@ package enseirb.myinpulse.controller; -import enseirb.myinpulse.model.LCSection; +import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.service.EntrepreneurApiService; @@ -29,12 +29,12 @@ public class EntrepreneurApi { * @return status code */ @PutMapping("/entrepreneur/lcsection/modify/{sectionId}") - public void editLCSection( - @PathVariable String sectionId, - @RequestBody LCSection section, + public void editSectionCell( + @PathVariable Long sectionId, + @RequestBody SectionCell sectionCell, @AuthenticationPrincipal Jwt principal) { - entrepreneurApiService.editLCSection( - sectionId, section, principal.getClaimAsString("email")); + entrepreneurApiService.editSectionCell( + sectionId, sectionCell, principal.getClaimAsString("email")); } /** @@ -45,9 +45,9 @@ public class EntrepreneurApi { * @return status code */ @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") - public void removeLCSection( - @PathVariable String sectionId, @AuthenticationPrincipal Jwt principal) { - entrepreneurApiService.removeLCSection(sectionId, principal.getClaimAsString("email")); + public void removeSectionCell( + @PathVariable Long sectionId, @AuthenticationPrincipal Jwt principal) { + entrepreneurApiService.removeSectionCell(sectionId, principal.getClaimAsString("email")); } /** @@ -57,13 +57,10 @@ public class EntrepreneurApi { * * @return status code */ - @PostMapping("/entrepreneur/lcsection/add/{sectionId}") + @PostMapping("/entrepreneur/lcsection/add") // remove id from doc aswell public void addLCSection( - @PathVariable String sectionId, - @RequestBody LCSection section, - @AuthenticationPrincipal Jwt principal) { - entrepreneurApiService.addLCSection( - sectionId, section, principal.getClaimAsString("email")); + @RequestBody SectionCell sectionCell, @AuthenticationPrincipal Jwt principal) { + entrepreneurApiService.addSectionCell(sectionCell, principal.getClaimAsString("email")); } /** diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java index e7e9b3e..fa73e0d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java @@ -33,7 +33,7 @@ public class Annotation { return comment; } - public void setCommentary(String comment) { + public void setComment(String comment) { this.comment = comment; } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index 80d06ba..d22a6a9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -1,29 +1,66 @@ package enseirb.myinpulse.service; -import enseirb.myinpulse.model.LCSection; import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.SectionCell; +import enseirb.myinpulse.service.database.ProjectService; +import enseirb.myinpulse.service.database.SectionCellService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; @Service public class EntrepreneurApiService { - public void editLCSection(String sectionId, LCSection section, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + private final SectionCellService sectionCellService; + private final ProjectService projectService; + + @Autowired + EntrepreneurApiService(SectionCellService sectionCellService, ProjectService projectService) { + this.sectionCellService = sectionCellService; + this.projectService = projectService; } - public void removeLCSection(String sectionId, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) { + SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId); + if (editSectionCell == null) { + System.err.println("Trying to edit unknown section cell"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); + } + sectionCellService.updateSectionCell( + sectionCellId, + sectionCell.getTitle(), + sectionCell.getContentSectionCell(), + sectionCell.getModificationDate()); } - public void addLCSection(String sectionId, LCSection section, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + public void removeSectionCell(Long sectionCellId, String mail) { + SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId); + if (editSectionCell == null) { + System.err.println("Trying to remove unknown section cell"); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); + } + sectionCellService.removeSectionCellById(sectionCellId); + } + + public void addSectionCell(SectionCell sectionCell, String mail) { + if (sectionCell == null) { + System.err.println("Trying to create an empty section cell"); + throw new ResponseStatusException( + HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide"); + } + sectionCellService.addNewSectionCell(sectionCell); } public void requestNewProject(Project project, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + if (project == null) { + System.err.println("Trying to request the creation of a null project"); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide"); + } + project.setProjectStatus("PENDING"); + projectService.addNewProject(project); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java new file mode 100644 index 0000000..225ef06 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java @@ -0,0 +1,54 @@ +package enseirb.myinpulse.service.database; + +import enseirb.myinpulse.model.Annotation; +import enseirb.myinpulse.repository.AnnotationRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Optional; + +@Service +public class AnnotationService { + + private final AnnotationRepository annotationRepository; + + @Autowired + AnnotationService(AnnotationRepository annotationRepository) { + this.annotationRepository = annotationRepository; + } + + public Iterable getAllAnnotations() { + return annotationRepository.findAll(); + } + + public Annotation getAnnotationById(Long id) { + Optional annotation = annotationRepository.findById(id); + if (annotation.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette annotation n'existe pas"); + } + return annotation.get(); + } + + public Annotation addNewAnnotation(Annotation annotation) { + return this.annotationRepository.save(annotation); + } + + public void deleteAnnotationById(Long id) { + this.annotationRepository.deleteById(id); + } + + public Annotation updateAnnotation(Long id, String comment) { + Optional annotation = annotationRepository.findById(id); + if (annotation.isEmpty()) { + return null; + } + if (comment != null) { + annotation.get().setComment(comment); + } + return this.annotationRepository.save(annotation.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java new file mode 100644 index 0000000..c65f770 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java @@ -0,0 +1,63 @@ +package enseirb.myinpulse.service.database; + +import enseirb.myinpulse.model.SectionCell; +import enseirb.myinpulse.repository.SectionCellRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDateTime; +import java.util.Optional; + +@Service +public class SectionCellService { + + private final SectionCellRepository sectionCellRepository; + + @Autowired + SectionCellService(SectionCellRepository sectionCellRepository) { + this.sectionCellRepository = sectionCellRepository; + } + + public Iterable getAllSectionCells() { + return this.sectionCellRepository.findAll(); + } + + public SectionCell getSectionCellById(Long id) { + Optional sectionCell = this.sectionCellRepository.findById(id); + if (sectionCell.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); + } + return sectionCell.get(); + } + + public SectionCell addNewSectionCell(SectionCell sectionCell) { + return this.sectionCellRepository.save(sectionCell); + } + + public void removeSectionCellById(Long id) { + this.sectionCellRepository.deleteById(id); + } + + public SectionCell updateSectionCell( + Long id, String title, String contentSectionCell, LocalDateTime modificationDate) { + Optional sectionCell = this.sectionCellRepository.findById(id); + if (sectionCell.isEmpty()) { + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); + } + if (title != null) { + sectionCell.get().setTitle(title); + } + if (contentSectionCell != null) { + sectionCell.get().setContentSectionCell(contentSectionCell); + } + if (modificationDate != null) { + sectionCell.get().setModificationDate(modificationDate); + } + return this.sectionCellRepository.save(sectionCell.get()); + } +} -- 2.47.2 From 1a6db7c953488198b9edb89bbd31ced9e47d359e Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 15:29:55 +0100 Subject: [PATCH 52/97] feat: added color in logs --- ...eurController.java => EntrepreneurService.java} | 0 .../src/main/resources/application.properties | 1 + MyINPulse-back/src/main/resources/log4j2.xml | 14 -------------- 3 files changed, 1 insertion(+), 14 deletions(-) rename MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/{old_controllers_to_convert_to_services/EntrepreneurController.java => EntrepreneurService.java} (100%) delete mode 100644 MyINPulse-back/src/main/resources/log4j2.xml diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneurController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java similarity index 100% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/EntrepreneurController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index 08dccb9..a6e039e 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -6,3 +6,4 @@ spring.datasource.url=jdbc:postgresql://${DATABASE_URL}/${BACKEND_DB} spring.datasource.username=${BACKEND_USER} spring.datasource.password=${BACKEND_PASSWORD} spring.jpa.hibernate.ddl-auto=update +logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n \ No newline at end of file diff --git a/MyINPulse-back/src/main/resources/log4j2.xml b/MyINPulse-back/src/main/resources/log4j2.xml deleted file mode 100644 index 5616b9b..0000000 --- a/MyINPulse-back/src/main/resources/log4j2.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file -- 2.47.2 From 8d4dc7916d0b99a5a9b7a660d5867fb80f888c57 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 15:31:02 +0100 Subject: [PATCH 53/97] feat: added most of shared API calls --- .../myinpulse/controller/SharedApi.java | 4 +- .../enseirb/myinpulse/model/Entrepreneur.java | 4 + .../java/enseirb/myinpulse/model/Project.java | 4 + .../repository/AdministratorRepository.java | 2 + .../repository/EntrepreneurRepository.java | 3 + .../myinpulse/service/AdminApiService.java | 4 +- .../myinpulse/service/SharedApiService.java | 78 ++++++++++++++++++- .../database/AdministratorService.java | 6 ++ .../service/database/EntrepreneurService.java | 32 ++++---- .../service/database/UserService.java | 5 +- 10 files changed, 117 insertions(+), 25 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index 4424c10..883cc9f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -54,10 +54,10 @@ public class SharedApi { /** * Endpoint used to get the administrator of a project. * - * @return a list of all project managed by the current admin user + * @return the admin of a project */ @GetMapping("/shared/projects/admin/{projectId}") - public Iterable getAdminByProjectId( + public Administrator getAdminByProjectId( @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) { return sharedApiService.getAdminByProjectId(projectId, principal.getClaimAsString("email")); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java index 3773cea..d85c99d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java @@ -75,4 +75,8 @@ public class Entrepreneur extends User { public void setSneeStatus(boolean statusSnee) { this.sneeStatus = sneeStatus; } + + public Project getProjectParticipation() { + return projectParticipation; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index 96dcbb4..070efc6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -93,6 +93,10 @@ public class Project { this.projectStatus = projectStatus; } + public Administrator getAdministrator() { + return this.projectAdministrator; + } + public void setAdministrator(Administrator administrator) { this.projectAdministrator = administrator; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java index 34431fd..c9f3e50 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java @@ -8,6 +8,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface AdministratorRepository extends JpaRepository { + //public Administrator findByListProjectIsContaining(Project project); + /* @Query("SELECT a from Administrators a") Administrator findAllAdministrator(); */ diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java index eee1020..15a2222 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/EntrepreneurRepository.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.repository; import enseirb.myinpulse.model.Entrepreneur; +import enseirb.myinpulse.model.Project; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @@ -8,6 +9,8 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface EntrepreneurRepository extends JpaRepository { + Iterable getEntrepreneurByProjectParticipation(Project project); + /* @Query("SELECT e from Entrepreneur e") Entrepreneur findAllEntrepreneurl(); */ diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 6d5806b..400c2b6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -31,7 +31,7 @@ public class AdminApiService { public Iterable getProjectsOfAdmin(String email) { return projectService.getProjectsByAdminId( administratorService.getAdministratorById( - this.userService.getIdUserByEmail(email))); + this.userService.getUserByEmail(email).getIdUser())); } // TODO @@ -57,7 +57,7 @@ public class AdminApiService { // TODO: solve todo + test public void addNewProject(Project project) { - projectService.addNewProject(project); // TODO: how can the user know the ID ? + projectService.addNewProject(project); // TODO: how can the front know the ID ? } // TODO diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index ea45245..e104cdd 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -1,7 +1,14 @@ package enseirb.myinpulse.service; import enseirb.myinpulse.model.*; +import enseirb.myinpulse.service.database.AdministratorService; +import enseirb.myinpulse.service.database.EntrepreneurService; +import enseirb.myinpulse.service.database.ProjectService; +import enseirb.myinpulse.service.database.UserService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; @@ -9,17 +16,80 @@ import org.springframework.web.server.ResponseStatusException; @Service public class SharedApiService { + protected static final Logger logger = LogManager.getLogger(); + + private final AdministratorService administratorService; + private final UserService userService; + private final ProjectService projectService; + private final EntrepreneurService entrepreneurService; + + @Autowired + SharedApiService( + AdministratorService administratorService, + UserService userService, + ProjectService projectService, + EntrepreneurService entrepreneurService) { + this.administratorService = administratorService; + this.userService = userService; + this.projectService = projectService; + this.entrepreneurService = entrepreneurService; + } + + // TODO: test + Boolean isAnAdmin(String mail) { + try { + long userId = this.userService.getUserByEmail(mail).getIdUser(); + Administrator a = this.administratorService.getAdministratorById(userId); + return true; + } catch (ResponseStatusException e) { + logger.info(e); + return false; + } + } + + // TODO: test + Boolean isAllowedToCheckProject(String mail, long projectId) { + if (isAnAdmin(mail)) { + return true; + } + User user = this.userService.getUserByEmail(mail); + Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); + Project project = this.projectService.getProjectById(projectId); + return entrepreneur.getProjectParticipation() == project; + } + + // TODO public Iterable getLCSection( String projectId, String title, String date, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - public Iterable getEntrepreneursByProjectId(int projectId, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + // TODO: test, protect via email + public Iterable getEntrepreneursByProjectId(long projectId, String mail) { + if (!isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to check the member of the project {} but is not allowed to.", + mail, + projectId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + Project project = this.projectService.getProjectById(projectId); + return this.entrepreneurService.GetEntrepreneurByProject(project); } - public Iterable getAdminByProjectId(int projectId, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + // TODO: test, protect via email + public Administrator getAdminByProjectId(long projectId, String mail) { + if (!isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to check the admin of the project {} but is not allowed to.", + mail, + projectId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + Project project = this.projectService.getProjectById(projectId); + return project.getAdministrator(); } public Iterable getAppointmentsByProjectId(int projectId, String mail) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java index 645e00d..0f595a0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java @@ -40,4 +40,10 @@ public class AdministratorService { public Administrator addAdministrator(Administrator administrator) { return this.administratorRepository.save(administrator); } + + /* + public Administrator getAdministratorByProject(Project project) { + r + } + */ } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java index 3e72159..6e85920 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java @@ -1,28 +1,30 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; +package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Entrepreneur; +import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.EntrepreneurRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import java.util.Optional; -@RestController -public class EntrepreneurController { +@Service +public class EntrepreneurService { - @Autowired EntrepreneurRepository entrepreneurRepository; + private final EntrepreneurRepository entrepreneurRepository; - @GetMapping("/Entrepreneur") - @ResponseBody - public Iterable allEntrepreneurs() { + EntrepreneurService(EntrepreneurRepository entrepreneurRepository) { + this.entrepreneurRepository = entrepreneurRepository; + } + + public Iterable getAllEntrepreneurs() { return this.entrepreneurRepository.findAll(); } - @GetMapping("/Entrepreneur/{id}") - public Entrepreneur getEntrepreneurById(@PathVariable Long id) { + public Entrepreneur getEntrepreneurById(Long id) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { throw new ResponseStatusException( @@ -31,14 +33,12 @@ public class EntrepreneurController { return entrepreneur.get(); } - @PostMapping("/Entrepreneur") - public Entrepreneur addEntrepreneur(@RequestBody Entrepreneur entrepreneur) { + public Entrepreneur addEntrepreneur(Entrepreneur entrepreneur) { return this.entrepreneurRepository.save(entrepreneur); } - @PostMapping("/Entrepreneur/{id}") public Entrepreneur updateEntrepreneur( - @PathVariable Long id, String school, String course, Boolean sneeStatus) { + Long id, String school, String course, Boolean sneeStatus) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { throw new ResponseStatusException( @@ -55,4 +55,8 @@ public class EntrepreneurController { } return this.entrepreneurRepository.save(entrepreneur.get()); } + + public Iterable GetEntrepreneurByProject(Project project) { + return this.entrepreneurRepository.getEntrepreneurByProjectParticipation(project); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java index 6c3f33f..ab2361d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java @@ -26,15 +26,14 @@ public class UserService { } // TODO - public long getIdUserByEmail(String email) { + public User getUserByEmail(String email) { Optional opt_user = this.userRepository.findByPrimaryMail(email); if (opt_user.isEmpty()) { System.err.println("Couldn't find user with email " + email); throw new ResponseStatusException(HttpStatus.NOT_FOUND); } - User user = opt_user.get(); - return user.getIdUser(); + return opt_user.get(); } public Iterable allUsers() { -- 2.47.2 From 5c3b2b138dc7407cc440474a42512df70820284d Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 15:55:33 +0100 Subject: [PATCH 54/97] feat: renamex title to sectionId and added a new shared API call --- .../myinpulse/controller/SharedApi.java | 16 ++--- .../enseirb/myinpulse/model/SectionCell.java | 37 +++++------ .../repository/SectionCellRepository.java | 6 +- .../service/EntrepreneurApiService.java | 4 +- .../myinpulse/service/SharedApiService.java | 33 +++++++--- .../service/database/SectionCellService.java | 11 +++- .../SectionCellController.java | 62 ------------------- 7 files changed, 61 insertions(+), 108 deletions(-) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index 883cc9f..3d17290 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -21,22 +21,18 @@ public class SharedApi { } /** - * TODO: It does not looks like a good id to have the title and the date in the url. What even - * TODO: is the title btw ? if this is the LC section, wouldn't it be better to use an ID ? - * TODO: choose return type, cf comment in LCSection - * - *

Endpoint used to get the data inside the lean canvas + * Endpoint used to get the data inside the lean canvas * * @return a list of lean canvas sections */ - @GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}") + @GetMapping("/shared/project/lcsection/{projectId}/{sectionId}/{date}") public Iterable getLCSection( - @PathVariable("projectId") String projectId, - @PathVariable("title") String title, + @PathVariable("projectId") Long projectId, + @PathVariable("sectionId") Long sectionId, @PathVariable("date") String date, @AuthenticationPrincipal Jwt principal) { - return sharedApiService.getLCSection( - projectId, title, date, principal.getClaimAsString("email")); + return sharedApiService.getSectionCells( + projectId, sectionId, date, principal.getClaimAsString("email")); } /** diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java index aec0a0e..9a03393 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -11,42 +11,39 @@ import java.util.List; @Table(name = "section_cell") public class SectionCell { + @ManyToMany(mappedBy = "listSectionCell") + private final List appointment = new ArrayList<>(); + + @OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) + private final List listAnnotation = new ArrayList<>(); + @Id @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idSectionCell; - @Column(length = 255) - private String title; - + @Column() private long sectionId; private String contentSectionCell; + /*@ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "idAdministrator") + private Administrator administratorSectionCell;*/ + // should now be useless private LocalDateTime modificationDate; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idProject") private Project projectSectionCell; - /*@ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "idAdministrator") - private Administrator administratorSectionCell;*/ - // should now be useless - - @ManyToMany(mappedBy = "listSectionCell") - private List appointment = new ArrayList<>(); - - @OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) - private List listAnnotation = new ArrayList<>(); - public SectionCell() {} public SectionCell( Long idSectionCell, - String title, + Long sectionId, String contentSectionCell, LocalDateTime modificationDate) { this.idSectionCell = idSectionCell; - this.title = title; + this.sectionId = sectionId; this.contentSectionCell = contentSectionCell; this.modificationDate = modificationDate; } @@ -59,12 +56,12 @@ public class SectionCell { this.idSectionCell = idSectionCell; } - public String getTitle() { - return title; + public Long getSectionId() { + return sectionId; } - public void setTitle(String title) { - this.title = title; + public void setSectionId(Long sectionId) { + this.sectionId = sectionId; } public String getContentSectionCell() { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java index 66ce004..674c549 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java @@ -1,9 +1,13 @@ package enseirb.myinpulse.repository; +import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface SectionCellRepository extends JpaRepository {} +public interface SectionCellRepository extends JpaRepository { + + Iterable findByProjectSectionCellAndSectionId(Project project, long sectionId); +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index d22a6a9..95f0b79 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -2,9 +2,9 @@ package enseirb.myinpulse.service; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; - import enseirb.myinpulse.service.database.ProjectService; import enseirb.myinpulse.service.database.SectionCellService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -31,7 +31,7 @@ public class EntrepreneurApiService { } sectionCellService.updateSectionCell( sectionCellId, - sectionCell.getTitle(), + sectionCell.getSectionId(), sectionCell.getContentSectionCell(), sectionCell.getModificationDate()); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index e104cdd..1fe9335 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -1,10 +1,7 @@ package enseirb.myinpulse.service; import enseirb.myinpulse.model.*; -import enseirb.myinpulse.service.database.AdministratorService; -import enseirb.myinpulse.service.database.EntrepreneurService; -import enseirb.myinpulse.service.database.ProjectService; -import enseirb.myinpulse.service.database.UserService; +import enseirb.myinpulse.service.database.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,17 +19,20 @@ public class SharedApiService { private final UserService userService; private final ProjectService projectService; private final EntrepreneurService entrepreneurService; + private final SectionCellService sectionCellService; @Autowired SharedApiService( AdministratorService administratorService, UserService userService, ProjectService projectService, - EntrepreneurService entrepreneurService) { + EntrepreneurService entrepreneurService, + SectionCellService sectionCellService) { this.administratorService = administratorService; this.userService = userService; this.projectService = projectService; this.entrepreneurService = entrepreneurService; + this.sectionCellService = sectionCellService; } // TODO: test @@ -58,13 +58,23 @@ public class SharedApiService { return entrepreneur.getProjectParticipation() == project; } - // TODO - public Iterable getLCSection( - String projectId, String title, String date, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + // TODO filter this with date + public Iterable getSectionCells( + long projectId, long sectionId, String date, String mail) { + + if (!isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to check section cells of the project {} but is not allowed to.", + mail, + projectId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + Project project = this.projectService.getProjectById(projectId); + return this.sectionCellService.getSectionCellsByProject(project, sectionId); } - // TODO: test, protect via email + // TODO: test public Iterable getEntrepreneursByProjectId(long projectId, String mail) { if (!isAllowedToCheckProject(mail, projectId)) { logger.warn( @@ -92,14 +102,17 @@ public class SharedApiService { return project.getAdministrator(); } + // TODO public Iterable getAppointmentsByProjectId(int projectId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } + // TODO public void getPDFReport(int appointmentId, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } + // TODO public void createAppointmentRequest(Appointment appointment, String mail) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java index c65f770..6f998ca 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java @@ -1,5 +1,6 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.repository.SectionCellRepository; @@ -43,14 +44,14 @@ public class SectionCellService { } public SectionCell updateSectionCell( - Long id, String title, String contentSectionCell, LocalDateTime modificationDate) { + Long id, Long sectionId, String contentSectionCell, LocalDateTime modificationDate) { Optional sectionCell = this.sectionCellRepository.findById(id); if (sectionCell.isEmpty()) { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } - if (title != null) { - sectionCell.get().setTitle(title); + if (sectionId != null) { + sectionCell.get().setSectionId(sectionId); } if (contentSectionCell != null) { sectionCell.get().setContentSectionCell(contentSectionCell); @@ -60,4 +61,8 @@ public class SectionCellService { } return this.sectionCellRepository.save(sectionCell.get()); } + + public Iterable getSectionCellsByProject(Project project, Long sectionId) { + return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java deleted file mode 100644 index 519fd90..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java +++ /dev/null @@ -1,62 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.SectionCell; -import enseirb.myinpulse.repository.SectionCellRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDateTime; -import java.util.Optional; - -@RestController -public class SectionCellController { - - @Autowired SectionCellRepository sectionCellRepository; - - @GetMapping("/SectionCell") - @ResponseBody - public Iterable allSectionCells() { - return this.sectionCellRepository.findAll(); - } - - @GetMapping("/SectionCell/{id}") - public SectionCell getSectionCellById(@PathVariable Long id) { - Optional sectionCell = this.sectionCellRepository.findById(id); - if (sectionCell.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); - } - return sectionCell.get(); - } - - @PostMapping("/SectionCell") - public SectionCell addSectionCell(@RequestBody SectionCell sectionCell) { - return this.sectionCellRepository.save(sectionCell); - } - - @PostMapping("/SectionCell/{id}") - public SectionCell updateSectionCell( - @PathVariable Long id, - String title, - String contentSectionCell, - LocalDateTime modificationDate) { - Optional sectionCell = this.sectionCellRepository.findById(id); - if (sectionCell.isEmpty()) { - throw new ResponseStatusException( - HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); - } - if (title != null) { - sectionCell.get().setTitle(title); - } - if (contentSectionCell != null) { - sectionCell.get().setContentSectionCell(contentSectionCell); - } - if (modificationDate != null) { - sectionCell.get().setModificationDate(modificationDate); - } - return this.sectionCellRepository.save(sectionCell.get()); - } -} -- 2.47.2 From e75a5c9d2cab6c4bcec65327b5f7c785c40ae852 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 15:57:03 +0100 Subject: [PATCH 55/97] fix: linter ??? pls idea be better --- .../enseirb/myinpulse/repository/AdministratorRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java index c9f3e50..34431fd 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java @@ -8,8 +8,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource public interface AdministratorRepository extends JpaRepository { - //public Administrator findByListProjectIsContaining(Project project); - /* @Query("SELECT a from Administrators a") Administrator findAllAdministrator(); */ -- 2.47.2 From f9de5ed6bfe5ee86cf0452d138a7873ab3c88a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 26 Feb 2025 17:35:52 +0100 Subject: [PATCH 56/97] feat: finished creating services from controllers, continued implementing entrepreneurServiceApi with some validation --- .../enseirb/myinpulse/model/SectionCell.java | 4 + .../repository/ReportRepository.java | 2 +- .../service/EntrepreneurApiService.java | 71 ++++++++- .../service/database/AnnotationService.java | 9 +- ...ontroller.java => AppointmentService.java} | 148 ++++++++++-------- .../service/database/EntrepreneurService.java | 7 +- .../service/database/ProjectService.java | 4 +- .../service/database/ReportService.java | 34 +++- .../service/database/SectionCellService.java | 12 ++ .../service/database/UserService.java | 10 +- .../ReportController.java | 43 ----- 11 files changed, 219 insertions(+), 125 deletions(-) rename MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/{old_controllers_to_convert_to_services/AppointmentController.java => AppointmentService.java} (64%) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java index 9a03393..71f5940 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -79,4 +79,8 @@ public class SectionCell { public void setModificationDate(LocalDateTime modificationDate) { this.modificationDate = modificationDate; } + + public Project getProjectSectionCell() { + return projectSectionCell; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java index e228003..cc70746 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java @@ -6,4 +6,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ReportRepository extends JpaRepository {} +public interface ReportRepository extends JpaRepository {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index 95f0b79..4e04f88 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -1,10 +1,16 @@ package enseirb.myinpulse.service; +import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; +import enseirb.myinpulse.model.User; +import enseirb.myinpulse.service.database.EntrepreneurService; import enseirb.myinpulse.service.database.ProjectService; import enseirb.myinpulse.service.database.SectionCellService; +import enseirb.myinpulse.service.database.UserService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -13,13 +19,31 @@ import org.springframework.web.server.ResponseStatusException; @Service public class EntrepreneurApiService { + protected static final Logger logger = LogManager.getLogger(); + private final SectionCellService sectionCellService; private final ProjectService projectService; + private final UserService userService; + private final EntrepreneurService entrepreneurService; @Autowired - EntrepreneurApiService(SectionCellService sectionCellService, ProjectService projectService) { + EntrepreneurApiService( + SectionCellService sectionCellService, + ProjectService projectService, + UserService userService, + EntrepreneurService entrepreneurService) { this.sectionCellService = sectionCellService; this.projectService = projectService; + this.userService = userService; + this.entrepreneurService = entrepreneurService; + } + + // Create utils file ? + Boolean isAllowedToCheckProject(String mail, long projectId) { + User user = this.userService.getUserByEmail(mail); + Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); + Project project = this.projectService.getProjectById(projectId); + return entrepreneur.getProjectParticipation() == project; } public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) { @@ -29,6 +53,20 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } + if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + logger.warn( + "User {} tried to edit section cells {} of the project {} but is not allowed to.", + mail, + sectionCellId, + this.sectionCellService.getProjectId(sectionCellId)); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} edited section cell {} of the project with id {}", + mail, + sectionCellId, + this.sectionCellService.getProjectId(sectionCellId)); sectionCellService.updateSectionCell( sectionCellId, sectionCell.getSectionId(), @@ -43,6 +81,20 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } + if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + logger.warn( + "User {} tried to remove section cells {} of the project {} but is not allowed to.", + mail, + sectionCellId, + this.sectionCellService.getSectionCellById(sectionCellId)); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} removed section cell {} of the project with id {}", + mail, + sectionCellId, + this.sectionCellService.getProjectId(sectionCellId)); sectionCellService.removeSectionCellById(sectionCellId); } @@ -52,14 +104,29 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide"); } + if (!isAllowedToCheckProject( + mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) { + logger.warn( + "User {} tried to add a section cell to the project {} but is not allowed to.", + mail, + this.sectionCellService.getProjectId(sectionCell.getIdSectionCell())); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} added a new section cell {} to the project with id {}", + mail, + sectionCell.getIdSectionCell(), + this.sectionCellService.getProjectId(sectionCell.getIdSectionCell())); sectionCellService.addNewSectionCell(sectionCell); } public void requestNewProject(Project project, String mail) { if (project == null) { - System.err.println("Trying to request the creation of a null project"); + logger.error("Trying to request the creation of a null project"); throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide"); } + logger.info("User {} created a new project with id {}", mail, project.getIdProject()); project.setProjectStatus("PENDING"); projectService.addNewProject(project); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java index 225ef06..577cf9b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java @@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Annotation; import enseirb.myinpulse.repository.AnnotationRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -13,6 +15,8 @@ import java.util.Optional; @Service public class AnnotationService { + protected static final Logger logger = LogManager.getLogger(); + private final AnnotationRepository annotationRepository; @Autowired @@ -27,6 +31,7 @@ public class AnnotationService { public Annotation getAnnotationById(Long id) { Optional annotation = annotationRepository.findById(id); if (annotation.isEmpty()) { + logger.error("getAnnotationById : No annotation found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette annotation n'existe pas"); } @@ -44,7 +49,9 @@ public class AnnotationService { public Annotation updateAnnotation(Long id, String comment) { Optional annotation = annotationRepository.findById(id); if (annotation.isEmpty()) { - return null; + logger.error("updateAnnotation : No annotation found with id {}", id); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette annotation n'existe pas"); } if (comment != null) { annotation.get().setComment(comment); diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java similarity index 64% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java index 3761d51..7ba0ff5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java @@ -1,69 +1,79 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Appointment; -import enseirb.myinpulse.repository.AppointmentRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.Optional; - -@RestController -public class AppointmentController { - - @Autowired AppointmentRepository appointmentRepository; - - @GetMapping("/Appointment") - @ResponseBody - public Iterable allAppointments() { - return this.appointmentRepository.findAll(); - } - - @GetMapping("/Appointment/{id}") - public Appointment getAppointmentById(@PathVariable Long id) { - Optional appointment = this.appointmentRepository.findById(id); - if (appointment.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - return appointment.get(); - } - - @PostMapping("/Appointment") - public Appointment addAppointment(@RequestBody Appointment appointment) { - return this.appointmentRepository.save(appointment); - } - - @PostMapping("/Appointment/{id}") - public Appointment updateAppointment( - @PathVariable Long id, - LocalDate appointmentDate, - LocalTime appointmentTime, - LocalTime appointmentDuration, - String appointmentPlace, - String appointmentSubject) { - Optional appointment = this.appointmentRepository.findById(id); - if (appointment.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - if (appointmentDate != null) { - appointment.get().setAppointmentDate(appointmentDate); - } - if (appointmentTime != null) { - appointment.get().setAppointmentTime(appointmentTime); - } - if (appointmentDuration != null) { - appointment.get().setAppointmentDuration(appointmentDuration); - } - if (appointmentPlace != null) { - appointment.get().setAppointmentPlace(appointmentPlace); - } - if (appointmentSubject != null) { - appointment.get().setAppointmentSubject(appointmentSubject); - } - return this.appointmentRepository.save(appointment.get()); - } -} +package enseirb.myinpulse.service.database; + +import enseirb.myinpulse.model.Appointment; +import enseirb.myinpulse.repository.AppointmentRepository; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Optional; + +@Service +public class AppointmentService { + + private static final Logger logger = LogManager.getLogger(AppointmentService.class); + + private AppointmentRepository appointmentRepository; + + @Autowired + AppointmentService(AppointmentRepository appointmentRepository) { + this.appointmentRepository = appointmentRepository; + } + + public Iterable getallAppointments() { + return this.appointmentRepository.findAll(); + } + + public Appointment getAppointmentById(Long id) { + Optional appointment = this.appointmentRepository.findById(id); + if (appointment.isEmpty()) { + logger.error("getAppointmentById : No appointment found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + return appointment.get(); + } + + public Appointment addNewAppointment(Appointment appointment) { + return this.appointmentRepository.save(appointment); + } + + public void deleteAppointmentById(Long id) { + this.appointmentRepository.deleteById(id); + } + + public Appointment updateAppointment( + Long id, + LocalDate appointmentDate, + LocalTime appointmentTime, + LocalTime appointmentDuration, + String appointmentPlace, + String appointmentSubject) { + Optional appointment = this.appointmentRepository.findById(id); + if (appointment.isEmpty()) { + logger.error("updateAppointment : No appointment found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + if (appointmentDate != null) { + appointment.get().setAppointmentDate(appointmentDate); + } + if (appointmentTime != null) { + appointment.get().setAppointmentTime(appointmentTime); + } + if (appointmentDuration != null) { + appointment.get().setAppointmentDuration(appointmentDuration); + } + if (appointmentPlace != null) { + appointment.get().setAppointmentPlace(appointmentPlace); + } + if (appointmentSubject != null) { + appointment.get().setAppointmentSubject(appointmentSubject); + } + return this.appointmentRepository.save(appointment.get()); + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java index 6e85920..f24878f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java @@ -4,9 +4,10 @@ import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.EntrepreneurRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import java.util.Optional; @@ -14,6 +15,8 @@ import java.util.Optional; @Service public class EntrepreneurService { + protected static final Logger logger = LogManager.getLogger(); + private final EntrepreneurRepository entrepreneurRepository; EntrepreneurService(EntrepreneurRepository entrepreneurRepository) { @@ -27,6 +30,7 @@ public class EntrepreneurService { public Entrepreneur getEntrepreneurById(Long id) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { + logger.error("getEntrepreneurById : No entrepreneur found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } @@ -41,6 +45,7 @@ public class EntrepreneurService { Long id, String school, String course, Boolean sneeStatus) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { + logger.error("updateEntrepreneur : No entrepreneur found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index d073b26..10dc7e9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -34,7 +34,7 @@ public class ProjectService { public Project getProjectById(Long id) { Optional project = this.projectRepository.findById(id); if (project.isEmpty()) { - System.err.println("Project with id " + id + " not found"); + logger.error("No project found with id {}", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); } return project.get(); @@ -77,7 +77,7 @@ public class ProjectService { if (projectStatus != null) { if (!validateStatus(projectStatus)) { - System.err.println("updateProjectStatus: Invalid status " + projectStatus); + logger.error("updateProjectStatus: Invalid status {}", projectStatus); throw new ResponseStatusException( HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java index e9d8d27..2a8d273 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java @@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Report; import enseirb.myinpulse.repository.ReportRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -12,6 +14,9 @@ import java.util.Optional; @Service public class ReportService { + + protected static final Logger logger = LogManager.getLogger(); + private final ReportRepository reportRepository; @Autowired @@ -19,16 +24,37 @@ public class ReportService { this.reportRepository = reportRepository; } - Report getReportById(int id) { - Optional report = reportRepository.findById(id); + public Iterable getAllReports() { + return this.reportRepository.findAll(); + } + + public Report getReportById(Long id) { + Optional report = this.reportRepository.findById(id); if (report.isEmpty()) { + logger.error("getReportById : No report found with id {}", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); } return report.get(); } // TODO: do some validation - void saveReport(Report report) { - reportRepository.save(report); + public Report addNewReport(Report report) { + return this.reportRepository.save(report); + } + + public void deleteReportById(Long id) { + this.reportRepository.deleteById(id); + } + + public Report updateReport(Long id, String reportContent) { + Optional report = this.reportRepository.findById(id); + if (report.isEmpty()) { + logger.error("updateReport : No report found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + if (reportContent != null) { + report.get().setReportContent(reportContent); + } + return this.reportRepository.save(report.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java index 6f998ca..f51f4d5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java @@ -4,6 +4,8 @@ import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.repository.SectionCellRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -15,6 +17,8 @@ import java.util.Optional; @Service public class SectionCellService { + protected static final Logger logger = LogManager.getLogger(); + private final SectionCellRepository sectionCellRepository; @Autowired @@ -29,6 +33,7 @@ public class SectionCellService { public SectionCell getSectionCellById(Long id) { Optional sectionCell = this.sectionCellRepository.findById(id); if (sectionCell.isEmpty()) { + logger.error("getSectionCellById : No sectionCell found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } @@ -47,6 +52,7 @@ public class SectionCellService { Long id, Long sectionId, String contentSectionCell, LocalDateTime modificationDate) { Optional sectionCell = this.sectionCellRepository.findById(id); if (sectionCell.isEmpty()) { + logger.error("updateSectionCell : No sectionCell found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } @@ -65,4 +71,10 @@ public class SectionCellService { public Iterable getSectionCellsByProject(Project project, Long sectionId) { return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId); } + + public Long getProjectId(Long sectionCellId) { + SectionCell sectionCell = getSectionCellById(sectionCellId); + Project sectionProject = sectionCell.getProjectSectionCell(); + return sectionProject.getIdProject(); + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java index ab2361d..cf24fa3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java @@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.User; import enseirb.myinpulse.repository.UserRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -14,6 +16,9 @@ import java.util.Optional; @Service public class UserService { + + protected static final Logger logger = LogManager.getLogger(); + private final UserRepository userRepository; @Autowired @@ -30,8 +35,8 @@ public class UserService { Optional opt_user = this.userRepository.findByPrimaryMail(email); if (opt_user.isEmpty()) { - System.err.println("Couldn't find user with email " + email); - throw new ResponseStatusException(HttpStatus.NOT_FOUND); + logger.error("getUserByEmail : No user found with email {}", email); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); } return opt_user.get(); } @@ -53,6 +58,7 @@ public class UserService { String phoneNumber) { Optional user = userRepository.findById(id); if (user.isEmpty()) { + logger.error("updateUser : No user found with id {}", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); } if (userName != null) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java deleted file mode 100644 index 7b3458b..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java +++ /dev/null @@ -1,43 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import org.springframework.web.bind.annotation.*; - -@RestController -public class ReportController { - /* - private final ReportRepository reportRepository; - - @Autowired - public ReportController(ReportRepository reportRepository) { - this.reportRepository = reportRepository; - } - - @GetMapping("/Report") - @ResponseBody - public Iterable allReports() { - System.out.println("\n\n"); - System.out.println(ReportRepository); - System.out.println("\n\n"); - return this.reportRepository.findAll(); - } - - - @PostMapping("/Report") - public Report addReport(@RequestBody Report report) { - return this.reportRepository.save(report); - } - - @PostMapping("/Report/{id}") - public Report updateProject(@PathVariable Long id, String reportContent) { - Optional report = this.reportRepository.findById(id); - if (report.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - if (reportContent != null) { - report.get().setReportContent(reportContent); - } - return this.reportRepository.save(report.get()); - } - - */ -} -- 2.47.2 From 1d970ce5f58fd449ed76308c0db802b9d5383ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 26 Feb 2025 18:33:09 +0100 Subject: [PATCH 57/97] feat: continued to implement SharedApiService (if linter fails i don't understand) --- .../enseirb/myinpulse/model/Appointment.java | 12 +++- .../java/enseirb/myinpulse/model/Report.java | 6 +- .../enseirb/myinpulse/model/SectionCell.java | 4 ++ .../myinpulse/service/SharedApiService.java | 60 +++++++++++++++++-- .../service/database/SectionCellService.java | 7 +++ 5 files changed, 82 insertions(+), 7 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index 91cf332..67c0fd9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -17,8 +17,8 @@ public class Appointment { new ArrayList<>(); */ // should now be useless - @OneToMany(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) - private final List listReport = new ArrayList<>(); + @OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) + private Report report; @ManyToMany( fetch = FetchType.LAZY, @@ -109,4 +109,12 @@ public class Appointment { public void setAppointmentSubject(String appointmentSubject) { this.appointmentSubject = appointmentSubject; } + + public List getAppointmentListSectionCell() { + return listSectionCell; + } + + public Report getAppointmentReport() { + return report; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java index 410cd7c..5ff5e82 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java @@ -17,7 +17,7 @@ public class Report { private String reportContent; - @ManyToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idAppointment") private Appointment appointmentReport; @@ -28,6 +28,10 @@ public class Report { this.reportContent = reportContent; } + public Long getIdReport() { + return idReport; + } + public String getReportContent() { return reportContent; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java index 71f5940..d77faf6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -83,4 +83,8 @@ public class SectionCell { public Project getProjectSectionCell() { return projectSectionCell; } + + public List getAppointmentSectionCell() { + return appointment; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index 1fe9335..e5983e0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -10,6 +10,9 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; +import java.util.ArrayList; +import java.util.List; + @Service public class SharedApiService { @@ -20,6 +23,7 @@ public class SharedApiService { private final ProjectService projectService; private final EntrepreneurService entrepreneurService; private final SectionCellService sectionCellService; + private final AppointmentService appointmentService; @Autowired SharedApiService( @@ -27,12 +31,14 @@ public class SharedApiService { UserService userService, ProjectService projectService, EntrepreneurService entrepreneurService, - SectionCellService sectionCellService) { + SectionCellService sectionCellService, + AppointmentService appointmentService) { this.administratorService = administratorService; this.userService = userService; this.projectService = projectService; this.entrepreneurService = entrepreneurService; this.sectionCellService = sectionCellService; + this.appointmentService = appointmentService; } // TODO: test @@ -103,12 +109,58 @@ public class SharedApiService { } // TODO - public Iterable getAppointmentsByProjectId(int projectId, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + public Iterable getAppointmentsByProjectId(long projectId, String mail) { + if (!isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to check the appointments related to the project {} but is not allowed to.", + mail, + projectId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} tried to check the appointments related to the project {}", + mail, + projectId); + Iterable sectionCells = + this.sectionCellService.getSectionCellsByProject( + projectService.getProjectById(projectId), + 2L); // sectionId useless in this function ? + List appointments = new ArrayList(); + sectionCells.forEach( + sectionCell -> { + appointments.addAll( + this.sectionCellService.getAppointmentsBySectionCellId( + sectionCell.getIdSectionCell())); + }); + return appointments; } // TODO - public void getPDFReport(int appointmentId, String mail) { + public void getPDFReport(long appointmentId, String mail) { + long projectId = + this.appointmentService + .getAppointmentById(appointmentId) + .getAppointmentListSectionCell() + .getFirst() + .getProjectSectionCell() + .getIdProject(); + if (!isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to generate the PDF report {} related to the appointment {} but is not allowed to.", + mail, + this.appointmentService + .getAppointmentById(appointmentId) + .getAppointmentReport() + .getIdReport(), + appointmentId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + /* return this.appointmentService + .getAppointmentById(appointmentId) + .getAppointmentReport().getReportContent(); */ + // generate pdf from this string, and format it to be decent looking throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java index f51f4d5..5a70bee 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java @@ -1,5 +1,6 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.Appointment; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.repository.SectionCellRepository; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; @Service @@ -77,4 +79,9 @@ public class SectionCellService { Project sectionProject = sectionCell.getProjectSectionCell(); return sectionProject.getIdProject(); } + + public List getAppointmentsBySectionCellId(Long sectionCellId) { + SectionCell sectionCell = getSectionCellById(sectionCellId); + return sectionCell.getAppointmentSectionCell(); + } } -- 2.47.2 From b5c03798fcf9bdb1f59b0007c33262c9d1cc4f8d Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 26 Feb 2025 18:55:45 +0100 Subject: [PATCH 58/97] fix: formatter now follow the same logic as idea, see https://github.com/google/google-java-format/issues/566 --- .gitea/workflows/back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/back.yaml b/.gitea/workflows/back.yaml index 31aa219..bde3a22 100644 --- a/.gitea/workflows/back.yaml +++ b/.gitea/workflows/back.yaml @@ -15,4 +15,4 @@ jobs: - uses: axel-op/googlejavaformat-action@v3 with: - args: "--set-exit-if-changed --skip-sorting-imports --aosp -n" \ No newline at end of file + args: "--set-exit-if-changed --skip-sorting-imports --skip-reflowing-long-strings --aosp -n" -- 2.47.2 From 80b2d087e484f023e4be1c47c466cf0709e909ff Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 11:45:55 +0100 Subject: [PATCH 59/97] feat: implemented date filtration and a utils service to prevent code ducplication --- .../myinpulse/model/DelAppointment.java | 8 --- .../enseirb/myinpulse/model/DelProject.java | 7 --- .../enseirb/myinpulse/model/DelReport.java | 6 -- .../enseirb/myinpulse/model/LCSection.java | 7 --- .../repository/SectionCellRepository.java | 5 ++ .../service/EntrepreneurApiService.java | 27 +++----- .../myinpulse/service/SharedApiService.java | 56 ++++++----------- .../myinpulse/service/UtilsService.java | 62 +++++++++++++++++++ .../service/database/SectionCellService.java | 6 ++ 9 files changed, 99 insertions(+), 85 deletions(-) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java deleted file mode 100644 index f29a2eb..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelAppointment.java +++ /dev/null @@ -1,8 +0,0 @@ -package enseirb.myinpulse.model; - -public class DelAppointment { - int validated; - int[] akserId; - int[] destId; - String date; // TODO: date type ? -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java deleted file mode 100644 index 25a21f9..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelProject.java +++ /dev/null @@ -1,7 +0,0 @@ -package enseirb.myinpulse.model; - -public class DelProject { - int projectId; - String projectName; - String projectDescription; -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java deleted file mode 100644 index bbdbae8..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/DelReport.java +++ /dev/null @@ -1,6 +0,0 @@ -package enseirb.myinpulse.model; - -public class DelReport { - int projectId; - String reportContent; -} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java deleted file mode 100644 index 4fd6ec4..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/LCSection.java +++ /dev/null @@ -1,7 +0,0 @@ -package enseirb.myinpulse.model; - -// TODO: is this redundant with the Section class from the database ? -// TODO: In the one hand it represent the same data, and on the other it should be much lighter. -// TODO: btw why does a LC section have an administrator ? - -public class LCSection {} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java index 674c549..4ad5b51 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java @@ -6,8 +6,13 @@ import enseirb.myinpulse.model.SectionCell; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import java.time.LocalDateTime; + @RepositoryRestResource public interface SectionCellRepository extends JpaRepository { Iterable findByProjectSectionCellAndSectionId(Project project, long sectionId); + + Iterable findByProjectSectionCellAndSectionIdAndModificationDateBefore( + Project project, long sectionId, LocalDateTime date); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index 4e04f88..1bab1a1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -1,13 +1,9 @@ package enseirb.myinpulse.service; -import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; -import enseirb.myinpulse.model.User; -import enseirb.myinpulse.service.database.EntrepreneurService; import enseirb.myinpulse.service.database.ProjectService; import enseirb.myinpulse.service.database.SectionCellService; -import enseirb.myinpulse.service.database.UserService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -23,28 +19,19 @@ public class EntrepreneurApiService { private final SectionCellService sectionCellService; private final ProjectService projectService; - private final UserService userService; - private final EntrepreneurService entrepreneurService; + private final UtilsService utilsService; @Autowired EntrepreneurApiService( SectionCellService sectionCellService, ProjectService projectService, - UserService userService, - EntrepreneurService entrepreneurService) { + UtilsService utilsService) { this.sectionCellService = sectionCellService; this.projectService = projectService; - this.userService = userService; - this.entrepreneurService = entrepreneurService; + this.utilsService = utilsService; } - // Create utils file ? - Boolean isAllowedToCheckProject(String mail, long projectId) { - User user = this.userService.getUserByEmail(mail); - Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); - Project project = this.projectService.getProjectById(projectId); - return entrepreneur.getProjectParticipation() == project; - } + public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) { SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId); @@ -53,7 +40,7 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } - if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + if (!utilsService.isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { logger.warn( "User {} tried to edit section cells {} of the project {} but is not allowed to.", mail, @@ -81,7 +68,7 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } - if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + if (!utilsService.isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { logger.warn( "User {} tried to remove section cells {} of the project {} but is not allowed to.", mail, @@ -104,7 +91,7 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide"); } - if (!isAllowedToCheckProject( + if (!utilsService.isAllowedToCheckProject( mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) { logger.warn( "User {} tried to add a section cell to the project {} but is not allowed to.", diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index e5983e0..98cd05b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -10,6 +10,8 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -18,57 +20,32 @@ public class SharedApiService { protected static final Logger logger = LogManager.getLogger(); - private final AdministratorService administratorService; - private final UserService userService; private final ProjectService projectService; private final EntrepreneurService entrepreneurService; private final SectionCellService sectionCellService; private final AppointmentService appointmentService; + private final UtilsService utilsService; + @Autowired SharedApiService( - AdministratorService administratorService, - UserService userService, ProjectService projectService, EntrepreneurService entrepreneurService, SectionCellService sectionCellService, - AppointmentService appointmentService) { - this.administratorService = administratorService; - this.userService = userService; + AppointmentService appointmentService, + UtilsService utilsService) { this.projectService = projectService; this.entrepreneurService = entrepreneurService; this.sectionCellService = sectionCellService; this.appointmentService = appointmentService; - } - - // TODO: test - Boolean isAnAdmin(String mail) { - try { - long userId = this.userService.getUserByEmail(mail).getIdUser(); - Administrator a = this.administratorService.getAdministratorById(userId); - return true; - } catch (ResponseStatusException e) { - logger.info(e); - return false; - } - } - - // TODO: test - Boolean isAllowedToCheckProject(String mail, long projectId) { - if (isAnAdmin(mail)) { - return true; - } - User user = this.userService.getUserByEmail(mail); - Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); - Project project = this.projectService.getProjectById(projectId); - return entrepreneur.getProjectParticipation() == project; + this.utilsService = utilsService; } // TODO filter this with date public Iterable getSectionCells( long projectId, long sectionId, String date, String mail) { - if (!isAllowedToCheckProject(mail, projectId)) { + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { logger.warn( "User {} tried to check section cells of the project {} but is not allowed to.", mail, @@ -76,13 +53,18 @@ public class SharedApiService { throw new ResponseStatusException( HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); } + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime dateTime = LocalDateTime.parse(date, formatter); + Project project = this.projectService.getProjectById(projectId); - return this.sectionCellService.getSectionCellsByProject(project, sectionId); + return this.sectionCellService.getSectionCellsByProjectAndSectionIdBeforeDate( + project, sectionId, dateTime); } // TODO: test public Iterable getEntrepreneursByProjectId(long projectId, String mail) { - if (!isAllowedToCheckProject(mail, projectId)) { + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { logger.warn( "User {} tried to check the member of the project {} but is not allowed to.", mail, @@ -94,9 +76,9 @@ public class SharedApiService { return this.entrepreneurService.GetEntrepreneurByProject(project); } - // TODO: test, protect via email + // TODO: test public Administrator getAdminByProjectId(long projectId, String mail) { - if (!isAllowedToCheckProject(mail, projectId)) { + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { logger.warn( "User {} tried to check the admin of the project {} but is not allowed to.", mail, @@ -110,7 +92,7 @@ public class SharedApiService { // TODO public Iterable getAppointmentsByProjectId(long projectId, String mail) { - if (!isAllowedToCheckProject(mail, projectId)) { + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { logger.warn( "User {} tried to check the appointments related to the project {} but is not allowed to.", mail, @@ -145,7 +127,7 @@ public class SharedApiService { .getFirst() .getProjectSectionCell() .getIdProject(); - if (!isAllowedToCheckProject(mail, projectId)) { + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { logger.warn( "User {} tried to generate the PDF report {} related to the appointment {} but is not allowed to.", mail, diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java new file mode 100644 index 0000000..a49e82e --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java @@ -0,0 +1,62 @@ +package enseirb.myinpulse.service; + +import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.model.Entrepreneur; +import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.User; +import enseirb.myinpulse.service.database.AdministratorService; +import enseirb.myinpulse.service.database.EntrepreneurService; +import enseirb.myinpulse.service.database.ProjectService; +import enseirb.myinpulse.service.database.UserService; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +@Service +public class UtilsService { + + protected static final Logger logger = LogManager.getLogger(); + + private final UserService userService; + private final ProjectService projectService; + private final EntrepreneurService entrepreneurService; + private final AdministratorService administratorService; + + @Autowired + UtilsService( + ProjectService projectService, + UserService userService, + EntrepreneurService entrepreneurService, + AdministratorService administratorService) { + this.userService = userService; + this.projectService = projectService; + this.entrepreneurService = entrepreneurService; + this.administratorService = administratorService; + } + + // TODO: test? + public Boolean isAllowedToCheckProject(String mail, long projectId) { + if (isAnAdmin(mail)) { + return true; + } + User user = this.userService.getUserByEmail(mail); + Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); + Project project = this.projectService.getProjectById(projectId); + return entrepreneur.getProjectParticipation() == project; + } + + // TODO: test + Boolean isAnAdmin(String mail) { + try { + long userId = this.userService.getUserByEmail(mail).getIdUser(); + Administrator a = this.administratorService.getAdministratorById(userId); + return true; + } catch (ResponseStatusException e) { + logger.info(e); + return false; + } + } +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java index 5a70bee..59c7397 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java @@ -84,4 +84,10 @@ public class SectionCellService { SectionCell sectionCell = getSectionCellById(sectionCellId); return sectionCell.getAppointmentSectionCell(); } + + public Iterable getSectionCellsByProjectAndSectionIdBeforeDate( + Project project, long sectionId, LocalDateTime date) { + return sectionCellRepository.findByProjectSectionCellAndSectionIdAndModificationDateBefore( + project, sectionId, date); + } } -- 2.47.2 From 4880f3829cd88516dbbb498eee717e6e30fe35c4 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 11:47:45 +0100 Subject: [PATCH 60/97] I don't get it, how does it keeps failing with the formatter installed... time to create pre-commit hook I guess --- .../enseirb/myinpulse/service/EntrepreneurApiService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index 1bab1a1..61b16ab 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -31,8 +31,6 @@ public class EntrepreneurApiService { this.utilsService = utilsService; } - - public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) { SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId); if (editSectionCell == null) { @@ -40,7 +38,8 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } - if (!utilsService.isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + if (!utilsService.isAllowedToCheckProject( + mail, this.sectionCellService.getProjectId(sectionCellId))) { logger.warn( "User {} tried to edit section cells {} of the project {} but is not allowed to.", mail, @@ -68,7 +67,8 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } - if (!utilsService.isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + if (!utilsService.isAllowedToCheckProject( + mail, this.sectionCellService.getProjectId(sectionCellId))) { logger.warn( "User {} tried to remove section cells {} of the project {} but is not allowed to.", mail, -- 2.47.2 From 628c61fb8be5d0ed584fe769bf10d4fe3d8a9724 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 11:55:43 +0100 Subject: [PATCH 61/97] feat: pipeline should now test if the project builds --- .gitea/workflows/build-back.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .gitea/workflows/build-back.yaml diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml new file mode 100644 index 0000000..91d4a6e --- /dev/null +++ b/.gitea/workflows/build-back.yaml @@ -0,0 +1,20 @@ +name: Build + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Build with Gradle + run: ./gradlew build -- 2.47.2 From f3eaf8fe3469cb3c6370b27992f47d3095e8ff04 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 12:04:11 +0100 Subject: [PATCH 62/97] fix: action create the gradlew wrapper --- .gitea/workflows/build-back.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index 91d4a6e..d1972a8 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -14,7 +14,13 @@ jobs: with: distribution: 'temurin' java-version: 21 + - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 + + - name: Init gradle wrapper + run: gradle wrapper + + - name: Build with Gradle run: ./gradlew build -- 2.47.2 From dc843299eb0c1f20b199371e5c0b1b0f08ce67fb Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 12:10:13 +0100 Subject: [PATCH 63/97] fix: action create the gradlew wrapper --- .gitea/workflows/build-back.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index d1972a8..93958d0 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -18,9 +18,6 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - name: Init gradle wrapper - run: gradle wrapper - - name: Build with Gradle - run: ./gradlew build + run: ./MyINPulse-back/gradlew build -- 2.47.2 From d4dcc95d9be4704f5de4e89f74bd0d41405dd5b8 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 12:16:43 +0100 Subject: [PATCH 64/97] fix: removed cache to speed up things --- .gitea/workflows/build-back.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index 93958d0..3be18a8 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -17,7 +17,8 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - + with: + cache-disabled: true - - name: Build with Gradle - run: ./MyINPulse-back/gradlew build + - name: init gradle + run: ./MyINPulse-back/gradlew init -- 2.47.2 From 236bb0d1670fb9c580dc9877e862fea5740aa3a5 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 12:18:36 +0100 Subject: [PATCH 65/97] fix: improved the workflow --- .gitea/workflows/build-back.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index 3be18a8..0e95b6f 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -21,4 +21,5 @@ jobs: cache-disabled: true - name: init gradle + working-directory: ./MyINPulse-back/ run: ./MyINPulse-back/gradlew init -- 2.47.2 From 8894fea6d4500775ed836cd5957c2f50d43c8b45 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 12:20:05 +0100 Subject: [PATCH 66/97] fix: improved the workflow --- .gitea/workflows/build-back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index 0e95b6f..ce84de2 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -22,4 +22,4 @@ jobs: - name: init gradle working-directory: ./MyINPulse-back/ - run: ./MyINPulse-back/gradlew init + run: ./gradlew init -- 2.47.2 From e6a8d98d632d9e978b9a88873ffd155eeb98dbd3 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Fri, 28 Feb 2025 12:20:48 +0100 Subject: [PATCH 67/97] fix: improved the workflow --- .gitea/workflows/build-back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index ce84de2..63a1e8f 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -22,4 +22,4 @@ jobs: - name: init gradle working-directory: ./MyINPulse-back/ - run: ./gradlew init + run: ./gradlew build -- 2.47.2 From 3ca97cf3783e5fb2a69a078f838ba71d7bcfbd74 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sat, 1 Mar 2025 00:57:34 +0100 Subject: [PATCH 68/97] fix: improved the workflow --- .gitea/workflows/build-back.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index 63a1e8f..bac6cc0 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -22,4 +22,4 @@ jobs: - name: init gradle working-directory: ./MyINPulse-back/ - run: ./gradlew build + run: ./gradlew build -x test -- 2.47.2 From d78e43f7e04e1b7a07bc672b615f9e8050a0fecf Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sat, 1 Mar 2025 00:58:50 +0100 Subject: [PATCH 69/97] fix: improved the workflow --- .gitea/workflows/build-back.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index bac6cc0..eef9d86 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -17,9 +17,9 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - with: - cache-disabled: true + #with: + # cache-disabled: true - name: init gradle working-directory: ./MyINPulse-back/ - run: ./gradlew build -x test + run: ./gradlew build -x test # todo: run test, currently fail because no database is present -- 2.47.2 From 861e7495a702ce88b9a907d9cb1f81517721e10b Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sat, 1 Mar 2025 01:00:52 +0100 Subject: [PATCH 70/97] fix: re-enabled cache to drastically reduce action time. This should be fixed later --- .gitea/workflows/build-back.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index eef9d86..60dd4fa 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -17,8 +17,8 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - #with: - # cache-disabled: true + with: + cache-disabled: true - name: init gradle working-directory: ./MyINPulse-back/ -- 2.47.2 From 8153496a0f06d22203f736971382f338b8722701 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 4 Mar 2025 18:42:14 +0100 Subject: [PATCH 71/97] feat: implemented database for testing purposes --- MyINPulse-back/src/main/resources/delete.sql | 2 +- .../src/test/resources/application.properties | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 MyINPulse-back/src/test/resources/application.properties diff --git a/MyINPulse-back/src/main/resources/delete.sql b/MyINPulse-back/src/main/resources/delete.sql index 866a291..701b1f3 100644 --- a/MyINPulse-back/src/main/resources/delete.sql +++ b/MyINPulse-back/src/main/resources/delete.sql @@ -1,2 +1,2 @@ -DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE; +DROP TABLE IF EXISTS administrateurs, projets, utilisateurs, entrepreneurs, sections, rendez_vous, comptes_rendus, concerner CASCADE; DROP TABLE IF EXISTS administrator, project, user_inpulse, entrepreneur, section_cell, appointment, make_appointment, report, annotation, concern CASCADE; \ No newline at end of file diff --git a/MyINPulse-back/src/test/resources/application.properties b/MyINPulse-back/src/test/resources/application.properties new file mode 100644 index 0000000..bebfacd --- /dev/null +++ b/MyINPulse-back/src/test/resources/application.properties @@ -0,0 +1,11 @@ +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +spring.datasource.username=sa +spring.datasource.password=sa +spring.sql.init.mode=never +spring.application.name=myinpulse-test +spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs +spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test +logging.level.org.springframework.security=DEBUG +spring.jpa.hibernate.ddl-auto=update +logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n -- 2.47.2 From 3de7ebe2b10bc9117db5055b876892a3a5f8f691 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 20:21:32 +0100 Subject: [PATCH 72/97] fix: remoed debug logging --- MyINPulse-back/src/main/resources/application.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/MyINPulse-back/src/main/resources/application.properties b/MyINPulse-back/src/main/resources/application.properties index a6e039e..043c22b 100644 --- a/MyINPulse-back/src/main/resources/application.properties +++ b/MyINPulse-back/src/main/resources/application.properties @@ -1,7 +1,6 @@ spring.application.name=myinpulse spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test -logging.level.org.springframework.security=DEBUG spring.datasource.url=jdbc:postgresql://${DATABASE_URL}/${BACKEND_DB} spring.datasource.username=${BACKEND_USER} spring.datasource.password=${BACKEND_PASSWORD} -- 2.47.2 From dded62c25a6c72889ccdb4432e1dc096d6befe7c Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 20:22:20 +0100 Subject: [PATCH 73/97] fix: take latest implementation of logging module + imported inmemory database for testing --- MyINPulse-back/build.gradle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MyINPulse-back/build.gradle b/MyINPulse-back/build.gradle index 367d3ec..6cd0111 100644 --- a/MyINPulse-back/build.gradle +++ b/MyINPulse-back/build.gradle @@ -23,10 +23,13 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-data-rest' - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.16.0' - implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.16.0' + implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+' + implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+' implementation 'org.postgresql:postgresql' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'com.h2database:h2' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } -- 2.47.2 From 215d80ad70948cd66fa43103c03a4a684684b67b Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 21:04:52 +0100 Subject: [PATCH 74/97] fix: removed contradictive @NotNull preventing to add data to database. --- .../main/java/enseirb/myinpulse/model/Administrator.java | 7 +++---- .../src/main/java/enseirb/myinpulse/model/Annotation.java | 2 -- .../main/java/enseirb/myinpulse/model/Appointment.java | 8 ++------ .../java/enseirb/myinpulse/model/MakeAppointment.java | 2 -- .../src/main/java/enseirb/myinpulse/model/Project.java | 2 -- .../src/main/java/enseirb/myinpulse/model/Report.java | 2 -- .../main/java/enseirb/myinpulse/model/SectionCell.java | 2 -- .../src/main/java/enseirb/myinpulse/model/User.java | 2 -- 8 files changed, 5 insertions(+), 22 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java index d90e3aa..fcb4cdb 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java @@ -13,14 +13,14 @@ import java.util.List; public class Administrator extends User { @OneToMany(mappedBy = "projectAdministrator", fetch = FetchType.LAZY, orphanRemoval = true) - private List listProject = new ArrayList<>(); + private final List listProject = new ArrayList<>(); /*@OneToMany(mappedBy = "administratorSectionCell", fetch = FetchType.LAZY, orphanRemoval = true) private List listSectionCell = new ArrayList<>();*/ // should now be useless @OneToMany(mappedBy = "administratorAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) - private List listAnnotation = new ArrayList<>(); + private final List listAnnotation = new ArrayList<>(); /*@OneToMany(mappedBy = "administratorAppointment", fetch = FetchType.LAZY, orphanRemoval = true) private final List listAppointment = new ArrayList<>();*/ @@ -32,12 +32,11 @@ public class Administrator extends User { public Administrator() {} public Administrator( - Long idUser, String userSurname, String username, String mainMail, String secondaryMail, String phoneNumber) { - super(idUser, userSurname, username, mainMail, secondaryMail, phoneNumber); + super(null, userSurname, username, mainMail, secondaryMail, phoneNumber); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java index fa73e0d..a7ba0d8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java @@ -1,14 +1,12 @@ package enseirb.myinpulse.model; import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; @Entity @Table(name = "annotation") public class Annotation { @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idAnnotation; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index 67c0fd9..1540e39 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -1,7 +1,6 @@ package enseirb.myinpulse.model; import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; import java.time.LocalDate; import java.time.LocalTime; @@ -17,9 +16,6 @@ public class Appointment { new ArrayList<>(); */ // should now be useless - @OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) - private Report report; - @ManyToMany( fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @@ -28,9 +24,9 @@ public class Appointment { joinColumns = @JoinColumn(name = "idAppointment"), inverseJoinColumns = @JoinColumn(name = "idSectionCell")) List listSectionCell = new ArrayList<>(); - + @OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) + private Report report; @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idAppointment; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java index 91c97d5..aae4f18 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/MakeAppointment.java @@ -1,14 +1,12 @@ package enseirb.myinpulse.model; import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; @Entity @Table(name = "make_appointment") public class MakeAppointment { @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idMakeAppointment; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index 070efc6..38392c0 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -1,7 +1,6 @@ package enseirb.myinpulse.model; import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; import java.time.LocalDate; import java.util.ArrayList; @@ -18,7 +17,6 @@ public class Project { private final List listSectionCell = new ArrayList<>(); @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idProject; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java index 5ff5e82..055b134 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java @@ -4,14 +4,12 @@ import jakarta.persistence.*; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; -import jakarta.validation.constraints.NotNull; @Entity @Table(name = "report") public class Report { @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idReport; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java index d77faf6..0fb8c89 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -1,7 +1,6 @@ package enseirb.myinpulse.model; import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.ArrayList; @@ -18,7 +17,6 @@ public class SectionCell { private final List listAnnotation = new ArrayList<>(); @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idSectionCell; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java index c23b285..8dbe4e8 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java @@ -1,7 +1,6 @@ package enseirb.myinpulse.model; import jakarta.persistence.*; -import jakarta.validation.constraints.NotNull; @Entity @Table(name = "user_inpulse") @@ -9,7 +8,6 @@ import jakarta.validation.constraints.NotNull; public class User { @Id - @NotNull @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idUser; -- 2.47.2 From 1106cf84781a9124bb93de504a14317a6639d2c7 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 21:06:31 +0100 Subject: [PATCH 75/97] feat: added tests. --- .../myinpulse/AdminApiServiceTest.java | 51 +++++++++++++++++++ .../myinpulse/MyinpulseApplicationTests.java | 2 + 2 files changed, 53 insertions(+) create mode 100644 MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java new file mode 100644 index 0000000..32068bb --- /dev/null +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java @@ -0,0 +1,51 @@ +package enseirb.myinpulse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.service.AdminApiService; +import enseirb.myinpulse.service.database.AdministratorService; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; + +import java.util.ArrayList; +import java.util.List; + +@SpringBootTest +@Transactional +public class AdminApiServiceTest { + @Autowired private AdminApiService adminApiService; + + @BeforeAll + static void setup(@Autowired AdministratorService administratorService) { + administratorService.addAdministrator( + new Administrator( + "admin", "admin", "testAdmin@example.com", "testAdmin@example.com", "")); + } + + @Test + void getProjectOfAdminIsEmpty() throws Exception { + Iterable projects = adminApiService.getProjectsOfAdmin("testAdmin@example.com"); + List l = new ArrayList<>(); + projects.forEach(l::add); + assertEquals(0, l.size()); + } + + @Test + void getProjectOfInexistantAdminFails() throws Exception { + String nonExistentAdminEmail = "testInexistantAdmin@example.com"; + + assertThrows( + ResponseStatusException.class, + () -> { + adminApiService.getProjectsOfAdmin(nonExistentAdminEmail); + }); + } +} diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java index 04669ca..c97449e 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/MyinpulseApplicationTests.java @@ -1,5 +1,6 @@ package enseirb.myinpulse; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -7,5 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest; class MyinpulseApplicationTests { @Test + @DisplayName("contextLoad => Test if the context can load, i.e. the application can start") void contextLoads() {} } -- 2.47.2 From 04589392cb83a139b7b3593e0cf7ce19d1d29c2d Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 21:07:29 +0100 Subject: [PATCH 76/97] fix: removed debug logging --- MyINPulse-back/src/test/resources/application.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MyINPulse-back/src/test/resources/application.properties b/MyINPulse-back/src/test/resources/application.properties index bebfacd..a27c24b 100644 --- a/MyINPulse-back/src/test/resources/application.properties +++ b/MyINPulse-back/src/test/resources/application.properties @@ -6,6 +6,5 @@ spring.sql.init.mode=never spring.application.name=myinpulse-test spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:7080/realms/test/protocol/openid-connect/certs spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:7080/realms/test -logging.level.org.springframework.security=DEBUG spring.jpa.hibernate.ddl-auto=update -logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n +logging.pattern.console=%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n \ No newline at end of file -- 2.47.2 From c5e7736a16dff9c386da236355bc07ff2e62877c Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 21:10:25 +0100 Subject: [PATCH 77/97] fix: wtf does idea do ?? Why d methods move ? fixed linter again... --- .../src/main/java/enseirb/myinpulse/model/Appointment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index 1540e39..2d501a4 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -24,8 +24,10 @@ public class Appointment { joinColumns = @JoinColumn(name = "idAppointment"), inverseJoinColumns = @JoinColumn(name = "idSectionCell")) List listSectionCell = new ArrayList<>(); + @OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) private Report report; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long idAppointment; -- 2.47.2 From 5f8fe4a374b585b3c5bc2998d5ba8e02bea4ae3e Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 21:19:00 +0100 Subject: [PATCH 78/97] feat: precommit hook for google java format --- hooks/README.md | 2 ++ hooks/google-java-format | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 hooks/README.md create mode 100755 hooks/google-java-format diff --git a/hooks/README.md b/hooks/README.md new file mode 100644 index 0000000..c9eae1c --- /dev/null +++ b/hooks/README.md @@ -0,0 +1,2 @@ +# Useful hooks in this project +To use, just add the content of the wanted hook in `.git/hook/pre-commit`. You may need to use `chmod +x pre-commit` diff --git a/hooks/google-java-format b/hooks/google-java-format new file mode 100755 index 0000000..5155e6c --- /dev/null +++ b/hooks/google-java-format @@ -0,0 +1,24 @@ +#!/bin/bash + +# Path to the Google Java Formatter JAR +FORMATTER_JAR="$HOME/.local/share/java/google-java-format.jar" + +# Download the Google Java Formatter JAR if it doesn't exist +if [ ! -f "$FORMATTER_JAR" ]; then + echo "Downloading Google Java Formatter..." + mkdir -p "$(dirname "$FORMATTER_JAR")" + curl -L -o "$FORMATTER_JAR" https://github.com/google/google-java-format/releases/download/v1.20.0/google-java-format-1.20.0-all-deps.jar +fi + +# Format all staged Java files +STAGED_JAVA_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "\.java$") + +if [ -n "$STAGED_JAVA_FILES" ]; then + echo "Formatting Java files..." + java -jar "$FORMATTER_JAR" --skip-sorting-imports --skip-reflowing-long-strings --aosp --replace $STAGED_JAVA_FILES + + # Re-stage the formatted files + git add $STAGED_JAVA_FILES +fi + +exit 0 -- 2.47.2 From e3393c8834c7a24267b8d4835efce8227f7922b3 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Sun, 9 Mar 2025 21:20:20 +0100 Subject: [PATCH 79/97] test -- 2.47.2 From a2e2395cc235994f7e044edcb15858f8170c9069 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Mar 2025 13:00:38 +0100 Subject: [PATCH 80/97] feat: added new tests and coverage report --- MyINPulse-back/build.gradle | 20 +++++++++ .../myinpulse/AdminApiServiceTest.java | 45 ++++++++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/MyINPulse-back/build.gradle b/MyINPulse-back/build.gradle index 6cd0111..e9d19ad 100644 --- a/MyINPulse-back/build.gradle +++ b/MyINPulse-back/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.4.2' id 'io.spring.dependency-management' version '1.1.7' + id 'jacoco' } group = 'enseirb' @@ -36,3 +37,22 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + + +test { + finalizedBy jacocoTestReport // report is always generated after tests run +} +jacocoTestReport { + dependsOn test // tests are required to run before generating the report + reports { + xml.required = false + csv.required = false + html.outputLocation = layout.buildDirectory.dir('jacocoHtml') + } +} + + +jacoco { + toolVersion = "0.8.12" + reportsDirectory = layout.buildDirectory.dir('customJacocoReportDir') +} diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java index 32068bb..47f8af4 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java @@ -7,6 +7,7 @@ import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.service.AdminApiService; import enseirb.myinpulse.service.database.AdministratorService; +import enseirb.myinpulse.service.database.ProjectService; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -15,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.server.ResponseStatusException; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -24,22 +26,44 @@ public class AdminApiServiceTest { @Autowired private AdminApiService adminApiService; @BeforeAll - static void setup(@Autowired AdministratorService administratorService) { + static void setup( + @Autowired AdministratorService administratorService, + @Autowired ProjectService projectService) { administratorService.addAdministrator( new Administrator( - "admin", "admin", "testAdmin@example.com", "testAdmin@example.com", "")); + "admin", + "admin", + "testAdminEmpty@example.com", + "testAdmin@example.com", + "")); + administratorService.addAdministrator( + new Administrator( + "admin2", + "admin2", + "testAdminFull@example.com", + "testAdmin@example.com", + "")); + projectService.addNewProject( + new Project( + "sampleProjectAdminApiService", + null, + LocalDate.now(), + "ONGOING", + administratorService.getAdministratorByPrimaryMain( + "testAdminFull@example.com"))); } @Test - void getProjectOfAdminIsEmpty() throws Exception { - Iterable projects = adminApiService.getProjectsOfAdmin("testAdmin@example.com"); + void getProjectOfAdminIsEmpty() { + Iterable projects = + adminApiService.getProjectsOfAdmin("testAdminEmpty@example.com"); List l = new ArrayList<>(); projects.forEach(l::add); assertEquals(0, l.size()); } @Test - void getProjectOfInexistantAdminFails() throws Exception { + void getProjectOfInexistantAdminFails() { String nonExistentAdminEmail = "testInexistantAdmin@example.com"; assertThrows( @@ -48,4 +72,15 @@ public class AdminApiServiceTest { adminApiService.getProjectsOfAdmin(nonExistentAdminEmail); }); } + + @Test + void getProjectOfAdminNotEmpty() { + Iterable projects = + adminApiService.getProjectsOfAdmin("testAdminFull@example.com"); + List l = new ArrayList<>(); + projects.forEach(l::add); + assertEquals(1, l.size()); + Project p = l.getFirst(); + assertEquals(p.getProjectName(), "sampleProjectAdminApiService"); + } } -- 2.47.2 From 467babab79cd6e94f112c07b27ddeebd0846b6f7 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Mar 2025 13:01:28 +0100 Subject: [PATCH 81/97] fix: removed id + renamed mainEmail to primaryEmail everywhere --- .../main/java/enseirb/myinpulse/model/Administrator.java | 4 ++-- .../src/main/java/enseirb/myinpulse/model/Entrepreneur.java | 4 ++-- .../src/main/java/enseirb/myinpulse/model/Project.java | 6 +++--- .../src/main/java/enseirb/myinpulse/model/User.java | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java index fcb4cdb..3b1ee7a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java @@ -34,9 +34,9 @@ public class Administrator extends User { public Administrator( String userSurname, String username, - String mainMail, + String primaryMail, String secondaryMail, String phoneNumber) { - super(null, userSurname, username, mainMail, secondaryMail, phoneNumber); + super(null, userSurname, username, primaryMail, secondaryMail, phoneNumber); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java index d85c99d..7eb64d5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java @@ -40,13 +40,13 @@ public class Entrepreneur extends User { Long idUser, String userSurname, String username, - String mainMail, + String primaryMail, String secondaryMail, String phoneNumber, String school, String course, boolean sneeStatus) { - super(idUser, userSurname, username, mainMail, secondaryMail, phoneNumber); + super(idUser, userSurname, username, primaryMail, secondaryMail, phoneNumber); this.school = school; this.course = course; this.sneeStatus = sneeStatus; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index 38392c0..ac1c5df 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -39,16 +39,16 @@ public class Project { public Project() {} public Project( - Long idProject, String projectName, byte[] logo, LocalDate creationDate, - String projectStatus) { - this.idProject = idProject; + String projectStatus, + Administrator projectAdministrator) { this.projectName = projectName; this.logo = logo; this.creationDate = creationDate; this.projectStatus = projectStatus; + this.projectAdministrator = projectAdministrator; } public Long getIdProject() { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java index 8dbe4e8..4d7f32f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java @@ -71,8 +71,8 @@ public class User { return primaryMail; } - public void setPrimaryMail(String mainMail) { - this.primaryMail = mainMail; + public void setPrimaryMail(String primaryMail) { + this.primaryMail = primaryMail; } public String getSecondaryMail() { -- 2.47.2 From 5608b12f847db92724773851b15cdd13f1fd352d Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Mar 2025 13:01:53 +0100 Subject: [PATCH 82/97] fix: removed id + renamed mainEmail to primaryEmail everywhere --- .../enseirb/myinpulse/repository/AdministratorRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java index 34431fd..bcf05c7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/AdministratorRepository.java @@ -5,10 +5,13 @@ import enseirb.myinpulse.model.Administrator; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import java.util.Optional; + @RepositoryRestResource public interface AdministratorRepository extends JpaRepository { /* @Query("SELECT a from Administrators a") Administrator findAllAdministrator(); */ + Optional findByPrimaryMail(String PrimaryMail); } -- 2.47.2 From ef964c4d35963c3843bbcf350af8565aad089af3 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Tue, 11 Mar 2025 13:02:17 +0100 Subject: [PATCH 83/97] fix: removed id + renamed mainEmail to primaryEmail everywhere --- .../service/database/AdministratorService.java | 11 +++++++++++ .../myinpulse/service/database/UserService.java | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java index 0f595a0..b3d91bc 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java @@ -37,6 +37,17 @@ public class AdministratorService { return administrator.get(); } + public Administrator getAdministratorByPrimaryMain(String primaryMail) { + Optional administrator = + this.administratorRepository.findByPrimaryMail(primaryMail); + if (administrator.isEmpty()) { + logger.error("No administrator found with the mail {}", primaryMail); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + return administrator.get(); + } + public Administrator addAdministrator(Administrator administrator) { return this.administratorRepository.save(administrator); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java index cf24fa3..45a4eac 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java @@ -53,7 +53,7 @@ public class UserService { @PathVariable Long id, String userSurname, String userName, - String mainMail, + String primaryMail, String secondaryMail, String phoneNumber) { Optional user = userRepository.findById(id); @@ -67,8 +67,8 @@ public class UserService { if (userSurname != null) { user.get().setUserSurname(userSurname); } - if (mainMail != null) { - user.get().setPrimaryMail(mainMail); + if (primaryMail != null) { + user.get().setPrimaryMail(primaryMail); } if (secondaryMail != null) { user.get().setSecondaryMail(secondaryMail); -- 2.47.2 From e011a5534e111050c6354bc9e63565d76d6d251b Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Mar 2025 10:21:08 +0100 Subject: [PATCH 84/97] feat: switched from String to ProjectDecisionValues --- .../java/enseirb/myinpulse/model/Project.java | 10 +++++----- .../myinpulse/model/ProjectDecisionValue.java | 8 ++++++++ .../repository/ProjectRepository.java | 2 +- .../myinpulse/service/AdminApiService.java | 20 +++++++++++-------- .../service/EntrepreneurApiService.java | 4 +++- .../service/database/ProjectService.java | 10 ++++++++-- 6 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index ac1c5df..b745c6f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -26,8 +26,7 @@ public class Project { private byte[] logo; private LocalDate creationDate; - @Column(length = 255) - private String projectStatus; + @Column private ProjectDecisionValue projectStatus; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "idAdministrator") @@ -42,11 +41,12 @@ public class Project { String projectName, byte[] logo, LocalDate creationDate, - String projectStatus, + ProjectDecisionValue projectStatus, Administrator projectAdministrator) { this.projectName = projectName; this.logo = logo; this.creationDate = creationDate; + // this.projectStatus = (long) projectStatus.ordinal(); this.projectStatus = projectStatus; this.projectAdministrator = projectAdministrator; } @@ -83,11 +83,11 @@ public class Project { this.creationDate = creationDate; } - public String getProjectStatus() { + public ProjectDecisionValue getProjectStatus() { return projectStatus; } - public void setProjectStatus(String projectStatus) { + public void setProjectStatus(ProjectDecisionValue projectStatus) { this.projectStatus = projectStatus; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java new file mode 100644 index 0000000..ca38489 --- /dev/null +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java @@ -0,0 +1,8 @@ +package enseirb.myinpulse.model; + +public enum ProjectDecisionValue { + PENDING, + ACTIVE, + ENDED, + ABORTED +} diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java index 2911655..0fc1b08 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java @@ -10,5 +10,5 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; public interface ProjectRepository extends JpaRepository { Iterable findByProjectAdministrator(Administrator administrator); - Iterable findByProjectStatus(String status); + Iterable findByProjectStatus(Long status); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 400c2b6..974754d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -1,5 +1,7 @@ package enseirb.myinpulse.service; +import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE; + import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.database.AdministratorService; import enseirb.myinpulse.service.database.ProjectService; @@ -27,7 +29,7 @@ public class AdminApiService { this.administratorService = administratorService; } - // TODO: test + // TODO: check if test are sufficient public Iterable getProjectsOfAdmin(String email) { return projectService.getProjectsByAdminId( administratorService.getAdministratorById( @@ -46,13 +48,15 @@ public class AdminApiService { // TODO: test public void validateProject(ProjectDecision decision) { - projectService.updateProject( - decision.projectId, - null, - null, - null, - "ACTIVE", - this.administratorService.getAdministratorById(decision.projectId)); + if (decision.isAccepted == 1) { + projectService.updateProject( + decision.projectId, + null, + null, + null, + ACTIVE, + this.administratorService.getAdministratorById(decision.projectId)); + } } // TODO: solve todo + test diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index 61b16ab..f1d6260 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -1,5 +1,7 @@ package enseirb.myinpulse.service; +import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING; + import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.service.database.ProjectService; @@ -114,7 +116,7 @@ public class EntrepreneurApiService { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide"); } logger.info("User {} created a new project with id {}", mail, project.getIdProject()); - project.setProjectStatus("PENDING"); + project.setProjectStatus(PENDING); projectService.addNewProject(project); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index 10dc7e9..d851a43 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -1,7 +1,10 @@ package enseirb.myinpulse.service.database; +import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING; + import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.ProjectDecisionValue; import enseirb.myinpulse.repository.ProjectRepository; import org.apache.logging.log4j.LogManager; @@ -54,7 +57,7 @@ public class ProjectService { String projectName, byte[] logo, LocalDate creationDate, - String projectStatus, + ProjectDecisionValue projectStatus, Administrator administrator) { Optional project = this.projectRepository.findById(id); @@ -76,11 +79,14 @@ public class ProjectService { } if (projectStatus != null) { + // TODO: check if this is really useful + /* if (!validateStatus(projectStatus)) { logger.error("updateProjectStatus: Invalid status {}", projectStatus); throw new ResponseStatusException( HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté"); } + */ project.get().setProjectStatus(projectStatus); } @@ -96,7 +102,7 @@ public class ProjectService { } public Iterable getPendingProjects() { - return this.projectRepository.findByProjectStatus("PENDING"); + return this.projectRepository.findByProjectStatus((long) PENDING.ordinal()); } public void deleteProjectById(Long id) { -- 2.47.2 From 419ceec1bc93326236cd34a802878cd8a431ee15 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Mar 2025 10:25:19 +0100 Subject: [PATCH 85/97] feat: switched from String to ProjectDecisionValues --- .../java/enseirb/myinpulse/repository/ProjectRepository.java | 3 ++- .../main/java/enseirb/myinpulse/service/AdminApiService.java | 4 +++- .../enseirb/myinpulse/service/database/ProjectService.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java index 0fc1b08..8f452f6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java @@ -2,6 +2,7 @@ package enseirb.myinpulse.repository; import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.ProjectDecisionValue; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @@ -10,5 +11,5 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; public interface ProjectRepository extends JpaRepository { Iterable findByProjectAdministrator(Administrator administrator); - Iterable findByProjectStatus(Long status); + Iterable findByProjectStatus(ProjectDecisionValue status); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 974754d..d268d98 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -61,7 +61,9 @@ public class AdminApiService { // TODO: solve todo + test public void addNewProject(Project project) { - projectService.addNewProject(project); // TODO: how can the front know the ID ? + projectService.addNewProject( + project); // TODO: how can the front know the ID ? => it does not, thus needing to + // have null in the project id field } // TODO diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index d851a43..5c32ae2 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -102,7 +102,7 @@ public class ProjectService { } public Iterable getPendingProjects() { - return this.projectRepository.findByProjectStatus((long) PENDING.ordinal()); + return this.projectRepository.findByProjectStatus(PENDING); } public void deleteProjectById(Long id) { -- 2.47.2 From 64da3c9ab00b4dfcaaf4eaf347a887804aed292c Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Mar 2025 12:07:48 +0100 Subject: [PATCH 86/97] feat: tests on AdminApiService --- .../myinpulse/AdminApiServiceTest.java | 117 +++++++++++++++--- 1 file changed, 102 insertions(+), 15 deletions(-) diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java index 47f8af4..abd21fb 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java @@ -1,10 +1,12 @@ package enseirb.myinpulse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static enseirb.myinpulse.model.ProjectDecisionValue.*; + +import static org.junit.jupiter.api.Assertions.*; import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.Project; +import enseirb.myinpulse.model.ProjectDecision; import enseirb.myinpulse.service.AdminApiService; import enseirb.myinpulse.service.database.AdministratorService; import enseirb.myinpulse.service.database.ProjectService; @@ -23,7 +25,9 @@ import java.util.List; @SpringBootTest @Transactional public class AdminApiServiceTest { + private static long administratorid; @Autowired private AdminApiService adminApiService; + @Autowired private ProjectService projectService; @BeforeAll static void setup( @@ -36,30 +40,36 @@ public class AdminApiServiceTest { "testAdminEmpty@example.com", "testAdmin@example.com", "")); - administratorService.addAdministrator( - new Administrator( - "admin2", - "admin2", - "testAdminFull@example.com", - "testAdmin@example.com", - "")); + Administrator a = + administratorService.addAdministrator( + new Administrator( + "admin2", + "admin2", + "testAdminFull@example.com", + "testAdmin@example.com", + "")); + administratorid = a.getIdUser(); projectService.addNewProject( new Project( "sampleProjectAdminApiService", null, LocalDate.now(), - "ONGOING", + ACTIVE, administratorService.getAdministratorByPrimaryMain( "testAdminFull@example.com"))); } + private List IterableToList(Iterable iterable) { + List l = new ArrayList<>(); + iterable.forEach(l::add); + return l; + } + @Test void getProjectOfAdminIsEmpty() { Iterable projects = adminApiService.getProjectsOfAdmin("testAdminEmpty@example.com"); - List l = new ArrayList<>(); - projects.forEach(l::add); - assertEquals(0, l.size()); + assertEquals(0, IterableToList(projects).size()); } @Test @@ -77,10 +87,87 @@ public class AdminApiServiceTest { void getProjectOfAdminNotEmpty() { Iterable projects = adminApiService.getProjectsOfAdmin("testAdminFull@example.com"); - List l = new ArrayList<>(); - projects.forEach(l::add); + List l = IterableToList(projects); assertEquals(1, l.size()); Project p = l.getFirst(); assertEquals(p.getProjectName(), "sampleProjectAdminApiService"); } + + @Test + void getPendingProjectsEmpty() { + assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size()); + } + + @Test + void getPendingProjectsNotEmpty() { + this.projectService.addNewProject( + new Project( + "PendingProjectAdminApiService1", null, LocalDate.now(), PENDING, null)); + this.projectService.addNewProject( + new Project( + "PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null)); + Iterable pendingProjects = this.adminApiService.getPendingProjects(); + List pendingProjectsList = IterableToList(pendingProjects); + assertEquals(2, pendingProjectsList.size()); + assertTrue( + List.of("PendingProjectAdminApiService1", "PendingProjectAdminApiService2") + .contains(pendingProjectsList.getFirst().getProjectName())); + assertTrue( + List.of("PendingProjectAdminApiService1", "PendingProjectAdminApiService2") + .contains(pendingProjectsList.getLast().getProjectName())); + } + + @Test + void validateInexistantProject() { + ProjectDecision d = new ProjectDecision(-1, 0, 1); + assertThrows(ResponseStatusException.class, () -> this.adminApiService.validateProject(d)); + } + + @Test + void validateExistantProject() { + Project p = + new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null); + this.projectService.addNewProject(p); + assertEquals(PENDING, p.getProjectStatus()); + ProjectDecision d = new ProjectDecision(p.getIdProject(), administratorid, 1); + this.adminApiService.validateProject(d); + assertEquals(ACTIVE, p.getProjectStatus()); + + // Check if the project was really updated in the database + assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size()); + } + + @Test + void refuseExistantProject() { + Project p = + new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null); + this.projectService.addNewProject(p); + assertEquals(PENDING, p.getProjectStatus()); + ProjectDecision d = new ProjectDecision(p.getIdProject(), administratorid, 0); + this.adminApiService.validateProject(d); + assertEquals(REJECTED, p.getProjectStatus()); + + // Check if the project was really updated in the database + assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size()); + } + + @Test + void addProject() { + assertEquals(0, IterableToList(this.adminApiService.getPendingProjects()).size()); + Project p1 = + new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null); + this.adminApiService.addNewProject(p1); + + assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size()); + } + + @Test + void addDuplicateProject() { + Project p1 = + new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null); + Project p2 = + new Project("PendingProjectAdminApiService2", null, LocalDate.now(), PENDING, null); + this.adminApiService.addNewProject(p1); + assertThrows(ResponseStatusException.class, () -> this.adminApiService.addNewProject(p2)); + } } -- 2.47.2 From 653f9236937769c93e6ba96ca0330ced98ab5651 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 12 Mar 2025 12:08:49 +0100 Subject: [PATCH 87/97] fix: bugfix --- .../myinpulse/model/ProjectDecision.java | 18 +++++++++ .../myinpulse/model/ProjectDecisionValue.java | 3 +- .../repository/ProjectRepository.java | 4 ++ .../myinpulse/service/AdminApiService.java | 39 +++++++++++-------- .../service/database/ProjectService.java | 13 +++++++ 5 files changed, 60 insertions(+), 17 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java index a2d3575..22eec2d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecision.java @@ -4,4 +4,22 @@ public class ProjectDecision { public long projectId; public long adminId; public long isAccepted; + + public ProjectDecision(long projectId, long adminId, long isAccepted) { + this.projectId = projectId; + this.adminId = adminId; + this.isAccepted = isAccepted; + } + + @Override + public String toString() { + return "ProjectDecision{" + + "projectId=" + + projectId + + ", adminId=" + + adminId + + ", isAccepted=" + + isAccepted + + '}'; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java index ca38489..a47c5f9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/ProjectDecisionValue.java @@ -4,5 +4,6 @@ public enum ProjectDecisionValue { PENDING, ACTIVE, ENDED, - ABORTED + ABORTED, + REJECTED, } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java index 8f452f6..7cf5214 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ProjectRepository.java @@ -7,9 +7,13 @@ import enseirb.myinpulse.model.ProjectDecisionValue; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; +import java.util.Optional; + @RepositoryRestResource public interface ProjectRepository extends JpaRepository { Iterable findByProjectAdministrator(Administrator administrator); Iterable findByProjectStatus(ProjectDecisionValue status); + + Optional findByProjectName(String projectName); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index d268d98..17059b9 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.service; import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE; +import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED; import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.database.AdministratorService; @@ -29,7 +30,7 @@ public class AdminApiService { this.administratorService = administratorService; } - // TODO: check if test are sufficient + // TODO: check if tests are sufficients - peer verification required public Iterable getProjectsOfAdmin(String email) { return projectService.getProjectsByAdminId( administratorService.getAdministratorById( @@ -41,29 +42,35 @@ public class AdminApiService { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); } - // TODO: test + // TODO: check if tests are sufficient - peer verification required public Iterable getPendingProjects() { return this.projectService.getPendingProjects(); } - // TODO: test + // TODO: check if tests are sufficient - peer verification required public void validateProject(ProjectDecision decision) { - if (decision.isAccepted == 1) { - projectService.updateProject( - decision.projectId, - null, - null, - null, - ACTIVE, - this.administratorService.getAdministratorById(decision.projectId)); - } + projectService.updateProject( + decision.projectId, + null, + null, + null, + (decision.isAccepted == 1) ? ACTIVE : REJECTED, + this.administratorService.getAdministratorById(decision.adminId)); } - // TODO: solve todo + test + // TODO: check if tests are sufficient - peer verification required public void addNewProject(Project project) { - projectService.addNewProject( - project); // TODO: how can the front know the ID ? => it does not, thus needing to - // have null in the project id field + project.setIdProject(null); + // We remove it from the request to be sure that it will be auto generated + try { + this.projectService.getProjectByName(project.getProjectName(), true); + throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists"); + } catch (ResponseStatusException e) { + if (e.getStatusCode() == HttpStatus.CONFLICT) { + throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists"); + } + projectService.addNewProject(project); + } } // TODO diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index 5c32ae2..32fc4c4 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -108,4 +108,17 @@ public class ProjectService { public void deleteProjectById(Long id) { this.projectRepository.deleteById(id); } + + public Project getProjectByName(String name, boolean noerror) { + Optional project = this.projectRepository.findByProjectName(name); + if (project.isEmpty()) { + if (noerror) logger.error("No project found with name {}", name); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); + } + return project.get(); + } + + public Project getProjectByName(String name) { + return getProjectByName(name, false); + } } -- 2.47.2 From 8d486dce897b3d959203597ab0ac9199347d9d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 12 Mar 2025 12:16:01 +0100 Subject: [PATCH 88/97] feat: continued implementing adminApiService --- MyINPulse-back/build.gradle | 1 + .../myinpulse/controller/AdminApi.java | 2 +- .../myinpulse/controller/SharedApi.java | 10 ++- .../enseirb/myinpulse/model/Appointment.java | 4 + .../java/enseirb/myinpulse/model/Report.java | 8 ++ .../myinpulse/service/AdminApiService.java | 50 +++++++++-- .../myinpulse/service/SharedApiService.java | 89 +++++++++++++++++-- documentation/Doc.txt | 12 +++ 8 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 documentation/Doc.txt diff --git a/MyINPulse-back/build.gradle b/MyINPulse-back/build.gradle index e9d19ad..47b0dc2 100644 --- a/MyINPulse-back/build.gradle +++ b/MyINPulse-back/build.gradle @@ -27,6 +27,7 @@ dependencies { implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+' implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+' implementation 'org.postgresql:postgresql' + implementation group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13.3' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'com.h2database:h2' diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java index b5f3866..d3f432a 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/AdminApi.java @@ -81,7 +81,7 @@ public class AdminApi { */ @PostMapping("/admin/appoitements/report/{appointmentId}") public void createAppointmentReport( - @PathVariable String appointmentId, + @PathVariable long appointmentId, @RequestBody Report report, @AuthenticationPrincipal Jwt principal) { adminApiService.createAppointmentReport( diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index 3d17290..e35818c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -1,5 +1,6 @@ package enseirb.myinpulse.controller; +import com.itextpdf.text.DocumentException; import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.SharedApiService; @@ -9,6 +10,9 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.*; +import java.io.File; +import java.io.FileNotFoundException; + @SpringBootApplication @RestController public class SharedApi { @@ -78,7 +82,11 @@ public class SharedApi { @GetMapping("/shared/projects/appointments/report/{appointmentId}") public void getPDFReport( @PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) { - sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); + try { + sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); + } catch (FileNotFoundException | DocumentException e) { + System.out.println(e); + } } /** diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index 2d501a4..352ab17 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -115,4 +115,8 @@ public class Appointment { public Report getAppointmentReport() { return report; } + + public void setAppointmentReport(Report report) { + this.report = report; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java index 055b134..40e3337 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Report.java @@ -37,4 +37,12 @@ public class Report { public void setReportContent(String reportContent) { this.reportContent = reportContent; } + + public Appointment getAppointmentReport() { + return appointmentReport; + } + + public void setAppointmentReport(Appointment appointmentReport) { + this.appointmentReport = appointmentReport; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 400c2b6..a9cb44f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -4,6 +4,12 @@ import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.database.AdministratorService; import enseirb.myinpulse.service.database.ProjectService; import enseirb.myinpulse.service.database.UserService; +import enseirb.myinpulse.service.database.AppointmentService; +import enseirb.myinpulse.service.database.ReportService; +import enseirb.myinpulse.service.UtilsService; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -13,30 +19,41 @@ import org.springframework.web.server.ResponseStatusException; @Service public class AdminApiService { + protected static final Logger logger = LogManager.getLogger(); + private final ProjectService projectService; private final UserService userService; private final AdministratorService administratorService; + private final UtilsService utilsService; + private final AppointmentService appointmentService; + private final ReportService reportService; @Autowired AdminApiService( ProjectService projectService, UserService userService, - AdministratorService administratorService) { + AdministratorService administratorService, + UtilsService utilsService, + AppointmentService appointmentService, + ReportService reportService) { this.projectService = projectService; this.userService = userService; this.administratorService = administratorService; + this.utilsService = utilsService; + this.appointmentService = appointmentService; + this.reportService = reportService; } // TODO: test - public Iterable getProjectsOfAdmin(String email) { + public Iterable getProjectsOfAdmin(String mail) { return projectService.getProjectsByAdminId( administratorService.getAdministratorById( - this.userService.getUserByEmail(email).getIdUser())); + this.userService.getUserByEmail(mail).getIdUser())); } // TODO - public Iterable getUpcomingAppointments(String email) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + public Iterable getUpcomingAppointments(String mail) { + logger.info("User {} check their upcoming appointments", mail); } // TODO: test @@ -60,9 +77,26 @@ public class AdminApiService { projectService.addNewProject(project); // TODO: how can the front know the ID ? } - // TODO - public void createAppointmentReport(String appointmentId, Report report, String email) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + public void createAppointmentReport(long appointmentId, Report report, String mail) { + long projectId = + this.appointmentService + .getAppointmentById(appointmentId) + .getAppointmentListSectionCell() + .getFirst() + .getProjectSectionCell() + .getIdProject(); + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to add an report for appointment {} but is not allowed to.", + mail, + projectId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info("User {} added a report for appointment {}", mail, projectId); + Report addedReport = this.reportService.addNewReport(report); + addedReport.setAppointmentReport(this.appointmentService.getAppointmentById(appointmentId)); + this.appointmentService.getAppointmentById(appointmentId).setAppointmentReport(addedReport); } // TODO: test diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index 98cd05b..869b278 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -10,6 +10,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; +import com.itextpdf.text.*; +import com.itextpdf.text.pdf.PdfWriter; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -118,8 +123,9 @@ public class SharedApiService { return appointments; } - // TODO - public void getPDFReport(long appointmentId, String mail) { + // + public void getPDFReport(long appointmentId, String mail) + throws FileNotFoundException, DocumentException { long projectId = this.appointmentService .getAppointmentById(appointmentId) @@ -139,15 +145,82 @@ public class SharedApiService { throw new ResponseStatusException( HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); } - /* return this.appointmentService - .getAppointmentById(appointmentId) - .getAppointmentReport().getReportContent(); */ - // generate pdf from this string, and format it to be decent looking - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + logger.info( + "User {} generated the PDF report related to appointment {}", mail, appointmentId); + + String reportContent = + this.appointmentService + .getAppointmentById(appointmentId) + .getAppointmentReport() + .getReportContent(); + + // PDF generation + Document document = new Document(); + PdfWriter.getInstance(document, new FileOutputStream("Report" + appointmentId + ".pdf")); + document.open(); + + Paragraph title = + new Paragraph( + new Phrase( + "Compte Rendu - Réunion du " + + this.appointmentService + .getAppointmentById(appointmentId) + .getAppointmentDate() + .toString(), + FontFactory.getFont( + FontFactory.HELVETICA, + 20, + Font.BOLDITALIC, + BaseColor.BLACK))); + title.setAlignment(Element.ALIGN_CENTER); + document.add(title); + + Font subsection = + FontFactory.getFont(FontFactory.HELVETICA, 14, Font.UNDERLINE, BaseColor.DARK_GRAY); + Font body = FontFactory.getFont(FontFactory.COURIER, 12, BaseColor.BLACK); + + String[] split = reportContent.split(" "); + + String tmp = ""; + int counter = 1; + for (String s : split) { + if (s.equals("//")) { + Chunk chunk = new Chunk(tmp, body); + document.add(chunk); + document.add(new Paragraph("\n")); + tmp = ""; + Paragraph paragraph = new Paragraph("Point n°" + counter + " : ", subsection); + document.add(paragraph); + document.add(new Paragraph("\n")); + counter++; + } else { + tmp = tmp.concat(s + " "); + } + } + Chunk chunk = new Chunk(tmp, body); + document.add(chunk); + document.add(new Paragraph("\n")); + + document.close(); } // TODO public void createAppointmentRequest(Appointment appointment, String mail) { - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + long projectId = + appointment + .getAppointmentListSectionCell() + .getFirst() + .getProjectSectionCell() + .getIdProject(); + if (!utilsService.isAllowedToCheckProject(mail, projectId)) { + logger.warn( + "User {} tried to create for the project {} but is not allowed to.", + mail, + projectId); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info("User {} tried to create an appointment for project {}", mail, projectId); + this.appointmentService.addNewAppointment(appointment); } } diff --git a/documentation/Doc.txt b/documentation/Doc.txt new file mode 100644 index 0000000..21b094a --- /dev/null +++ b/documentation/Doc.txt @@ -0,0 +1,12 @@ +Format des comptes rendus de réunion : +Texte organisé par bullet point, chaque bullet point est séparé par "//" pour pouvoir être correctement généré. + +Exemple : +Le texte "// blablabla // oui bonjour" +donne le résultat + +Point n°1 : + blablabla + +Point n°2 : + oui bonjour \ No newline at end of file -- 2.47.2 From 78c72bdd724fc323d25780c6f30744ee4fd216ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 12 Mar 2025 12:23:27 +0100 Subject: [PATCH 89/97] fix: linter --- .../main/java/enseirb/myinpulse/controller/SharedApi.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index e35818c..519ee41 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -10,7 +10,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.*; -import java.io.File; import java.io.FileNotFoundException; @SpringBootApplication @@ -84,8 +83,10 @@ public class SharedApi { @PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) { try { sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); - } catch (FileNotFoundException | DocumentException e) { - System.out.println(e); + } catch (FileNotFoundException e) { + System.out.println(e + "File not found"); + } catch (DocumentException e) { + System.out.println(e + "Document exception"); } } -- 2.47.2 From d5c89bf8f4f032b330b7c13c4e4754a93f118d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 12 Mar 2025 12:25:26 +0100 Subject: [PATCH 90/97] fix: spelling --- .../main/java/enseirb/myinpulse/service/AdminApiService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index cd70a97..e00171e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -9,7 +9,6 @@ import enseirb.myinpulse.service.database.ProjectService; import enseirb.myinpulse.service.database.UserService; import enseirb.myinpulse.service.database.AppointmentService; import enseirb.myinpulse.service.database.ReportService; -import enseirb.myinpulse.service.UtilsService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -47,7 +46,7 @@ public class AdminApiService { this.reportService = reportService; } - // TODO: check if tests are sufficients - peer verification required + // TODO: check if tests are sufficient - peer verification required public Iterable getProjectsOfAdmin(String mail) { return projectService.getProjectsByAdminId( administratorService.getAdministratorById( -- 2.47.2 From c94d3654ced7b5e4fa113d2fb4f932280ca63fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Sat, 15 Mar 2025 15:23:18 +0100 Subject: [PATCH 91/97] fix: updating foreign keys when adding new entity to the db --- .../myinpulse/model/Administrator.java | 24 ++++++++++ .../enseirb/myinpulse/model/Annotation.java | 24 ++++++++++ .../enseirb/myinpulse/model/Appointment.java | 4 ++ .../enseirb/myinpulse/model/Entrepreneur.java | 42 +++++++++++++++++ .../java/enseirb/myinpulse/model/Project.java | 47 +++++++++++++++++-- .../enseirb/myinpulse/model/SectionCell.java | 28 +++++++++-- .../myinpulse/service/AdminApiService.java | 21 +++++++-- .../service/EntrepreneurApiService.java | 15 +++++- .../myinpulse/service/SharedApiService.java | 17 +++++-- .../service/database/ProjectService.java | 2 +- 10 files changed, 206 insertions(+), 18 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java index 3b1ee7a..d6eecda 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Administrator.java @@ -39,4 +39,28 @@ public class Administrator extends User { String phoneNumber) { super(null, userSurname, username, primaryMail, secondaryMail, phoneNumber); } + + public List getListProject() { + return listProject; + } + + public void updateListProject(Project project) { + listProject.add(project); + } + + public List getListAnnotation() { + return listAnnotation; + } + + public void updateListAnnotation(Annotation annotation) { + listAnnotation.add(annotation); + } + + public MakeAppointment getMakeAppointment() { + return makeAppointment; + } + + public void setMakeAppointment(MakeAppointment makeAppointment) { + this.makeAppointment = makeAppointment; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java index a7ba0d8..f34f663 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Annotation.java @@ -34,4 +34,28 @@ public class Annotation { public void setComment(String comment) { this.comment = comment; } + + public Long getIdAnnotation() { + return idAnnotation; + } + + public void setIdAnnotation(Long idAnnotation) { + this.idAnnotation = idAnnotation; + } + + public SectionCell getSectionCellAnnotation() { + return sectionCellAnnotation; + } + + public void setSectionCellAnnotation(SectionCell sectionCellAnnotation) { + this.sectionCellAnnotation = sectionCellAnnotation; + } + + public Administrator getAdministratorAnnotation() { + return administratorAnnotation; + } + + public void setAdministratorAnnotation(Administrator administratorAnnotation) { + this.administratorAnnotation = administratorAnnotation; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java index 352ab17..a683d3f 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Appointment.java @@ -112,6 +112,10 @@ public class Appointment { return listSectionCell; } + public void updateListSectionCell(SectionCell sectionCell) { + listSectionCell.add(sectionCell); + } + public Report getAppointmentReport() { return report; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java index 7eb64d5..9763b4e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java @@ -52,6 +52,28 @@ public class Entrepreneur extends User { this.sneeStatus = sneeStatus; } + public Entrepreneur( + Long idUser, + String userSurname, + String userName, + String primaryMail, + String secondaryMail, + String phoneNumber, + String school, + String course, + boolean sneeStatus, + Project projectParticipation, + Project projectProposed, + MakeAppointment makeAppointment) { + super(idUser, userSurname, userName, primaryMail, secondaryMail, phoneNumber); + this.school = school; + this.course = course; + this.sneeStatus = sneeStatus; + this.projectParticipation = projectParticipation; + this.projectProposed = projectProposed; + this.makeAppointment = makeAppointment; + } + public String getSchool() { return school; } @@ -79,4 +101,24 @@ public class Entrepreneur extends User { public Project getProjectParticipation() { return projectParticipation; } + + public void setProjectParticipation(Project projectParticipation) { + this.projectParticipation = projectParticipation; + } + + public Project getProjectProposed() { + return projectProposed; + } + + public void setProjectProposed(Project projectProposed) { + this.projectProposed = projectProposed; + } + + public MakeAppointment getMakeAppointment() { + return makeAppointment; + } + + public void setMakeAppointment(MakeAppointment makeAppointment) { + this.makeAppointment = makeAppointment; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index b745c6f..866e685 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -51,6 +51,21 @@ public class Project { this.projectAdministrator = projectAdministrator; } + public Project( + String projectName, + byte[] logo, + LocalDate creationDate, + ProjectDecisionValue projectStatus, + Administrator projectAdministrator, + Entrepreneur entrepreneurProposed) { + this.projectName = projectName; + this.logo = logo; + this.creationDate = creationDate; + this.projectStatus = projectStatus; + this.projectAdministrator = projectAdministrator; + this.entrepreneurProposed = entrepreneurProposed; + } + public Long getIdProject() { return idProject; } @@ -91,11 +106,35 @@ public class Project { this.projectStatus = projectStatus; } - public Administrator getAdministrator() { - return this.projectAdministrator; + public List getListEntrepreneurParticipation() { + return listEntrepreneurParticipation; } - public void setAdministrator(Administrator administrator) { - this.projectAdministrator = administrator; + public void updateListEntrepreneurParticipation(Entrepreneur projectParticipant) { + listEntrepreneurParticipation.add(projectParticipant); + } + + public List getListSectionCell() { + return listSectionCell; + } + + public void updateListSectionCell(SectionCell projectSectionCell) { + listSectionCell.add(projectSectionCell); + } + + public Administrator getProjectAdministrator() { + return projectAdministrator; + } + + public void setProjectAdministrator(Administrator projectAdministrator) { + this.projectAdministrator = projectAdministrator; + } + + public Entrepreneur getEntrepreneurProposed() { + return entrepreneurProposed; + } + + public void setEntrepreneurProposed(Entrepreneur entrepreneurProposed) { + this.entrepreneurProposed = entrepreneurProposed; } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java index 0fb8c89..2bd1888 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -11,7 +11,7 @@ import java.util.List; public class SectionCell { @ManyToMany(mappedBy = "listSectionCell") - private final List appointment = new ArrayList<>(); + private final List listAppointment = new ArrayList<>(); @OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true) private final List listAnnotation = new ArrayList<>(); @@ -39,11 +39,13 @@ public class SectionCell { Long idSectionCell, Long sectionId, String contentSectionCell, - LocalDateTime modificationDate) { + LocalDateTime modificationDate, + Project projectSectionCell) { this.idSectionCell = idSectionCell; this.sectionId = sectionId; this.contentSectionCell = contentSectionCell; this.modificationDate = modificationDate; + this.projectSectionCell = projectSectionCell; } public Long getIdSectionCell() { @@ -83,6 +85,26 @@ public class SectionCell { } public List getAppointmentSectionCell() { - return appointment; + return listAppointment; + } + + public void updateAppointmentSectionCell(Appointment appointment) { + listAppointment.add(appointment); + } + + public List getListAnnotation() { + return listAnnotation; + } + + public void updateListAnnotation(Annotation annotation) { + listAnnotation.add(annotation); + } + + public void setSectionId(long sectionId) { + this.sectionId = sectionId; + } + + public void setProjectSectionCell(Project projectSectionCell) { + this.projectSectionCell = projectSectionCell; } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index e00171e..d6efc7d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -5,14 +5,13 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED; import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.database.AdministratorService; -import enseirb.myinpulse.service.database.ProjectService; -import enseirb.myinpulse.service.database.UserService; import enseirb.myinpulse.service.database.AppointmentService; +import enseirb.myinpulse.service.database.ProjectService; import enseirb.myinpulse.service.database.ReportService; +import enseirb.myinpulse.service.database.UserService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -86,8 +85,22 @@ public class AdminApiService { if (e.getStatusCode() == HttpStatus.CONFLICT) { throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists"); } - projectService.addNewProject(project); } + Project newProject = projectService.addNewProject(project); + newProject.getProjectAdministrator().updateListProject(newProject); + newProject.getEntrepreneurProposed().setProjectProposed(newProject); + newProject + .getListEntrepreneurParticipation() + .forEach( + participation -> { + participation.setProjectParticipation(newProject); + }); + newProject + .getListSectionCell() + .forEach( + sectionCell -> { + sectionCell.setProjectSectionCell(newProject); + }); } public void createAppointmentReport(long appointmentId, Report report, String mail) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index f1d6260..1e9cd92 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -107,7 +107,20 @@ public class EntrepreneurApiService { mail, sectionCell.getIdSectionCell(), this.sectionCellService.getProjectId(sectionCell.getIdSectionCell())); - sectionCellService.addNewSectionCell(sectionCell); + SectionCell newSectionCell = sectionCellService.addNewSectionCell(sectionCell); + newSectionCell.getProjectSectionCell().updateListSectionCell(newSectionCell); + newSectionCell + .getAppointmentSectionCell() + .forEach( + appointment -> { + appointment.updateListSectionCell(newSectionCell); + }); + newSectionCell + .getListAnnotation() + .forEach( + annotation -> { + annotation.setSectionCellAnnotation(newSectionCell); + }); } public void requestNewProject(Project project, String mail) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index 869b278..fc539b7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -1,5 +1,8 @@ package enseirb.myinpulse.service; +import com.itextpdf.text.*; +import com.itextpdf.text.pdf.PdfWriter; + import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.database.*; @@ -10,9 +13,6 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; -import com.itextpdf.text.*; -import com.itextpdf.text.pdf.PdfWriter; - import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.time.LocalDateTime; @@ -92,7 +92,7 @@ public class SharedApiService { HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); } Project project = this.projectService.getProjectById(projectId); - return project.getAdministrator(); + return project.getProjectAdministrator(); } // TODO @@ -221,6 +221,13 @@ public class SharedApiService { HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); } logger.info("User {} tried to create an appointment for project {}", mail, projectId); - this.appointmentService.addNewAppointment(appointment); + Appointment newAppointment = this.appointmentService.addNewAppointment(appointment); + newAppointment + .getAppointmentListSectionCell() + .forEach( + sectionCell -> { + sectionCell.updateAppointmentSectionCell(newAppointment); + }); + newAppointment.getAppointmentReport().setAppointmentReport(newAppointment); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index 32fc4c4..7eb0651 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -91,7 +91,7 @@ public class ProjectService { } if (administrator != null) { - project.get().setAdministrator(administrator); + project.get().setProjectAdministrator(administrator); } return this.projectRepository.save(project.get()); -- 2.47.2 From fea86876647c498d481f4e70fbe62cbdf2373b0f Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Mon, 17 Mar 2025 09:05:24 +0100 Subject: [PATCH 92/97] feat: now running tests --- .gitea/workflows/build-back.yaml | 12 ++++++++++-- config/.env.dev | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 config/.env.dev diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index 60dd4fa..fcc93f6 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -9,6 +9,14 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 + + - name: Load .env file + uses: xom9ikk/dotenv@v2.3.0 + with: + path: ./config/ + mode: dev + load-mode: strict + - name: Setup Java uses: actions/setup-java@v4 with: @@ -18,8 +26,8 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 with: - cache-disabled: true + cache-disabled: true # Once the code has been pushed once in main, this should be reenabled. - name: init gradle working-directory: ./MyINPulse-back/ - run: ./gradlew build -x test # todo: run test, currently fail because no database is present + run: ./gradlew build # todo: run test, currently fail because no database is present diff --git a/config/.env.dev b/config/.env.dev new file mode 100644 index 0000000..bcd45f3 --- /dev/null +++ b/config/.env.dev @@ -0,0 +1,22 @@ +POSTGRES_DB=postgres_db +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres_db_user_password + +KEYCLOAK_ADMIN=admin +KEYCLOAK_ADMIN_PASSWORD=admin +KEYCLOAK_HOSTNAME=localhost +KEYCLOAK_DB=keycloak_db +KEYCLOAK_USER=keycloak_db_user +KEYCLOAK_PASSWORD=keycloak_db_user_password + +BACKEND_DB=backend_db +BACKEND_USER=backend_db_user +BACKEND_PASSWORD=backend_db_user_password + +DATABASE_URL=localhost:5433 + +VITE_KEYCLOAK_URL=http://localhost:7080 +VITE_KEYCLOAK_CLIENT_ID=myinpulse-dev +VITE_KEYCLOAK_REALM=test +VITE_APP_URL=http://localhost:5173 +VITE_BACKEND_URL=http://localhost:8081/ -- 2.47.2 From 834d68949c52cebc4a4d4185fcbbb886804d9e70 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Mon, 17 Mar 2025 09:08:33 +0100 Subject: [PATCH 93/97] fix: tabulation error --- .gitea/workflows/build-back.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/build-back.yaml b/.gitea/workflows/build-back.yaml index fcc93f6..2526e98 100644 --- a/.gitea/workflows/build-back.yaml +++ b/.gitea/workflows/build-back.yaml @@ -10,12 +10,12 @@ jobs: - name: Checkout sources uses: actions/checkout@v4 - - name: Load .env file - uses: xom9ikk/dotenv@v2.3.0 - with: - path: ./config/ - mode: dev - load-mode: strict + - name: Load .env file + uses: xom9ikk/dotenv@v2.3.0 + with: + path: ./config/ + mode: dev + load-mode: strict - name: Setup Java uses: actions/setup-java@v4 -- 2.47.2 From 84b70f8f388aa34190ba9dc26d9884998d6c85a7 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Mon, 17 Mar 2025 09:18:21 +0100 Subject: [PATCH 94/97] fix: sometimes, project administrators may be null. Fixing nullPointerException --- .../enseirb/myinpulse/service/AdminApiService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index d6efc7d..9f42d0e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -77,7 +77,7 @@ public class AdminApiService { // TODO: check if tests are sufficient - peer verification required public void addNewProject(Project project) { project.setIdProject(null); - // We remove it from the request to be sure that it will be auto generated + // We remove the ID from the request to be sure that it will be auto generated try { this.projectService.getProjectByName(project.getProjectName(), true); throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists"); @@ -87,8 +87,12 @@ public class AdminApiService { } } Project newProject = projectService.addNewProject(project); - newProject.getProjectAdministrator().updateListProject(newProject); - newProject.getEntrepreneurProposed().setProjectProposed(newProject); + if (project.getProjectAdministrator() != null) { + newProject.getProjectAdministrator().updateListProject(newProject); + } + if (newProject.getEntrepreneurProposed() != null) { + newProject.getEntrepreneurProposed().setProjectProposed(newProject); + } newProject .getListEntrepreneurParticipation() .forEach( -- 2.47.2 From 52511dd4c4609939fbb7663da36e8b4b1172e98f Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 19 Mar 2025 10:42:46 +0100 Subject: [PATCH 95/97] fix: Makefile now run everything needed to build the app --- Makefile | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 617387b..6f4e820 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,14 @@ front/MyINPulse-front/.installed: vite: ./front/MyINPulse-front/.installed +keycloak: ./keycloak/.installed -dev-front: clean vite +keycloak/.installed: + @echo "running one time install" + @cd keycloak/CAS && sudo sh build.sh + @touch ./keycloak/.installed + +dev-front: clean vite keycloak @cp config/frontdev.env front/MyINPulse-front/.env @cp config/frontdev.env .env @cp config/frontdev.env MyINPulse-back/.env @@ -28,7 +34,7 @@ dev-front: clean vite @docker compose up -d --build @cd ./front/MyINPulse-front/ && npm run dev -prod: clean +prod: clean keycloak @cp config/prod.env front/MyINPulse-front/.env @cp config/prod.env .env @cp config/prod.env .env @@ -37,7 +43,7 @@ prod: clean -dev-back: +dev-back: keycloak @cp config/backdev.env front/MyINPulse-front/.env @cp config/backdev.env .env @cp config/backdev.env MyINPulse-back/.env @@ -46,7 +52,7 @@ dev-back: @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' @echo "./gradlew bootRun --args='--server.port=8081'" -dev: clean vite +dev: clean vite keycloak @cp config/dev.env front/MyINPulse-front/.env @cp config/dev.env .env @cp config/dev.env MyINPulse-back/.env @@ -55,3 +61,13 @@ dev: clean vite @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' @echo "./gradlew bootRun --args='--server.port=8081'" @cd ./front/MyINPulse-front/ && npm run dev & + +test-back: clean keycloak + @cp config/dev.env front/MyINPulse-front/.env + @cp config/dev.env .env + @cp config/dev.env MyINPulse-back/.env + @cp config/dev.docker-compose.yaml docker-compose.yaml + @docker compose up -d --build + @echo "cd MyINPulse-back" && echo 'export $$(cat .env | xargs)' + @cd ./MyINPulse-back/ && ./gradlew test && ./gradlew jacocoTestReport + @firefox ./MyINPulse-back/build/jacocoHtml/index.html -- 2.47.2 From 5ee375554899cc335e3dface6ee68453945f5b40 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 19 Mar 2025 12:05:01 +0100 Subject: [PATCH 96/97] feat: added new tests and fixed few issues --- .../enseirb/myinpulse/model/Entrepreneur.java | 3 +- .../java/enseirb/myinpulse/model/User.java | 15 +++++ .../myinpulse/service/AdminApiService.java | 4 +- .../myinpulse/AdminApiServiceTest.java | 57 ++++++++++++++++++- 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java index 9763b4e..35b6e71 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Entrepreneur.java @@ -37,7 +37,6 @@ public class Entrepreneur extends User { public Entrepreneur() {} public Entrepreneur( - Long idUser, String userSurname, String username, String primaryMail, @@ -46,7 +45,7 @@ public class Entrepreneur extends User { String school, String course, boolean sneeStatus) { - super(idUser, userSurname, username, primaryMail, secondaryMail, phoneNumber); + super(userSurname, username, primaryMail, secondaryMail, phoneNumber); this.school = school; this.course = course; this.sneeStatus = sneeStatus; diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java index 4d7f32f..37a551d 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/User.java @@ -28,6 +28,8 @@ public class User { public User() {} + // TODO: this should be removed as we shouldn't be able to chose the ID. Leaving it for + // compatibility purposes, as soon as it's not used anymore, delete it public User( Long idUser, String userSurname, @@ -43,6 +45,19 @@ public class User { this.phoneNumber = phoneNumber; } + public User( + String userSurname, + String userName, + String primaryMail, + String secondaryMail, + String phoneNumber) { + this.userSurname = userSurname; + this.userName = userName; + this.primaryMail = primaryMail; + this.secondaryMail = secondaryMail; + this.phoneNumber = phoneNumber; + } + public Long getIdUser() { return idUser; } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 9f42d0e..38cb9e6 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -91,7 +91,9 @@ public class AdminApiService { newProject.getProjectAdministrator().updateListProject(newProject); } if (newProject.getEntrepreneurProposed() != null) { - newProject.getEntrepreneurProposed().setProjectProposed(newProject); + Entrepreneur proposed = newProject.getEntrepreneurProposed(); + proposed.setProjectProposed(newProject); + proposed.setProjectParticipation(newProject); } newProject .getListEntrepreneurParticipation() diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java index abd21fb..676dfc9 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/AdminApiServiceTest.java @@ -5,10 +5,12 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.*; import static org.junit.jupiter.api.Assertions.*; import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.ProjectDecision; import enseirb.myinpulse.service.AdminApiService; import enseirb.myinpulse.service.database.AdministratorService; +import enseirb.myinpulse.service.database.EntrepreneurService; import enseirb.myinpulse.service.database.ProjectService; import org.junit.jupiter.api.BeforeAll; @@ -26,13 +28,16 @@ import java.util.List; @Transactional public class AdminApiServiceTest { private static long administratorid; + private static Administrator administrator; + private static Entrepreneur entrepreneur; @Autowired private AdminApiService adminApiService; @Autowired private ProjectService projectService; @BeforeAll static void setup( @Autowired AdministratorService administratorService, - @Autowired ProjectService projectService) { + @Autowired ProjectService projectService, + @Autowired EntrepreneurService entrepreneurService) { administratorService.addAdministrator( new Administrator( "admin", @@ -40,7 +45,7 @@ public class AdminApiServiceTest { "testAdminEmpty@example.com", "testAdmin@example.com", "")); - Administrator a = + administrator = administratorService.addAdministrator( new Administrator( "admin2", @@ -48,7 +53,18 @@ public class AdminApiServiceTest { "testAdminFull@example.com", "testAdmin@example.com", "")); - administratorid = a.getIdUser(); + administratorid = administrator.getIdUser(); + entrepreneur = + new Entrepreneur( + "JeSuisUnEntrepreneurDeCompet", + "EtUé", + "Entrepreneur@inpulse.com", + "mail2", + "phone", + "Ensimag nan jdeconne ENSEIRB (-matmeca mais on s'en fout)", + "info ofc", + false); + entrepreneurService.addEntrepreneur(entrepreneur); projectService.addNewProject( new Project( "sampleProjectAdminApiService", @@ -161,6 +177,41 @@ public class AdminApiServiceTest { assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size()); } + @Test + void addProjectToAdmin() { + assertEquals(0, administrator.getListProject().size()); + Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, administrator); + this.adminApiService.addNewProject(p1); + assertEquals(1, administrator.getListProject().size()); + } + + @Test + void addProjectToUser() { + assertNull(entrepreneur.getProjectParticipation()); + Project p1 = + new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, entrepreneur); + this.adminApiService.addNewProject(p1); + assertEquals(p1, entrepreneur.getProjectParticipation()); + } + + @Test + void addProjectWithManyUsers() { + Entrepreneur e1 = new Entrepreneur(); + Entrepreneur e2 = new Entrepreneur(); + Entrepreneur e3 = new Entrepreneur(); + assertNull(e1.getProjectParticipation()); + assertNull(e2.getProjectParticipation()); + assertNull(e3.getProjectParticipation()); + Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, null); + p1.updateListEntrepreneurParticipation(e1); + p1.updateListEntrepreneurParticipation(e2); + p1.updateListEntrepreneurParticipation(e3); + this.adminApiService.addNewProject(p1); + assertEquals(p1, e1.getProjectParticipation()); + assertEquals(p1, e2.getProjectParticipation()); + assertEquals(p1, e3.getProjectParticipation()); + } + @Test void addDuplicateProject() { Project p1 = -- 2.47.2 From 3c61fdca93e0a80100826fa8099279a63ebd1cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 19 Mar 2025 12:05:56 +0100 Subject: [PATCH 97/97] feat: finished implementing apiService functions --- .../myinpulse/controller/SharedApi.java | 10 +++-- .../myinpulse/service/AdminApiService.java | 44 +++++++++++++++---- .../myinpulse/service/SharedApiService.java | 29 +++++++++--- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java index 519ee41..a0b63e3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.controller; import com.itextpdf.text.DocumentException; + import enseirb.myinpulse.model.*; import enseirb.myinpulse.service.SharedApiService; @@ -10,7 +11,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.web.bind.annotation.*; -import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URISyntaxException; @SpringBootApplication @RestController @@ -83,10 +85,12 @@ public class SharedApi { @PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) { try { sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); - } catch (FileNotFoundException e) { - System.out.println(e + "File not found"); } catch (DocumentException e) { System.out.println(e + "Document exception"); + } catch (URISyntaxException e) { + System.out.println(e + "Error with URI"); + } catch (IOException e) { + System.out.println(e + "Failed to access file"); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index d6efc7d..629aaf1 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -4,11 +4,7 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE; import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED; import enseirb.myinpulse.model.*; -import enseirb.myinpulse.service.database.AdministratorService; -import enseirb.myinpulse.service.database.AppointmentService; -import enseirb.myinpulse.service.database.ProjectService; -import enseirb.myinpulse.service.database.ReportService; -import enseirb.myinpulse.service.database.UserService; +import enseirb.myinpulse.service.database.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -17,6 +13,9 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; +import java.util.ArrayList; +import java.util.List; + @Service public class AdminApiService { @@ -28,6 +27,7 @@ public class AdminApiService { private final UtilsService utilsService; private final AppointmentService appointmentService; private final ReportService reportService; + private final SectionCellService sectionCellService; @Autowired AdminApiService( @@ -36,13 +36,15 @@ public class AdminApiService { AdministratorService administratorService, UtilsService utilsService, AppointmentService appointmentService, - ReportService reportService) { + ReportService reportService, + SectionCellService sectionCellService) { this.projectService = projectService; this.userService = userService; this.administratorService = administratorService; this.utilsService = utilsService; this.appointmentService = appointmentService; this.reportService = reportService; + this.sectionCellService = sectionCellService; } // TODO: check if tests are sufficient - peer verification required @@ -52,10 +54,36 @@ public class AdminApiService { this.userService.getUserByEmail(mail).getIdUser())); } - // TODO public Iterable getUpcomingAppointments(String mail) { logger.info("User {} check their upcoming appointments", mail); - throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); + User user = this.userService.getUserByEmail(mail); + List appointments = new ArrayList<>(); + if (user instanceof Administrator) { + List projects = new ArrayList<>(((Administrator) user).getListProject()); + projects.forEach( + project -> { + project.getListSectionCell() + .forEach( + sectionCell -> { + appointments.addAll( + this.sectionCellService + .getAppointmentsBySectionCellId( + sectionCell + .getIdSectionCell())); + }); + }); + } + if (user instanceof Entrepreneur) { + Project project = ((Entrepreneur) user).getProjectParticipation(); + project.getListSectionCell() + .forEach( + sectionCell -> { + appointments.addAll( + this.sectionCellService.getAppointmentsBySectionCellId( + sectionCell.getIdSectionCell())); + }); + } + return appointments; } // TODO: check if tests are sufficient - peer verification required diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java index fc539b7..23ad616 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java @@ -13,8 +13,14 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; -import java.io.FileNotFoundException; +import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -95,7 +101,6 @@ public class SharedApiService { return project.getProjectAdministrator(); } - // TODO public Iterable getAppointmentsByProjectId(long projectId, String mail) { if (!utilsService.isAllowedToCheckProject(mail, projectId)) { logger.warn( @@ -123,9 +128,8 @@ public class SharedApiService { return appointments; } - // public void getPDFReport(long appointmentId, String mail) - throws FileNotFoundException, DocumentException { + throws DocumentException, URISyntaxException, IOException { long projectId = this.appointmentService .getAppointmentById(appointmentId) @@ -202,9 +206,24 @@ public class SharedApiService { document.add(new Paragraph("\n")); document.close(); + + // Replace uri with website address + Files.copy( + new URI( + "http://localhost:8080/shared/projects/appointments/report/" + + appointmentId) + .toURL() + .openStream(), + Paths.get("Report" + appointmentId + ".pdf"), + StandardCopyOption.REPLACE_EXISTING); + + // delete file, we don't want to stock all reports on the server + File file = new File("Report" + appointmentId + ".pdf"); + if (!file.delete()) { + logger.warn("Failed to delete report {}", file.getAbsolutePath()); + } } - // TODO public void createAppointmentRequest(Appointment appointment, String mail) { long projectId = appointment -- 2.47.2