feat: continued to implement SharedApiService (if linter fails i don't understand)
Some checks failed
Format / formatting (push) Failing after 6s
CI / build (push) Successful in 11s

This commit is contained in:
Théo Le Lez
2025-02-26 18:33:09 +01:00
parent f9de5ed6bf
commit 1d970ce5f5
5 changed files with 82 additions and 7 deletions

View File

@ -10,6 +10,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 SharedApiService {
@ -20,6 +23,7 @@ public class SharedApiService {
private final ProjectService projectService;
private final EntrepreneurService entrepreneurService;
private final SectionCellService sectionCellService;
private final AppointmentService appointmentService;
@Autowired
SharedApiService(
@ -27,12 +31,14 @@ public class SharedApiService {
UserService userService,
ProjectService projectService,
EntrepreneurService entrepreneurService,
SectionCellService sectionCellService) {
SectionCellService sectionCellService,
AppointmentService appointmentService) {
this.administratorService = administratorService;
this.userService = userService;
this.projectService = projectService;
this.entrepreneurService = entrepreneurService;
this.sectionCellService = sectionCellService;
this.appointmentService = appointmentService;
}
// TODO: test
@ -103,12 +109,58 @@ public class SharedApiService {
}
// TODO
public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
public Iterable<Appointment> getAppointmentsByProjectId(long projectId, String mail) {
if (!isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to check the appointments related to the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info(
"User {} tried to check the appointments related to the project {}",
mail,
projectId);
Iterable<SectionCell> sectionCells =
this.sectionCellService.getSectionCellsByProject(
projectService.getProjectById(projectId),
2L); // sectionId useless in this function ?
List<Appointment> appointments = new ArrayList<Appointment>();
sectionCells.forEach(
sectionCell -> {
appointments.addAll(
this.sectionCellService.getAppointmentsBySectionCellId(
sectionCell.getIdSectionCell()));
});
return appointments;
}
// TODO
public void getPDFReport(int appointmentId, String mail) {
public void getPDFReport(long appointmentId, String mail) {
long projectId =
this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentListSectionCell()
.getFirst()
.getProjectSectionCell()
.getIdProject();
if (!isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to generate the PDF report {} related to the appointment {} but is not allowed to.",
mail,
this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentReport()
.getIdReport(),
appointmentId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
/* return this.appointmentService
.getAppointmentById(appointmentId)
.getAppointmentReport().getReportContent(); */
// generate pdf from this string, and format it to be decent looking
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
}