feat: finsihed tests for EntrepreneurApiService
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 40s
CI / build (push) Successful in 13s

This commit is contained in:
Théo Le Lez
2025-04-23 11:54:18 +02:00
parent e7739af80b
commit bee47473d5
3 changed files with 175 additions and 33 deletions

View File

@ -5,10 +5,7 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING;
import enseirb.myinpulse.model.Entrepreneur;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.SectionCellService;
import enseirb.myinpulse.service.database.UserService;
import enseirb.myinpulse.service.database.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -29,6 +26,9 @@ public class EntrepreneurApiService {
private final UtilsService utilsService;
private final UserService userService;
private final EntrepreneurService entrepreneurService;
private final AdministratorService administratorService;
private final AppointmentService appointmentService;
private final AnnotationService annotationService;
@Autowired
EntrepreneurApiService(
@ -36,21 +36,27 @@ public class EntrepreneurApiService {
ProjectService projectService,
UtilsService utilsService,
UserService userService,
EntrepreneurService entrepreneurService) {
EntrepreneurService entrepreneurService,
AdministratorService administratorService,
AppointmentService appointmentService,
AnnotationService annotationService) {
this.sectionCellService = sectionCellService;
this.projectService = projectService;
this.utilsService = utilsService;
this.userService = userService;
this.entrepreneurService = entrepreneurService;
this.administratorService = administratorService;
this.appointmentService = appointmentService;
this.annotationService = annotationService;
}
public void editSectionCell(Long sectionCellId, String content, String mail) {
SectionCell sectionCell = sectionCellService.getSectionCellById(sectionCellId);
if (sectionCell == null) {
System.err.println("Trying to edit unknown section cell");
if (sectionCellId == null) {
logger.warn("Trying to edit unknown section cell");
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
SectionCell sectionCell = sectionCellService.getSectionCellById(sectionCellId);
if (!utilsService.isAllowedToCheckProject(
mail, this.sectionCellService.getProjectId(sectionCellId))) {
logger.warn(
@ -74,29 +80,30 @@ public class EntrepreneurApiService {
LocalDateTime.now(),
sectionCell.getProjectSectionCell());
newSectionCell.setIdReference(sectionCell.getIdReference());
this.addSectionCell(newSectionCell, mail);
sectionCell
.getAppointmentSectionCell()
.forEach(
appointment -> {
newSectionCell.updateAppointmentSectionCell(appointment);
this.appointmentService.updateAppointmentListSectionCell(
appointment.getIdAppointment(), newSectionCell);
});
sectionCell
.getListAnnotation()
.forEach(
annotation -> {
newSectionCell.updateListAnnotation(annotation);
this.annotationService.updateAnnotationSectionCell(
annotation.getIdAnnotation(), newSectionCell);
});
this.addSectionCell(newSectionCell, mail);
// sectionCellService.updateSectionCell(sectionCellId, content, null, null, null);
}
public void removeSectionCell(Long sectionCellId, String mail) {
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
if (editSectionCell == null) {
System.err.println("Trying to remove unknown section cell");
if (sectionCellId == null) {
logger.warn("Trying to remove unknown section cell");
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
if (!utilsService.isAllowedToCheckProject(
mail, this.sectionCellService.getProjectId(sectionCellId))) {
logger.warn(
@ -130,12 +137,12 @@ public class EntrepreneurApiService {
public void addSectionCell(SectionCell sectionCell, String mail) {
if (sectionCell == null) {
System.err.println("Trying to create an empty section cell");
logger.warn("Trying to create an empty section cell");
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
}
if (sectionCell.getSectionId() == -1) {
System.err.println("Trying to create an illegal section cell");
logger.warn("Trying to create an illegal section cell");
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST, "La cellule de section fournie n'est pas valide");
}
@ -161,28 +168,35 @@ public class EntrepreneurApiService {
.getAppointmentSectionCell()
.forEach(
appointment -> {
appointment.updateListSectionCell(newSectionCell);
this.appointmentService.updateAppointmentListSectionCell(
appointment.getIdAppointment(), newSectionCell);
});
newSectionCell
.getListAnnotation()
.forEach(
annotation -> {
annotation.setSectionCellAnnotation(newSectionCell);
this.annotationService.updateAnnotationSectionCell(
annotation.getIdAnnotation(), newSectionCell);
});
}
public void requestNewProject(Project project, String mail) {
if (project == null) {
logger.error("Trying to request the creation of a null project");
logger.warn("Trying to request the creation of a null project");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide");
}
logger.info("User {} created a new project with id {}", mail, project.getIdProject());
project.setProjectStatus(PENDING);
logger.info("User {} created a new project named {}", mail, project.getProjectName());
project.setEntrepreneurProposed((Entrepreneur) this.userService.getUserByEmail(mail));
projectService.addNewProject(project);
project.getProjectAdministrator().updateListProject(project);
this.projectService.updateProjectStatus(project.getIdProject(), PENDING);
if (project.getProjectAdministrator() != null) {
this.administratorService.updateAdministratorListProject(
project.getProjectAdministrator().getIdUser(), project);
}
this.entrepreneurService.updateEntrepreneurProjectProposed(
this.userService.getUserByEmail(mail).getIdUser(), project);
this.entrepreneurService.updateEntrepreneurProjectParticipation(
this.userService.getUserByEmail(mail).getIdUser(), project);
project.getListEntrepreneurParticipation()
.forEach(
entrepreneur ->

View File

@ -1,6 +1,8 @@
package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Administrator;
import enseirb.myinpulse.model.Annotation;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.repository.AnnotationRepository;
import org.apache.logging.log4j.LogManager;
@ -64,4 +66,16 @@ public class AnnotationService {
}
return this.annotationRepository.save(annotation.get());
}
public void updateAnnotationSectionCell(long idAnnotation, SectionCell sectionCell) {
Annotation annotation = getAnnotationById(idAnnotation);
annotation.setSectionCellAnnotation(sectionCell);
this.annotationRepository.save(annotation);
}
public void updateAnnotationAdministrator(long idAnnotation, Administrator administrator) {
Annotation annotation = getAnnotationById(idAnnotation);
annotation.setAdministratorAnnotation(administrator);
this.annotationRepository.save(annotation);
}
}