From aaa6e46d0c92a6ac52d11eae323f316e8dc166fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Sun, 6 Apr 2025 19:22:18 +0200 Subject: [PATCH] fix (kinda) : refactored update of data, still trying to fix bug from EntrepreneurApiServiceTests (code is a bit messy with prints and comments dw) --- .../java/enseirb/myinpulse/model/Project.java | 15 ++--- .../myinpulse/repository/UserRepository.java | 2 +- .../myinpulse/service/AdminApiService.java | 3 +- .../service/EntrepreneurApiService.java | 4 +- .../myinpulse/service/UtilsService.java | 2 +- .../database/AdministratorService.java | 46 ++++++++++++++ .../service/database/AnnotationService.java | 6 ++ .../service/database/AppointmentService.java | 43 ++++++++++++- .../service/database/EntrepreneurService.java | 60 ++++++++++++++++++- .../service/database/ProjectService.java | 57 ++++++++++++++---- .../service/database/ReportService.java | 18 +++++- .../service/database/SectionCellService.java | 49 ++++++++++++++- .../service/database/UserService.java | 39 ++++++++++++ .../myinpulse/EntrepreneurApiServiceTest.java | 42 +++++-------- 14 files changed, 327 insertions(+), 59 deletions(-) diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java index e4085b8..0a23118 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/Project.java @@ -5,7 +5,6 @@ import jakarta.persistence.*; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; -import java.util.Objects; @Entity @Table(name = "project") @@ -69,17 +68,11 @@ public class Project { @Override public boolean equals(Object o) { - if (o == null || getClass() != o.getClass()) return false; + if (o == this) { + return true; + } Project project = (Project) o; - return Objects.equals(listEntrepreneurParticipation, project.listEntrepreneurParticipation) - && Objects.equals(listSectionCell, project.listSectionCell) - && Objects.equals(idProject, project.idProject) - && Objects.equals(projectName, project.projectName) - && Objects.deepEquals(logo, project.logo) - && Objects.equals(creationDate, project.creationDate) - && projectStatus == project.projectStatus - && Objects.equals(projectAdministrator, project.projectAdministrator) - && Objects.equals(entrepreneurProposed, project.entrepreneurProposed); + return this.idProject == project.idProject; } public Long getIdProject() { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java index 291a97d..687248c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/UserRepository.java @@ -9,7 +9,7 @@ import java.util.Optional; @RepositoryRestResource public interface UserRepository extends JpaRepository { - Optional findByPrimaryMail(String email); + Optional findByPrimaryMail(String primaryMail); /* @Query("SELECT u from User u") User findAllUser(); */ diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java index 4fd1ccc..bd05a2c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/AdminApiService.java @@ -97,8 +97,9 @@ public class AdminApiService { decision.projectId, null, null, - null, (decision.isAccepted == 1) ? ACTIVE : REJECTED, + null, + null, this.administratorService.getAdministratorById(decision.adminId)); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java index 10479c3..3bb8a8b 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -55,7 +55,7 @@ public class EntrepreneurApiService { mail, sectionCellId, this.sectionCellService.getProjectId(sectionCellId)); - sectionCellService.updateSectionCell(sectionCellId, content); + sectionCellService.updateSectionCell(sectionCellId, content, null, null, null); } public void removeSectionCell(Long sectionCellId, String mail) { @@ -71,7 +71,7 @@ public class EntrepreneurApiService { "User {} tried to remove section cells {} of the project {} but is not allowed to.", mail, sectionCellId, - this.sectionCellService.getSectionCellById(sectionCellId)); + this.sectionCellService.getProjectId(sectionCellId)); throw new ResponseStatusException( HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java index a49e82e..df20142 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/UtilsService.java @@ -45,7 +45,7 @@ public class UtilsService { User user = this.userService.getUserByEmail(mail); Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); Project project = this.projectService.getProjectById(projectId); - return entrepreneur.getProjectParticipation() == project; + return entrepreneur.getProjectParticipation().equals(project); } // TODO: test diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java index b3d91bc..9a027e2 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AdministratorService.java @@ -1,6 +1,9 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Administrator; +import enseirb.myinpulse.model.Annotation; +import enseirb.myinpulse.model.MakeAppointment; +import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.AdministratorRepository; import org.apache.logging.log4j.LogManager; @@ -52,6 +55,49 @@ public class AdministratorService { return this.administratorRepository.save(administrator); } + public void updateAdministratorListProject(long idAdministrator, Project project) { + Administrator administrator = getAdministratorById(idAdministrator); + administrator.updateListProject(project); + this.administratorRepository.save(administrator); + } + + public void updateAdministratorListAnnotation(long idAdministrator, Annotation annotation) { + Administrator administrator = getAdministratorById(idAdministrator); + administrator.updateListAnnotation(annotation); + this.administratorRepository.save(administrator); + } + + public void updateAdministratorMakeAppointment( + long idAdministrator, MakeAppointment makeAppointment) { + Administrator administrator = getAdministratorById(idAdministrator); + administrator.setMakeAppointment(makeAppointment); + this.administratorRepository.save(administrator); + } + + public Administrator updateAdministrator( + Long idAdministrator, + Project project, + Annotation annotation, + MakeAppointment makeAppointment) { + Optional administrator = administratorRepository.findById(idAdministrator); + if (administrator.isEmpty()) { + logger.error( + "updateAdministrator : No administrator found with id {}", idAdministrator); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cet administrateur n'existe pas"); + } + if (project != null) { + administrator.get().updateListProject(project); + } + if (annotation != null) { + administrator.get().updateListAnnotation(annotation); + } + if (makeAppointment != null) { + administrator.get().setMakeAppointment(makeAppointment); + } + return this.administratorRepository.save(administrator.get()); + } + /* public Administrator getAdministratorByProject(Project project) { r diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java index 577cf9b..88c119e 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AnnotationService.java @@ -46,6 +46,12 @@ public class AnnotationService { this.annotationRepository.deleteById(id); } + public void updateAnnotationComment(long idAnnotation, String comment) { + Annotation annotation = getAnnotationById(idAnnotation); + annotation.setComment(comment); + this.annotationRepository.save(annotation); + } + public Annotation updateAnnotation(Long id, String comment) { Optional annotation = annotationRepository.findById(id); if (annotation.isEmpty()) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java index 7ba0ff5..2bd3bc3 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Appointment; +import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.repository.AppointmentRepository; import org.apache.logging.log4j.LogManager; @@ -47,13 +48,50 @@ public class AppointmentService { this.appointmentRepository.deleteById(id); } + public void updateAppointmentDate(long idAppointment, LocalDate date) { + Appointment appointment = getAppointmentById(idAppointment); + appointment.setAppointmentDate(date); + this.appointmentRepository.save(appointment); + } + + public void updateAppointmentTime(long idAppointment, LocalTime time) { + Appointment appointment = getAppointmentById(idAppointment); + appointment.setAppointmentTime(time); + this.appointmentRepository.save(appointment); + } + + public void updateAppointmentDuration(long idAppointment, LocalTime duration) { + Appointment appointment = getAppointmentById(idAppointment); + appointment.setAppointmentDuration(duration); + this.appointmentRepository.save(appointment); + } + + public void updateAppointmentPlace(long idAppointment, String place) { + Appointment appointment = getAppointmentById(idAppointment); + appointment.setAppointmentPlace(place); + this.appointmentRepository.save(appointment); + } + + public void updateAppointmentSubject(long idAppointment, String subject) { + Appointment appointment = getAppointmentById(idAppointment); + appointment.setAppointmentSubject(subject); + this.appointmentRepository.save(appointment); + } + + public void updateAppointmentListSectionCell(long idAppointment, SectionCell sectionCell) { + Appointment appointment = getAppointmentById(idAppointment); + appointment.updateListSectionCell(sectionCell); + this.appointmentRepository.save(appointment); + } + public Appointment updateAppointment( Long id, LocalDate appointmentDate, LocalTime appointmentTime, LocalTime appointmentDuration, String appointmentPlace, - String appointmentSubject) { + String appointmentSubject, + SectionCell sectionCell) { Optional appointment = this.appointmentRepository.findById(id); if (appointment.isEmpty()) { logger.error("updateAppointment : No appointment found with id {}", id); @@ -74,6 +112,9 @@ public class AppointmentService { if (appointmentSubject != null) { appointment.get().setAppointmentSubject(appointmentSubject); } + if (sectionCell != null) { + appointment.get().updateListSectionCell(sectionCell); + } return this.appointmentRepository.save(appointment.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java index f24878f..11cab5c 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/EntrepreneurService.java @@ -1,6 +1,7 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Entrepreneur; +import enseirb.myinpulse.model.MakeAppointment; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.EntrepreneurRepository; @@ -41,8 +42,56 @@ public class EntrepreneurService { return this.entrepreneurRepository.save(entrepreneur); } + public void updateEntrepreneurSchool(long idEntrepreneur, String school) { + Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur); + entrepreneur.setSchool(school); + this.entrepreneurRepository.save(entrepreneur); + } + + public void updateEntrepreneurCourse(long idEntrepreneur, String course) { + Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur); + entrepreneur.setCourse(course); + this.entrepreneurRepository.save(entrepreneur); + } + + public void updateEntrepreneurSneeStatus(long idEntrepreneur, boolean status) { + Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur); + entrepreneur.setSneeStatus(status); + this.entrepreneurRepository.save(entrepreneur); + } + + public void updateEntrepreneurProjectParticipation( + long idEntrepreneur, Project projectParticipation) { + System.out.println("expected"); + System.out.println(getEntrepreneurById(idEntrepreneur)); + Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur); + System.out.println("test"); + System.out.println(entrepreneur); + entrepreneur.setProjectParticipation(projectParticipation); + this.entrepreneurRepository.save(entrepreneur); + } + + public void updateEntrepreneurProjectProposed(long idEntrepreneur, Project projectProposed) { + Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur); + entrepreneur.setProjectParticipation(projectProposed); + this.entrepreneurRepository.save(entrepreneur); + } + + public void updateEntrepreneurMakeAppointment( + long idEntrepreneur, MakeAppointment makeAppointment) { + Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur); + entrepreneur.setMakeAppointment(makeAppointment); + this.entrepreneurRepository.save(entrepreneur); + } + public Entrepreneur updateEntrepreneur( - Long id, String school, String course, Boolean sneeStatus) { + Long id, + String school, + String course, + Boolean sneeStatus, + Project projectParticipation, + Project projectProposed, + MakeAppointment makeAppointment) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { logger.error("updateEntrepreneur : No entrepreneur found with id {}", id); @@ -58,6 +107,15 @@ public class EntrepreneurService { if (sneeStatus != null) { entrepreneur.get().setSneeStatus(sneeStatus); } + if (projectParticipation != null) { + entrepreneur.get().setProjectParticipation(projectParticipation); + } + if (projectProposed != null) { + entrepreneur.get().setProjectParticipation(projectProposed); + } + if (makeAppointment != null) { + entrepreneur.get().setMakeAppointment(makeAppointment); + } return this.entrepreneurRepository.save(entrepreneur.get()); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java index 7eb0651..ddf6c96 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ProjectService.java @@ -2,9 +2,7 @@ package enseirb.myinpulse.service.database; import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING; -import enseirb.myinpulse.model.Administrator; -import enseirb.myinpulse.model.Project; -import enseirb.myinpulse.model.ProjectDecisionValue; +import enseirb.myinpulse.model.*; import enseirb.myinpulse.repository.ProjectRepository; import org.apache.logging.log4j.LogManager; @@ -14,7 +12,6 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; -import java.time.LocalDate; import java.util.List; import java.util.Optional; @@ -52,12 +49,50 @@ public class ProjectService { return this.projectRepository.save(project); } + public void updateProjectName(long idProject, String name) { + Project project = getProjectById(idProject); + project.setProjectName(name); + this.projectRepository.save(project); + } + + public void updateProjectLogo(long idProject, byte[] logo) { + Project project = getProjectById(idProject); + project.setLogo(logo); + this.projectRepository.save(project); + } + + public void updateProjectStatus(long idProject, ProjectDecisionValue status) { + Project project = getProjectById(idProject); + project.setProjectStatus(status); + this.projectRepository.save(project); + } + + public void updateProjectEntrepreneurParticipation( + long idProject, Entrepreneur entrepreneurParticipation) { + Project project = getProjectById(idProject); + project.updateListEntrepreneurParticipation(entrepreneurParticipation); + this.projectRepository.save(project); + } + + public void updateProjectListSectionCell(long idProject, SectionCell sectionCell) { + Project project = getProjectById(idProject); + project.updateListSectionCell(sectionCell); + this.projectRepository.save(project); + } + + public void updateProjectAdministrator(long idProject, Administrator administrator) { + Project project = getProjectById(idProject); + project.setProjectAdministrator(administrator); + this.projectRepository.save(project); + } + public Project updateProject( Long id, String projectName, byte[] logo, - LocalDate creationDate, ProjectDecisionValue projectStatus, + Entrepreneur entrepreneurParticipation, + SectionCell sectionCell, Administrator administrator) { Optional project = this.projectRepository.findById(id); @@ -73,11 +108,6 @@ public class ProjectService { if (logo != null) { project.get().setLogo(logo); } - - if (creationDate != null) { - project.get().setCreationDate(creationDate); - } - if (projectStatus != null) { // TODO: check if this is really useful /* @@ -89,7 +119,12 @@ public class ProjectService { */ project.get().setProjectStatus(projectStatus); } - + if (entrepreneurParticipation != null) { + project.get().updateListEntrepreneurParticipation(entrepreneurParticipation); + } + if (sectionCell != null) { + project.get().updateListSectionCell(sectionCell); + } if (administrator != null) { project.get().setProjectAdministrator(administrator); } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java index 2a8d273..f057aa7 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/ReportService.java @@ -1,5 +1,6 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.Appointment; import enseirb.myinpulse.model.Report; import enseirb.myinpulse.repository.ReportRepository; @@ -46,7 +47,19 @@ public class ReportService { this.reportRepository.deleteById(id); } - public Report updateReport(Long id, String reportContent) { + public void updateReportContent(long idReport, String content) { + Report report = getReportById(idReport); + report.setReportContent(content); + this.reportRepository.save(report); + } + + public void updateReportAppointment(long idReport, Appointment appointment) { + Report report = getReportById(idReport); + report.setAppointmentReport(appointment); + this.reportRepository.save(report); + } + + public Report updateReport(Long id, String reportContent, Appointment appointment) { Optional report = this.reportRepository.findById(id); if (report.isEmpty()) { logger.error("updateReport : No report found with id {}", id); @@ -55,6 +68,9 @@ public class ReportService { if (reportContent != null) { report.get().setReportContent(reportContent); } + if (appointment != null) { + report.get().setAppointmentReport(appointment); + } return this.reportRepository.save(report.get()); } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java index 9ef84fd..71f90c2 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/SectionCellService.java @@ -1,5 +1,6 @@ package enseirb.myinpulse.service.database; +import enseirb.myinpulse.model.Annotation; import enseirb.myinpulse.model.Appointment; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; @@ -50,7 +51,36 @@ public class SectionCellService { this.sectionCellRepository.deleteById(id); } - public SectionCell updateSectionCell(Long id, String contentSectionCell) { + public void updateSectionCellContent(long idSectionCell, String content) { + SectionCell sectionCell = getSectionCellById(idSectionCell); + sectionCell.setContentSectionCell(content); + this.sectionCellRepository.save(sectionCell); + } + + public void updateSectionCellListAppointment(long idSectionCell, Appointment appointment) { + SectionCell sectionCell = getSectionCellById(idSectionCell); + sectionCell.updateAppointmentSectionCell(appointment); + this.sectionCellRepository.save(sectionCell); + } + + public void updateSectionCellListAnnotation(long idSectionCell, Annotation annotation) { + SectionCell sectionCell = getSectionCellById(idSectionCell); + sectionCell.updateListAnnotation(annotation); + this.sectionCellRepository.save(sectionCell); + } + + public void updateSectionCellProject(long idSectionCell, Project project) { + SectionCell sectionCell = getSectionCellById(idSectionCell); + sectionCell.setProjectSectionCell(project); + this.sectionCellRepository.save(sectionCell); + } + + public SectionCell updateSectionCell( + Long id, + String contentSectionCell, + Appointment appointment, + Annotation annotation, + Project project) { Optional sectionCell = this.sectionCellRepository.findById(id); if (sectionCell.isEmpty()) { logger.error("updateSectionCell : No sectionCell found with id {}", id); @@ -61,11 +91,24 @@ public class SectionCellService { sectionCell.get().setContentSectionCell(contentSectionCell); sectionCell.get().setModificationDate(LocalDateTime.now()); } + if (appointment != null) { + sectionCell.get().updateAppointmentSectionCell(appointment); + sectionCell.get().setModificationDate(LocalDateTime.now()); + } + if (annotation != null) { + sectionCell.get().updateListAnnotation(annotation); + sectionCell.get().setModificationDate(LocalDateTime.now()); + } + if (project != null) { + sectionCell.get().setProjectSectionCell(project); + sectionCell.get().setModificationDate(LocalDateTime.now()); + } return this.sectionCellRepository.save(sectionCell.get()); } - public Iterable getSectionCellsByProject(Project project, Long sectionId) { - return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId); + public Iterable getSectionCellsByProject(Project project, Long idSectionCell) { + return this.sectionCellRepository.findByProjectSectionCellAndSectionId( + project, idSectionCell); } public Long getProjectId(Long sectionCellId) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java index 45a4eac..567c519 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/UserService.java @@ -30,6 +30,15 @@ public class UserService { return this.userRepository.findAll(); } + public User getUserById(long id) { + Optional user = this.userRepository.findById(id); + if (user.isEmpty()) { + logger.error("getUserById : No user found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); + } + return user.get(); + } + // TODO public User getUserByEmail(String email) { Optional opt_user = this.userRepository.findByPrimaryMail(email); @@ -49,6 +58,36 @@ public class UserService { return this.userRepository.save(user); } + public void updateUserSurname(long idUser, String surname) { + User user = getUserById(idUser); + user.setUserSurname(surname); + this.userRepository.save(user); + } + + public void updateUserName(long idUser, String name) { + User user = getUserById(idUser); + user.setUserName(name); + this.userRepository.save(user); + } + + public void updateUserPrimaryMail(long idUser, String primaryMail) { + User user = getUserById(idUser); + user.setPrimaryMail(primaryMail); + this.userRepository.save(user); + } + + public void updateUserSecondaryMail(long idUser, String secondaryMail) { + User user = getUserById(idUser); + user.setSecondaryMail(secondaryMail); + this.userRepository.save(user); + } + + public void updateUserPhoneNumber(long idUser, String phoneNumber) { + User user = getUserById(idUser); + user.setPhoneNumber(phoneNumber); + this.userRepository.save(user); + } + public User updateUser( @PathVariable Long id, String userSurname, diff --git a/MyINPulse-back/src/test/java/enseirb/myinpulse/EntrepreneurApiServiceTest.java b/MyINPulse-back/src/test/java/enseirb/myinpulse/EntrepreneurApiServiceTest.java index 53ce8e3..5e32371 100644 --- a/MyINPulse-back/src/test/java/enseirb/myinpulse/EntrepreneurApiServiceTest.java +++ b/MyINPulse-back/src/test/java/enseirb/myinpulse/EntrepreneurApiServiceTest.java @@ -28,6 +28,7 @@ import java.util.List; @Transactional public class EntrepreneurApiServiceTest { private static Entrepreneur entrepreneur; + private static Project project; private static Iterable sectionCells; @Autowired private EntrepreneurApiService entrepreneurApiService; @Autowired private EntrepreneurService entrepreneurService; @@ -60,20 +61,22 @@ public class EntrepreneurApiServiceTest { "ENSEGID", "", true)); - Project project = + project = projectService.addNewProject( new Project("Project", null, LocalDate.now(), ACTIVE, null, entrepreneur)); - entrepreneur.setProjectParticipation(project); + // projectService.updateProjectEntrepreneurParticipation(project.getIdProject(), + // entrepreneur); proxy error because why not + entrepreneurService.updateEntrepreneurProjectProposed(entrepreneur.getIdUser(), project); + entrepreneurService.updateEntrepreneurProjectParticipation( + entrepreneur.getIdUser(), project); + System.out.println(("real")); + System.out.println(entrepreneur); + // System.out.println(entrepreneur.getProjectProposed()); + // System.out.println(entrepreneur.getProjectParticipation()); sectionCellService.addNewSectionCell( new SectionCell( - null, - 2L, - "contenu très intéressant", - LocalDateTime.now(), - projectService.getProjectByName("Project"))); - sectionCells = - sectionCellService.getSectionCellsByProject( - projectService.getProjectByName("Project"), 2L); + null, 2L, "contenu très intéressant", LocalDateTime.now(), project)); + sectionCells = sectionCellService.getSectionCellsByProject(project, 2L); } private List IterableToList(Iterable iterable) { @@ -84,7 +87,6 @@ public class EntrepreneurApiServiceTest { @Test void editValidSectionCell() { - System.out.println(sectionCells); entrepreneurApiService.editSectionCell( IterableToList(sectionCells).getFirst().getIdSectionCell(), "modified content", @@ -122,25 +124,13 @@ public class EntrepreneurApiServiceTest { SectionCell tmpCell = sectionCellService.addNewSectionCell( new SectionCell( - null, - 2L, - "contenu temporaire", - LocalDateTime.now(), - projectService.getProjectByName("Project"))); + null, 2L, "contenu temporaire", LocalDateTime.now(), project)); assertEquals( - 2, - IterableToList( - sectionCellService.getSectionCellsByProject( - projectService.getProjectByName("Project"), 2L)) - .size()); + 2, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size()); entrepreneurApiService.removeSectionCell( tmpCell.getIdSectionCell(), "entrepreneur@mail.fr"); assertEquals( - 1, - IterableToList( - sectionCellService.getSectionCellsByProject( - projectService.getProjectByName("Project"), 2L)) - .size()); + 1, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size()); } @Test