fix: updating foreign keys when adding new entity to the db
All checks were successful
Format / formatting (push) Successful in 7s
Build / build (push) Successful in 31s
CI / build (push) Successful in 11s

This commit is contained in:
Théo Le Lez
2025-03-15 15:23:18 +01:00
parent d5c89bf8f4
commit c94d3654ce
10 changed files with 206 additions and 18 deletions

View File

@ -5,14 +5,13 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.AdministratorService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.UserService;
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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@ -86,8 +85,22 @@ public class AdminApiService {
if (e.getStatusCode() == HttpStatus.CONFLICT) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
}
projectService.addNewProject(project);
}
Project newProject = projectService.addNewProject(project);
newProject.getProjectAdministrator().updateListProject(newProject);
newProject.getEntrepreneurProposed().setProjectProposed(newProject);
newProject
.getListEntrepreneurParticipation()
.forEach(
participation -> {
participation.setProjectParticipation(newProject);
});
newProject
.getListSectionCell()
.forEach(
sectionCell -> {
sectionCell.setProjectSectionCell(newProject);
});
}
public void createAppointmentReport(long appointmentId, Report report, String mail) {

View File

@ -107,7 +107,20 @@ public class EntrepreneurApiService {
mail,
sectionCell.getIdSectionCell(),
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
sectionCellService.addNewSectionCell(sectionCell);
SectionCell newSectionCell = sectionCellService.addNewSectionCell(sectionCell);
newSectionCell.getProjectSectionCell().updateListSectionCell(newSectionCell);
newSectionCell
.getAppointmentSectionCell()
.forEach(
appointment -> {
appointment.updateListSectionCell(newSectionCell);
});
newSectionCell
.getListAnnotation()
.forEach(
annotation -> {
annotation.setSectionCellAnnotation(newSectionCell);
});
}
public void requestNewProject(Project project, String mail) {

View File

@ -1,5 +1,8 @@
package enseirb.myinpulse.service;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.*;
@ -10,9 +13,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.time.LocalDateTime;
@ -92,7 +92,7 @@ public class SharedApiService {
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
Project project = this.projectService.getProjectById(projectId);
return project.getAdministrator();
return project.getProjectAdministrator();
}
// TODO
@ -221,6 +221,13 @@ public class SharedApiService {
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
logger.info("User {} tried to create an appointment for project {}", mail, projectId);
this.appointmentService.addNewAppointment(appointment);
Appointment newAppointment = this.appointmentService.addNewAppointment(appointment);
newAppointment
.getAppointmentListSectionCell()
.forEach(
sectionCell -> {
sectionCell.updateAppointmentSectionCell(newAppointment);
});
newAppointment.getAppointmentReport().setAppointmentReport(newAppointment);
}
}

View File

@ -91,7 +91,7 @@ public class ProjectService {
}
if (administrator != null) {
project.get().setAdministrator(administrator);
project.get().setProjectAdministrator(administrator);
}
return this.projectRepository.save(project.get());