106 lines
3.7 KiB
Java
106 lines
3.7 KiB
Java
package enseirb.myinpulse.controller;
|
|
|
|
import com.itextpdf.text.DocumentException;
|
|
|
|
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.*;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URISyntaxException;
|
|
|
|
@SpringBootApplication
|
|
@RestController
|
|
public class SharedApi {
|
|
|
|
private final SharedApiService sharedApiService;
|
|
|
|
@Autowired
|
|
SharedApi(SharedApiService sharedApiService) {
|
|
this.sharedApiService = sharedApiService;
|
|
}
|
|
|
|
/**
|
|
* Endpoint used to get the data inside the lean canvas
|
|
*
|
|
* @return a list of lean canvas sections
|
|
*/
|
|
@GetMapping("/shared/project/lcsection/{projectId}/{sectionId}/{date}")
|
|
public Iterable<SectionCell> getLCSection(
|
|
@PathVariable("projectId") Long projectId,
|
|
@PathVariable("sectionId") Long sectionId,
|
|
@PathVariable("date") String date,
|
|
@AuthenticationPrincipal Jwt principal) {
|
|
return sharedApiService.getSectionCells(
|
|
projectId, sectionId, 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<Entrepreneur> getEntrepreneursByProjectId(
|
|
@PathVariable int projectId, @AuthenticationPrincipal Jwt principal) {
|
|
return sharedApiService.getEntrepreneursByProjectId(
|
|
projectId, principal.getClaimAsString("email"));
|
|
}
|
|
|
|
/**
|
|
* Endpoint used to get the administrator of a project.
|
|
*
|
|
* @return the admin of a project
|
|
*/
|
|
@GetMapping("/shared/projects/admin/{projectId}")
|
|
public Administrator 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<Appointment> 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) {
|
|
try {
|
|
sharedApiService.getPDFReport(appointmentId, principal.getClaimAsString("email"));
|
|
} 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");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return TODO
|
|
*/
|
|
@PostMapping("/shared/appointment/request")
|
|
public void createAppointmentRequest(
|
|
@RequestBody Appointment appointment, @AuthenticationPrincipal Jwt principal) {
|
|
sharedApiService.createAppointmentRequest(appointment, principal.getClaimAsString("email"));
|
|
}
|
|
}
|