backend-api #6
@@ -17,8 +17,8 @@ public class Appointment {
 | 
				
			|||||||
            new ArrayList<>(); */
 | 
					            new ArrayList<>(); */
 | 
				
			||||||
    // should now be useless
 | 
					    // should now be useless
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @OneToMany(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true)
 | 
					    @OneToOne(mappedBy = "appointmentReport", fetch = FetchType.LAZY, orphanRemoval = true)
 | 
				
			||||||
    private final List<Report> listReport = new ArrayList<>();
 | 
					    private Report report;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @ManyToMany(
 | 
					    @ManyToMany(
 | 
				
			||||||
            fetch = FetchType.LAZY,
 | 
					            fetch = FetchType.LAZY,
 | 
				
			||||||
@@ -109,4 +109,12 @@ public class Appointment {
 | 
				
			|||||||
    public void setAppointmentSubject(String appointmentSubject) {
 | 
					    public void setAppointmentSubject(String appointmentSubject) {
 | 
				
			||||||
        this.appointmentSubject = 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;
 | 
					    private String reportContent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @ManyToOne(fetch = FetchType.LAZY)
 | 
					    @OneToOne(fetch = FetchType.LAZY)
 | 
				
			||||||
    @JoinColumn(name = "idAppointment")
 | 
					    @JoinColumn(name = "idAppointment")
 | 
				
			||||||
    private Appointment appointmentReport;
 | 
					    private Appointment appointmentReport;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -28,6 +28,10 @@ public class Report {
 | 
				
			|||||||
        this.reportContent = reportContent;
 | 
					        this.reportContent = reportContent;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Long getIdReport() {
 | 
				
			||||||
 | 
					        return idReport;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getReportContent() {
 | 
					    public String getReportContent() {
 | 
				
			||||||
        return reportContent;
 | 
					        return reportContent;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,4 +83,8 @@ public class SectionCell {
 | 
				
			|||||||
    public Project getProjectSectionCell() {
 | 
					    public Project getProjectSectionCell() {
 | 
				
			||||||
        return projectSectionCell;
 | 
					        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.stereotype.Service;
 | 
				
			||||||
import org.springframework.web.server.ResponseStatusException;
 | 
					import org.springframework.web.server.ResponseStatusException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
public class SharedApiService {
 | 
					public class SharedApiService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,6 +23,7 @@ public class SharedApiService {
 | 
				
			|||||||
    private final ProjectService projectService;
 | 
					    private final ProjectService projectService;
 | 
				
			||||||
    private final EntrepreneurService entrepreneurService;
 | 
					    private final EntrepreneurService entrepreneurService;
 | 
				
			||||||
    private final SectionCellService sectionCellService;
 | 
					    private final SectionCellService sectionCellService;
 | 
				
			||||||
 | 
					    private final AppointmentService appointmentService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    SharedApiService(
 | 
					    SharedApiService(
 | 
				
			||||||
@@ -27,12 +31,14 @@ public class SharedApiService {
 | 
				
			|||||||
            UserService userService,
 | 
					            UserService userService,
 | 
				
			||||||
            ProjectService projectService,
 | 
					            ProjectService projectService,
 | 
				
			||||||
            EntrepreneurService entrepreneurService,
 | 
					            EntrepreneurService entrepreneurService,
 | 
				
			||||||
            SectionCellService sectionCellService) {
 | 
					            SectionCellService sectionCellService,
 | 
				
			||||||
 | 
					            AppointmentService appointmentService) {
 | 
				
			||||||
        this.administratorService = administratorService;
 | 
					        this.administratorService = administratorService;
 | 
				
			||||||
        this.userService = userService;
 | 
					        this.userService = userService;
 | 
				
			||||||
        this.projectService = projectService;
 | 
					        this.projectService = projectService;
 | 
				
			||||||
        this.entrepreneurService = entrepreneurService;
 | 
					        this.entrepreneurService = entrepreneurService;
 | 
				
			||||||
        this.sectionCellService = sectionCellService;
 | 
					        this.sectionCellService = sectionCellService;
 | 
				
			||||||
 | 
					        this.appointmentService = appointmentService;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: test
 | 
					    // TODO: test
 | 
				
			||||||
@@ -103,12 +109,58 @@ public class SharedApiService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO
 | 
					    // TODO
 | 
				
			||||||
    public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) {
 | 
					    public Iterable<Appointment> getAppointmentsByProjectId(long projectId, String mail) {
 | 
				
			||||||
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
 | 
					        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
 | 
					    // 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");
 | 
					        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package enseirb.myinpulse.service.database;
 | 
					package enseirb.myinpulse.service.database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import enseirb.myinpulse.model.Appointment;
 | 
				
			||||||
import enseirb.myinpulse.model.Project;
 | 
					import enseirb.myinpulse.model.Project;
 | 
				
			||||||
import enseirb.myinpulse.model.SectionCell;
 | 
					import enseirb.myinpulse.model.SectionCell;
 | 
				
			||||||
import enseirb.myinpulse.repository.SectionCellRepository;
 | 
					import enseirb.myinpulse.repository.SectionCellRepository;
 | 
				
			||||||
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Service;
 | 
				
			|||||||
import org.springframework.web.server.ResponseStatusException;
 | 
					import org.springframework.web.server.ResponseStatusException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.time.LocalDateTime;
 | 
					import java.time.LocalDateTime;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Optional;
 | 
					import java.util.Optional;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
@@ -77,4 +79,9 @@ public class SectionCellService {
 | 
				
			|||||||
        Project sectionProject = sectionCell.getProjectSectionCell();
 | 
					        Project sectionProject = sectionCell.getProjectSectionCell();
 | 
				
			||||||
        return sectionProject.getIdProject();
 | 
					        return sectionProject.getIdProject();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<Appointment> getAppointmentsBySectionCellId(Long sectionCellId) {
 | 
				
			||||||
 | 
					        SectionCell sectionCell = getSectionCellById(sectionCellId);
 | 
				
			||||||
 | 
					        return sectionCell.getAppointmentSectionCell();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user