package enseirb.myinpulse.controller; import enseirb.myinpulse.model.*; 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 @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 ? * 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 Iterable getLCSection( @PathVariable("projectId") String projectId, @PathVariable("title") String title, @PathVariable("date") String date, @AuthenticationPrincipal Jwt principal) { return sharedApiService.getLCSection( projectId, title, date, principal.getClaimAsString("email")); } /** * Endpoint used to get entrepreneurs details * * @return a list of all entrepreneurs in a project */ @GetMapping("/shared/entrepreneurs/{projectId}") public Iterable getEntrepreneursByProjectId( @PathVariable int projectId, @AuthenticationPrincipal Jwt principal) { return sharedApiService.getEntrepreneursByProjectId( projectId, principal.getClaimAsString("email")); } /** * 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, @AuthenticationPrincipal Jwt principal) { return sharedApiService.getAdminByProjectId(projectId, principal.getClaimAsString("email")); } /** * 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, @AuthenticationPrincipal Jwt principal) { return sharedApiService.getAppointmentsByProjectId( projectId, principal.getClaimAsString("email")); } /** * 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, @AuthenticationPrincipal Jwt principal) { sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email")); } /** * @return TODO */ @PostMapping("/shared/appointment/request") public void createAppointmentRequest( @RequestBody Appointment appointment, @AuthenticationPrincipal Jwt principal) { sharedApiService.createAppointmentRequest(appointment, principal.getClaimAsString("email")); } }