feat: finished implementing apiService functions

This commit is contained in:
Théo Le Lez
2025-03-19 12:05:56 +01:00
parent c94d3654ce
commit 3c61fdca93
3 changed files with 67 additions and 16 deletions

View File

@ -4,11 +4,7 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.AdministratorService;
import enseirb.myinpulse.service.database.AppointmentService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.ReportService;
import enseirb.myinpulse.service.database.UserService;
import enseirb.myinpulse.service.database.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -17,6 +13,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.util.ArrayList;
import java.util.List;
@Service
public class AdminApiService {
@ -28,6 +27,7 @@ public class AdminApiService {
private final UtilsService utilsService;
private final AppointmentService appointmentService;
private final ReportService reportService;
private final SectionCellService sectionCellService;
@Autowired
AdminApiService(
@ -36,13 +36,15 @@ public class AdminApiService {
AdministratorService administratorService,
UtilsService utilsService,
AppointmentService appointmentService,
ReportService reportService) {
ReportService reportService,
SectionCellService sectionCellService) {
this.projectService = projectService;
this.userService = userService;
this.administratorService = administratorService;
this.utilsService = utilsService;
this.appointmentService = appointmentService;
this.reportService = reportService;
this.sectionCellService = sectionCellService;
}
// TODO: check if tests are sufficient - peer verification required
@ -52,10 +54,36 @@ public class AdminApiService {
this.userService.getUserByEmail(mail).getIdUser()));
}
// TODO
public Iterable<Appointment> getUpcomingAppointments(String mail) {
logger.info("User {} check their upcoming appointments", mail);
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
User user = this.userService.getUserByEmail(mail);
List<Appointment> appointments = new ArrayList<>();
if (user instanceof Administrator) {
List<Project> projects = new ArrayList<>(((Administrator) user).getListProject());
projects.forEach(
project -> {
project.getListSectionCell()
.forEach(
sectionCell -> {
appointments.addAll(
this.sectionCellService
.getAppointmentsBySectionCellId(
sectionCell
.getIdSectionCell()));
});
});
}
if (user instanceof Entrepreneur) {
Project project = ((Entrepreneur) user).getProjectParticipation();
project.getListSectionCell()
.forEach(
sectionCell -> {
appointments.addAll(
this.sectionCellService.getAppointmentsBySectionCellId(
sectionCell.getIdSectionCell()));
});
}
return appointments;
}
// TODO: check if tests are sufficient - peer verification required