From 4698aa549f5f575a293ec1d850bae8a960b0c838 Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Wed, 19 Feb 2025 12:09:37 +0100 Subject: [PATCH] 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"); } }