feat: continued implementing adminApiService
This commit is contained in:
@ -4,6 +4,12 @@ import enseirb.myinpulse.model.*;
|
||||
import enseirb.myinpulse.service.database.AdministratorService;
|
||||
import enseirb.myinpulse.service.database.ProjectService;
|
||||
import enseirb.myinpulse.service.database.UserService;
|
||||
import enseirb.myinpulse.service.database.AppointmentService;
|
||||
import enseirb.myinpulse.service.database.ReportService;
|
||||
import enseirb.myinpulse.service.UtilsService;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -13,30 +19,41 @@ import org.springframework.web.server.ResponseStatusException;
|
||||
@Service
|
||||
public class AdminApiService {
|
||||
|
||||
protected static final Logger logger = LogManager.getLogger();
|
||||
|
||||
private final ProjectService projectService;
|
||||
private final UserService userService;
|
||||
private final AdministratorService administratorService;
|
||||
private final UtilsService utilsService;
|
||||
private final AppointmentService appointmentService;
|
||||
private final ReportService reportService;
|
||||
|
||||
@Autowired
|
||||
AdminApiService(
|
||||
ProjectService projectService,
|
||||
UserService userService,
|
||||
AdministratorService administratorService) {
|
||||
AdministratorService administratorService,
|
||||
UtilsService utilsService,
|
||||
AppointmentService appointmentService,
|
||||
ReportService reportService) {
|
||||
this.projectService = projectService;
|
||||
this.userService = userService;
|
||||
this.administratorService = administratorService;
|
||||
this.utilsService = utilsService;
|
||||
this.appointmentService = appointmentService;
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
public Iterable<Project> getProjectsOfAdmin(String email) {
|
||||
public Iterable<Project> getProjectsOfAdmin(String mail) {
|
||||
return projectService.getProjectsByAdminId(
|
||||
administratorService.getAdministratorById(
|
||||
this.userService.getUserByEmail(email).getIdUser()));
|
||||
this.userService.getUserByEmail(mail).getIdUser()));
|
||||
}
|
||||
|
||||
// TODO
|
||||
public Iterable<Appointment> getUpcomingAppointments(String email) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||
public Iterable<Appointment> getUpcomingAppointments(String mail) {
|
||||
logger.info("User {} check their upcoming appointments", mail);
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
@ -60,9 +77,26 @@ public class AdminApiService {
|
||||
projectService.addNewProject(project); // TODO: how can the front know the ID ?
|
||||
}
|
||||
|
||||
// TODO
|
||||
public void createAppointmentReport(String appointmentId, Report report, String email) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||
public void createAppointmentReport(long appointmentId, Report report, String mail) {
|
||||
long projectId =
|
||||
this.appointmentService
|
||||
.getAppointmentById(appointmentId)
|
||||
.getAppointmentListSectionCell()
|
||||
.getFirst()
|
||||
.getProjectSectionCell()
|
||||
.getIdProject();
|
||||
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||
logger.warn(
|
||||
"User {} tried to add an report for appointment {} but is not allowed to.",
|
||||
mail,
|
||||
projectId);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
|
||||
}
|
||||
logger.info("User {} added a report for appointment {}", mail, projectId);
|
||||
Report addedReport = this.reportService.addNewReport(report);
|
||||
addedReport.setAppointmentReport(this.appointmentService.getAppointmentById(appointmentId));
|
||||
this.appointmentService.getAppointmentById(appointmentId).setAppointmentReport(addedReport);
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
|
Reference in New Issue
Block a user