Pierre Tellier 66be0baca6
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 5m20s
CI / build (push) Successful in 11s
feat: created a better account creation flow
2025-04-09 17:39:43 +02:00

119 lines
3.9 KiB
Java

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<Project> 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<Appointment> 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<Project> getPendingProjects() {
return adminApiService.getPendingProjects();
}
/**
* Endpoint used to make a decision about a project.
*
* <p>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
*
* <p>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 long 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 ?
*
* <p>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);
}
@GetMapping("/admin/setadmin/{userId}")
public void setAdmin(@PathVariable long userId, @AuthenticationPrincipal Jwt principal) {
this.adminApiService.setAdmin(userId, principal.getTokenValue());
}
@GetMapping("/admin/validate_user_account/{userId}")
public void validateEntrepreneurAcc(
@PathVariable long userId, @AuthenticationPrincipal Jwt principal) {
this.adminApiService.validateEntrepreneurAccount(userId, principal.getTokenValue());
}
@GetMapping("/admin/get_pending_accounts")
public Iterable<User> validateEntrepreneurAcc() {
return this.adminApiService.getPendingUsers();
}
}