package enseirb.myinpulse.controller; import enseirb.myinpulse.model.*; 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 @RestController public class AdminApi { private final AdminApiService adminApiService; @Autowired AdminApi(AdminApiService adminApiService) { this.adminApiService = adminApiService; } /** * TODO: description * * @return a list of all project managed by the current admin user */ @GetMapping("/admin/projects") public Iterable getProjects(@AuthenticationPrincipal Jwt principal) { return adminApiService.getProjectsOfAdmin(principal.getClaimAsString("email")); } /** * TODO: Why in admin instead of shared ? + desc * * @return a list of upcoming appointments for the current user */ @GetMapping("/admin/appointments/upcoming") public Iterable getUpcomingAppointments(@AuthenticationPrincipal Jwt principal) { return adminApiService.getUpcomingAppointments(principal.getClaimAsString("email")); } /** * TODO: description * * @return a list of current unvalidated projects, waiting to be accepted */ @GetMapping("/admin/projects/pending") public Iterable getPendingProjects() { return adminApiService.getPendingProjects(); } /** * Endpoint used to make a decision about a project. * *

The decision must contain the administrator * * @return the status code of the request */ @PostMapping("/admin/projects/decision") public void validateProject(@RequestBody ProjectDecision decision) { adminApiService.validateProject(decision); } /** * 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) { adminApiService.addNewProject(project); } /** * TODO: shouldn't it be an PUT request ? / What is the rerun type * *

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, @AuthenticationPrincipal Jwt principal) { adminApiService.createAppointmentReport( appointmentId, report, principal.getClaimAsString("email")); } /** * 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 long projectId) { adminApiService.deleteProject(projectId); } }