backend-api #6
| @@ -17,8 +17,8 @@ public class Appointment { | ||||
|             new ArrayList<>(); */ | ||||
|     // should now be useless | ||||
|  | ||||
|     @OneToMany(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) | ||||
|     private final List<Report> listReport = new ArrayList<>(); | ||||
|     @OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true) | ||||
|     private Report report; | ||||
|  | ||||
|     @ManyToMany( | ||||
|             fetch = FetchType.LAZY, | ||||
| @@ -109,4 +109,12 @@ public class Appointment { | ||||
|     public void setAppointmentSubject(String appointmentSubject) { | ||||
|         this.appointmentSubject = appointmentSubject; | ||||
|     } | ||||
|  | ||||
|     public List<SectionCell> getAppointmentListSectionCell() { | ||||
|         return listSectionCell; | ||||
|     } | ||||
|  | ||||
|     public Report getAppointmentReport() { | ||||
|         return report; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -17,7 +17,7 @@ public class Report { | ||||
|  | ||||
|     private String reportContent; | ||||
|  | ||||
|     @ManyToOne(fetch = FetchType.LAZY) | ||||
|     @OneToOne(fetch = FetchType.LAZY) | ||||
|     @JoinColumn(name = "idAppointment") | ||||
|     private Appointment appointmentReport; | ||||
|  | ||||
| @@ -28,6 +28,10 @@ public class Report { | ||||
|         this.reportContent = reportContent; | ||||
|     } | ||||
|  | ||||
|     public Long getIdReport() { | ||||
|         return idReport; | ||||
|     } | ||||
|  | ||||
|     public String getReportContent() { | ||||
|         return reportContent; | ||||
|     } | ||||
|   | ||||
| @@ -83,4 +83,8 @@ public class SectionCell { | ||||
|     public Project getProjectSectionCell() { | ||||
|         return projectSectionCell; | ||||
|     } | ||||
|  | ||||
|     public List<Appointment> getAppointmentSectionCell() { | ||||
|         return appointment; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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"); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package enseirb.myinpulse.service.database; | ||||
|  | ||||
| import enseirb.myinpulse.model.Appointment; | ||||
| import enseirb.myinpulse.model.Project; | ||||
| import enseirb.myinpulse.model.SectionCell; | ||||
| import enseirb.myinpulse.repository.SectionCellRepository; | ||||
| @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; | ||||
| import org.springframework.web.server.ResponseStatusException; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
|  | ||||
| @Service | ||||
| @@ -77,4 +79,9 @@ public class SectionCellService { | ||||
|         Project sectionProject = sectionCell.getProjectSectionCell(); | ||||
|         return sectionProject.getIdProject(); | ||||
|     } | ||||
|  | ||||
|     public List<Appointment> getAppointmentsBySectionCellId(Long sectionCellId) { | ||||
|         SectionCell sectionCell = getSectionCellById(sectionCellId); | ||||
|         return sectionCell.getAppointmentSectionCell(); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user