backend-api #6

Merged
piair merged 107 commits from backend-api into main 2025-03-26 19:04:09 +01:00
6 changed files with 77 additions and 57 deletions
Showing only changes of commit 153501c8d4 - Show all commits

View File

@ -5,6 +5,8 @@ import enseirb.myinpulse.service.AdminApiService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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.*; import org.springframework.web.bind.annotation.*;
@SpringBootApplication @SpringBootApplication
@ -34,8 +36,8 @@ public class AdminApi {
* @return a list of upcoming appointments for the current user * @return a list of upcoming appointments for the current user
*/ */
@GetMapping("/admin/appointments/upcoming") @GetMapping("/admin/appointments/upcoming")
public Iterable<DelAppointment> getUpcomingAppointments() { public Iterable<Appointment> getUpcomingAppointments(@AuthenticationPrincipal Jwt principal) {
return adminApiService.getUpcomingAppointments(); return adminApiService.getUpcomingAppointments(principal.getClaimAsString("email"));
} }
/** /**
@ -44,13 +46,15 @@ public class AdminApi {
* @return a list of current unvalidated projects, waiting to be accepted * @return a list of current unvalidated projects, waiting to be accepted
*/ */
@GetMapping("/admin/projects/pending") @GetMapping("/admin/projects/pending")
public Iterable<DelProject> getPendingProjects() { public Iterable<Project> getPendingProjects() {
return adminApiService.getPendingProjects(); return adminApiService.getPendingProjects();
} }
/** /**
* Endpoint used to make a decision about a project. * Endpoint used to make a decision about a project.
* *
* <p>The decision must contains the administrator
*
* @return the status code of the request * @return the status code of the request
*/ */
@PostMapping("/admin/projects/decision") @PostMapping("/admin/projects/decision")
@ -64,7 +68,7 @@ public class AdminApi {
* @return the status code of the request * @return the status code of the request
*/ */
@PostMapping("/admin/project/add") @PostMapping("/admin/project/add")
public void addNewProject(@RequestBody DelProject project) { public void addNewProject(@RequestBody Project project) {
adminApiService.addNewProject(project); adminApiService.addNewProject(project);
} }
@ -77,8 +81,11 @@ public class AdminApi {
*/ */
@PostMapping("/admin/appoitements/report/{appointmentId}") @PostMapping("/admin/appoitements/report/{appointmentId}")
public void createAppointmentReport( public void createAppointmentReport(
@PathVariable String appointmentId, @RequestBody DelReport report) { @PathVariable String appointmentId,
adminApiService.createAppointmentReport(appointmentId, report); @RequestBody Report report,
@AuthenticationPrincipal Jwt principal) {
adminApiService.createAppointmentReport(
appointmentId, report, principal.getClaimAsString("email"));
} }
/** /**

View File

@ -1,11 +1,13 @@
package enseirb.myinpulse.controller; package enseirb.myinpulse.controller;
import enseirb.myinpulse.model.LCSection; import enseirb.myinpulse.model.LCSection;
import enseirb.myinpulse.model.DelProject; import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.service.EntrepreneurApiService; import enseirb.myinpulse.service.EntrepreneurApiService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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.*; import org.springframework.web.bind.annotation.*;
@SpringBootApplication @SpringBootApplication
@ -27,8 +29,12 @@ public class EntrepreneurApi {
* @return status code * @return status code
*/ */
@PutMapping("/entrepreneur/lcsection/modify/{sectionId}") @PutMapping("/entrepreneur/lcsection/modify/{sectionId}")
public void editLCSection(@PathVariable String sectionId, @RequestBody LCSection section) { public void editLCSection(
entrepreneurApiService.editLCSection(sectionId, section); @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 * @return status code
*/ */
@DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}")
public void removeLCSection(@PathVariable String sectionId) { public void removeLCSection(
entrepreneurApiService.removeLCSection(sectionId); @PathVariable String sectionId, @AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.removeLCSection(sectionId, principal.getClaimAsString("email"));
} }
/** /**
@ -51,8 +58,12 @@ public class EntrepreneurApi {
* @return status code * @return status code
*/ */
@PostMapping("/entrepreneur/lcsection/add/{sectionId}") @PostMapping("/entrepreneur/lcsection/add/{sectionId}")
public void addLCSection(@PathVariable String sectionId, @RequestBody LCSection section) { public void addLCSection(
entrepreneurApiService.addLCSection(sectionId, section); @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 * @return status code
*/ */
@PostMapping("/entrepreneur/project/request") @PostMapping("/entrepreneur/project/request")
public void requestNewProject(@RequestBody DelProject project) { public void requestNewProject(
entrepreneurApiService.requestNewProject(project); @RequestBody Project project, @AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.requestNewProject(project, principal.getClaimAsString("email"));
} }
} }

View File

@ -1,13 +1,12 @@
package enseirb.myinpulse.controller; package enseirb.myinpulse.controller;
import enseirb.myinpulse.model.Administrator; import enseirb.myinpulse.model.*;
import enseirb.myinpulse.model.DelAppointment;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.service.SharedApiService; import enseirb.myinpulse.service.SharedApiService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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.*; import org.springframework.web.bind.annotation.*;
@SpringBootApplication @SpringBootApplication
@ -34,8 +33,10 @@ public class SharedApi {
public Iterable<SectionCell> getLCSection( public Iterable<SectionCell> getLCSection(
@PathVariable("projectId") String projectId, @PathVariable("projectId") String projectId,
@PathVariable("title") String title, @PathVariable("title") String title,
@PathVariable("date") String date) { @PathVariable("date") String date,
return sharedApiService.getLCSection(projectId, title, date); @AuthenticationPrincipal Jwt principal) {
return sharedApiService.getLCSection(
projectId, title, date, principal.getClaimAsString("email"));
} }
/** /**
@ -44,34 +45,33 @@ public class SharedApi {
* @return a list of all entrepreneurs in a project * @return a list of all entrepreneurs in a project
*/ */
@GetMapping("/shared/entrepreneurs/{projectId}") @GetMapping("/shared/entrepreneurs/{projectId}")
public Iterable<Entrepreneur> getEntrepreneursByProjectId(@PathVariable int projectId) { public Iterable<Entrepreneur> getEntrepreneursByProjectId(
return sharedApiService.getEntrepreneursByProjectId(projectId); @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 * Endpoint used to get the administrator of a project.
* administrator.
*
* <p>Endpoint used to get the administrator of a project.
* *
* @return a list of all project managed by the current admin user * @return a list of all project managed by the current admin user
*/ */
@GetMapping("/shared/projects/admin/{projectId}") @GetMapping("/shared/projects/admin/{projectId}")
public Iterable<Administrator> getAdminByProjectId(@PathVariable int projectId) { public Iterable<Administrator> getAdminByProjectId(
return sharedApiService.getAdminByProjectId(projectId); @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 \\ * Endpoint used to get all appointments of a single project.
* TODO: between both ?
*
* <p>Endpoint used to get all appointments of a single project.
* *
* @return a list of all appointments. * @return a list of all appointments.
*/ */
@GetMapping("/shared/projects/appointments/{projectId}") @GetMapping("/shared/projects/appointments/{projectId}")
public Iterable<DelAppointment> getAppointmentsByProjectId(@PathVariable int projectId) { public Iterable<Appointment> getAppointmentsByProjectId(
return sharedApiService.getAppointmentsByProjectId(projectId); @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) {
return sharedApiService.getAppointmentsByProjectId(
projectId, principal.getClaimAsString("email"));
} }
/** /**
@ -80,17 +80,17 @@ public class SharedApi {
* @return a PDF file? TODO: how does that works ? * @return a PDF file? TODO: how does that works ?
*/ */
@GetMapping("/shared/projects/appointments/report/{appointmentId}") @GetMapping("/shared/projects/appointments/report/{appointmentId}")
public void getPDFReport(@PathVariable int appointmentId) { public void getPDFReport(
sharedApiService.getPDFReport(appointmentId); @PathVariable int appointmentId, @AuthenticationPrincipal Jwt principal) {
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
} }
/** /**
* TODO
*
* @return TODO * @return TODO
*/ */
@PostMapping("/shared/appointment/request") @PostMapping("/shared/appointment/request")
public void createAppointmentRequest(@RequestBody DelAppointment appointment) { public void createAppointmentRequest(
sharedApiService.createAppointmentRequest(appointment); @RequestBody Appointment appointment, @AuthenticationPrincipal Jwt principal) {
sharedApiService.createAppointmentRequest(appointment, principal.getClaimAsString("email"));
} }
} }

View File

@ -14,12 +14,12 @@ public class AdminApiService {
} }
// TODO // TODO
public Iterable<DelAppointment> getUpcomingAppointments() { public Iterable<Appointment> getUpcomingAppointments(String email) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
// TODO // TODO
public Iterable<DelProject> getPendingProjects() { public Iterable<Project> getPendingProjects() {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
@ -29,12 +29,12 @@ public class AdminApiService {
} }
// TODO // TODO
public void addNewProject(DelProject project) { public void addNewProject(Project project) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
// TODO // TODO
public void createAppointmentReport(String appointmentId, DelReport report) { public void createAppointmentReport(String appointmentId, Report report, String email) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }

View File

@ -1,28 +1,29 @@
package enseirb.myinpulse.service; package enseirb.myinpulse.service;
import enseirb.myinpulse.model.LCSection; import enseirb.myinpulse.model.LCSection;
import enseirb.myinpulse.model.DelProject; import enseirb.myinpulse.model.Project;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
@Service @Service
public class EntrepreneurApiService { 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"); 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"); 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"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
public void requestNewProject(DelProject project) { public void requestNewProject(Project project, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
} }

View File

@ -9,28 +9,28 @@ import org.springframework.web.server.ResponseStatusException;
@Service @Service
public class SharedApiService { public class SharedApiService {
public Iterable<SectionCell> getLCSection(String projectId, String title, String date) { public Iterable<SectionCell> getLCSection(
String projectId, String title, String date, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
public Iterable<Entrepreneur> getEntrepreneursByProjectId(int projectId) { public Iterable<Entrepreneur> getEntrepreneursByProjectId(int projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
public Iterable<Administrator> getAdminByProjectId(int projectId) { public Iterable<Administrator> getAdminByProjectId(int projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
public Iterable<DelAppointment> getAppointmentsByProjectId(int projectId) { public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); 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"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
public void createAppointmentRequest(DelAppointment appointment) { public void createAppointmentRequest(Appointment appointment, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
} }