From f9de5ed6bfe5ee86cf0452d138a7873ab3c88a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Le=20Lez?= Date: Wed, 26 Feb 2025 17:35:52 +0100 Subject: [PATCH] feat: finished creating services from controllers, continued implementing entrepreneurServiceApi with some validation --- .../enseirb/myinpulse/model/SectionCell.java | 4 + .../repository/ReportRepository.java | 2 +- .../service/EntrepreneurApiService.java | 71 ++++++++- .../service/database/AnnotationService.java | 9 +- ...ontroller.java => AppointmentService.java} | 148 ++++++++++-------- .../service/database/EntrepreneurService.java | 7 +- .../service/database/ProjectService.java | 4 +- .../service/database/ReportService.java | 34 +++- .../service/database/SectionCellService.java | 12 ++ .../service/database/UserService.java | 10 +- .../ReportController.java | 43 ----- 11 files changed, 219 insertions(+), 125 deletions(-) rename MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/{old_controllers_to_convert_to_services/AppointmentController.java => AppointmentService.java} (64%) delete mode 100644 MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java index 9a03393..71f5940 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java @@ -79,4 +79,8 @@ public class SectionCell { public void setModificationDate(LocalDateTime modificationDate) { this.modificationDate = modificationDate; } + + public Project getProjectSectionCell() { + return projectSectionCell; + } } diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java index e228003..cc70746 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/ReportRepository.java @@ -6,4 +6,4 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource -public interface ReportRepository extends JpaRepository {} +public interface ReportRepository extends JpaRepository {} 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 95f0b79..4e04f88 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java @@ -1,10 +1,16 @@ package enseirb.myinpulse.service; +import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; +import enseirb.myinpulse.model.User; +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 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; @@ -13,13 +19,31 @@ import org.springframework.web.server.ResponseStatusException; @Service public class EntrepreneurApiService { + protected static final Logger logger = LogManager.getLogger(); + private final SectionCellService sectionCellService; private final ProjectService projectService; + private final UserService userService; + private final EntrepreneurService entrepreneurService; @Autowired - EntrepreneurApiService(SectionCellService sectionCellService, ProjectService projectService) { + EntrepreneurApiService( + SectionCellService sectionCellService, + ProjectService projectService, + UserService userService, + EntrepreneurService entrepreneurService) { this.sectionCellService = sectionCellService; this.projectService = projectService; + this.userService = userService; + this.entrepreneurService = entrepreneurService; + } + + // Create utils file ? + Boolean isAllowedToCheckProject(String mail, long projectId) { + User user = this.userService.getUserByEmail(mail); + Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser()); + Project project = this.projectService.getProjectById(projectId); + return entrepreneur.getProjectParticipation() == project; } public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) { @@ -29,6 +53,20 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } + if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + logger.warn( + "User {} tried to edit section cells {} of the project {} but is not allowed to.", + mail, + sectionCellId, + this.sectionCellService.getProjectId(sectionCellId)); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} edited section cell {} of the project with id {}", + mail, + sectionCellId, + this.sectionCellService.getProjectId(sectionCellId)); sectionCellService.updateSectionCell( sectionCellId, sectionCell.getSectionId(), @@ -43,6 +81,20 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } + if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) { + logger.warn( + "User {} tried to remove section cells {} of the project {} but is not allowed to.", + mail, + sectionCellId, + this.sectionCellService.getSectionCellById(sectionCellId)); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} removed section cell {} of the project with id {}", + mail, + sectionCellId, + this.sectionCellService.getProjectId(sectionCellId)); sectionCellService.removeSectionCellById(sectionCellId); } @@ -52,14 +104,29 @@ public class EntrepreneurApiService { throw new ResponseStatusException( HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide"); } + if (!isAllowedToCheckProject( + mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) { + logger.warn( + "User {} tried to add a section cell to the project {} but is not allowed to.", + mail, + this.sectionCellService.getProjectId(sectionCell.getIdSectionCell())); + throw new ResponseStatusException( + HttpStatus.UNAUTHORIZED, "You're not allowed to check this project"); + } + logger.info( + "User {} added a new section cell {} to the project with id {}", + mail, + sectionCell.getIdSectionCell(), + this.sectionCellService.getProjectId(sectionCell.getIdSectionCell())); sectionCellService.addNewSectionCell(sectionCell); } public void requestNewProject(Project project, String mail) { if (project == null) { - System.err.println("Trying to request the creation of a null project"); + logger.error("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"); projectService.addNewProject(project); } 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 225ef06..577cf9b 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 @@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Annotation; import enseirb.myinpulse.repository.AnnotationRepository; +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; @@ -13,6 +15,8 @@ import java.util.Optional; @Service public class AnnotationService { + protected static final Logger logger = LogManager.getLogger(); + private final AnnotationRepository annotationRepository; @Autowired @@ -27,6 +31,7 @@ public class AnnotationService { public Annotation getAnnotationById(Long id) { Optional annotation = annotationRepository.findById(id); if (annotation.isEmpty()) { + logger.error("getAnnotationById : No annotation found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette annotation n'existe pas"); } @@ -44,7 +49,9 @@ public class AnnotationService { public Annotation updateAnnotation(Long id, String comment) { Optional annotation = annotationRepository.findById(id); if (annotation.isEmpty()) { - return null; + logger.error("updateAnnotation : No annotation found with id {}", id); + throw new ResponseStatusException( + HttpStatus.NOT_FOUND, "Cette annotation n'existe pas"); } if (comment != null) { annotation.get().setComment(comment); diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java similarity index 64% rename from MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java rename to MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java index 3761d51..7ba0ff5 100644 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/AppointmentController.java +++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/AppointmentService.java @@ -1,69 +1,79 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import enseirb.myinpulse.model.Appointment; -import enseirb.myinpulse.repository.AppointmentRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; - -import java.time.LocalDate; -import java.time.LocalTime; -import java.util.Optional; - -@RestController -public class AppointmentController { - - @Autowired AppointmentRepository appointmentRepository; - - @GetMapping("/Appointment") - @ResponseBody - public Iterable allAppointments() { - return this.appointmentRepository.findAll(); - } - - @GetMapping("/Appointment/{id}") - public Appointment getAppointmentById(@PathVariable Long id) { - Optional appointment = this.appointmentRepository.findById(id); - if (appointment.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - return appointment.get(); - } - - @PostMapping("/Appointment") - public Appointment addAppointment(@RequestBody Appointment appointment) { - return this.appointmentRepository.save(appointment); - } - - @PostMapping("/Appointment/{id}") - public Appointment updateAppointment( - @PathVariable Long id, - LocalDate appointmentDate, - LocalTime appointmentTime, - LocalTime appointmentDuration, - String appointmentPlace, - String appointmentSubject) { - Optional appointment = this.appointmentRepository.findById(id); - if (appointment.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); - } - if (appointmentDate != null) { - appointment.get().setAppointmentDate(appointmentDate); - } - if (appointmentTime != null) { - appointment.get().setAppointmentTime(appointmentTime); - } - if (appointmentDuration != null) { - appointment.get().setAppointmentDuration(appointmentDuration); - } - if (appointmentPlace != null) { - appointment.get().setAppointmentPlace(appointmentPlace); - } - if (appointmentSubject != null) { - appointment.get().setAppointmentSubject(appointmentSubject); - } - return this.appointmentRepository.save(appointment.get()); - } -} +package enseirb.myinpulse.service.database; + +import enseirb.myinpulse.model.Appointment; +import enseirb.myinpulse.repository.AppointmentRepository; + +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; +import org.springframework.web.server.ResponseStatusException; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.Optional; + +@Service +public class AppointmentService { + + private static final Logger logger = LogManager.getLogger(AppointmentService.class); + + private AppointmentRepository appointmentRepository; + + @Autowired + AppointmentService(AppointmentRepository appointmentRepository) { + this.appointmentRepository = appointmentRepository; + } + + public Iterable getallAppointments() { + return this.appointmentRepository.findAll(); + } + + public Appointment getAppointmentById(Long id) { + Optional appointment = this.appointmentRepository.findById(id); + if (appointment.isEmpty()) { + logger.error("getAppointmentById : No appointment found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + return appointment.get(); + } + + public Appointment addNewAppointment(Appointment appointment) { + return this.appointmentRepository.save(appointment); + } + + public void deleteAppointmentById(Long id) { + this.appointmentRepository.deleteById(id); + } + + public Appointment updateAppointment( + Long id, + LocalDate appointmentDate, + LocalTime appointmentTime, + LocalTime appointmentDuration, + String appointmentPlace, + String appointmentSubject) { + Optional appointment = this.appointmentRepository.findById(id); + if (appointment.isEmpty()) { + logger.error("updateAppointment : No appointment found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce rendez vous n'existe pas"); + } + if (appointmentDate != null) { + appointment.get().setAppointmentDate(appointmentDate); + } + if (appointmentTime != null) { + appointment.get().setAppointmentTime(appointmentTime); + } + if (appointmentDuration != null) { + appointment.get().setAppointmentDuration(appointmentDuration); + } + if (appointmentPlace != null) { + appointment.get().setAppointmentPlace(appointmentPlace); + } + if (appointmentSubject != null) { + appointment.get().setAppointmentSubject(appointmentSubject); + } + 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 6e85920..f24878f 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 @@ -4,9 +4,10 @@ import enseirb.myinpulse.model.Entrepreneur; import enseirb.myinpulse.model.Project; import enseirb.myinpulse.repository.EntrepreneurRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import java.util.Optional; @@ -14,6 +15,8 @@ import java.util.Optional; @Service public class EntrepreneurService { + protected static final Logger logger = LogManager.getLogger(); + private final EntrepreneurRepository entrepreneurRepository; EntrepreneurService(EntrepreneurRepository entrepreneurRepository) { @@ -27,6 +30,7 @@ public class EntrepreneurService { public Entrepreneur getEntrepreneurById(Long id) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { + logger.error("getEntrepreneurById : No entrepreneur found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } @@ -41,6 +45,7 @@ public class EntrepreneurService { Long id, String school, String course, Boolean sneeStatus) { Optional entrepreneur = entrepreneurRepository.findById(id); if (entrepreneur.isEmpty()) { + logger.error("updateEntrepreneur : No entrepreneur found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cet entrepreneur n'existe pas"); } 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 d073b26..10dc7e9 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 @@ -34,7 +34,7 @@ public class ProjectService { public Project getProjectById(Long id) { Optional project = this.projectRepository.findById(id); if (project.isEmpty()) { - System.err.println("Project with id " + id + " not found"); + logger.error("No project found with id {}", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas"); } return project.get(); @@ -77,7 +77,7 @@ public class ProjectService { if (projectStatus != null) { if (!validateStatus(projectStatus)) { - System.err.println("updateProjectStatus: Invalid status " + projectStatus); + logger.error("updateProjectStatus: Invalid status {}", projectStatus); throw new ResponseStatusException( HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté"); } 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 e9d8d27..2a8d273 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 @@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.Report; import enseirb.myinpulse.repository.ReportRepository; +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; @@ -12,6 +14,9 @@ import java.util.Optional; @Service public class ReportService { + + protected static final Logger logger = LogManager.getLogger(); + private final ReportRepository reportRepository; @Autowired @@ -19,16 +24,37 @@ public class ReportService { this.reportRepository = reportRepository; } - Report getReportById(int id) { - Optional report = reportRepository.findById(id); + public Iterable getAllReports() { + return this.reportRepository.findAll(); + } + + public Report getReportById(Long id) { + Optional report = this.reportRepository.findById(id); if (report.isEmpty()) { + logger.error("getReportById : No report found with id {}", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); } return report.get(); } // TODO: do some validation - void saveReport(Report report) { - reportRepository.save(report); + public Report addNewReport(Report report) { + return this.reportRepository.save(report); + } + + public void deleteReportById(Long id) { + this.reportRepository.deleteById(id); + } + + public Report updateReport(Long id, String reportContent) { + Optional report = this.reportRepository.findById(id); + if (report.isEmpty()) { + logger.error("updateReport : No report found with id {}", id); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); + } + if (reportContent != null) { + report.get().setReportContent(reportContent); + } + 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 6f998ca..f51f4d5 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 @@ -4,6 +4,8 @@ import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.repository.SectionCellRepository; +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; @@ -15,6 +17,8 @@ import java.util.Optional; @Service public class SectionCellService { + protected static final Logger logger = LogManager.getLogger(); + private final SectionCellRepository sectionCellRepository; @Autowired @@ -29,6 +33,7 @@ public class SectionCellService { public SectionCell getSectionCellById(Long id) { Optional sectionCell = this.sectionCellRepository.findById(id); if (sectionCell.isEmpty()) { + logger.error("getSectionCellById : No sectionCell found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } @@ -47,6 +52,7 @@ public class SectionCellService { Long id, Long sectionId, String contentSectionCell, LocalDateTime modificationDate) { Optional sectionCell = this.sectionCellRepository.findById(id); if (sectionCell.isEmpty()) { + logger.error("updateSectionCell : No sectionCell found with id {}", id); throw new ResponseStatusException( HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas"); } @@ -65,4 +71,10 @@ public class SectionCellService { public Iterable getSectionCellsByProject(Project project, Long sectionId) { return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId); } + + public Long getProjectId(Long sectionCellId) { + SectionCell sectionCell = getSectionCellById(sectionCellId); + Project sectionProject = sectionCell.getProjectSectionCell(); + return sectionProject.getIdProject(); + } } 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 ab2361d..cf24fa3 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 @@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database; import enseirb.myinpulse.model.User; import enseirb.myinpulse.repository.UserRepository; +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; @@ -14,6 +16,9 @@ import java.util.Optional; @Service public class UserService { + + protected static final Logger logger = LogManager.getLogger(); + private final UserRepository userRepository; @Autowired @@ -30,8 +35,8 @@ public class UserService { Optional opt_user = this.userRepository.findByPrimaryMail(email); if (opt_user.isEmpty()) { - System.err.println("Couldn't find user with email " + email); - throw new ResponseStatusException(HttpStatus.NOT_FOUND); + logger.error("getUserByEmail : No user found with email {}", email); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); } return opt_user.get(); } @@ -53,6 +58,7 @@ public class UserService { String phoneNumber) { Optional user = userRepository.findById(id); if (user.isEmpty()) { + logger.error("updateUser : No user found with id {}", id); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cet utilisateur n'existe pas"); } if (userName != null) { diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java deleted file mode 100644 index 7b3458b..0000000 --- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/ReportController.java +++ /dev/null @@ -1,43 +0,0 @@ -package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services; - -import org.springframework.web.bind.annotation.*; - -@RestController -public class ReportController { - /* - private final ReportRepository reportRepository; - - @Autowired - public ReportController(ReportRepository reportRepository) { - this.reportRepository = reportRepository; - } - - @GetMapping("/Report") - @ResponseBody - public Iterable allReports() { - System.out.println("\n\n"); - System.out.println(ReportRepository); - System.out.println("\n\n"); - return this.reportRepository.findAll(); - } - - - @PostMapping("/Report") - public Report addReport(@RequestBody Report report) { - return this.reportRepository.save(report); - } - - @PostMapping("/Report/{id}") - public Report updateProject(@PathVariable Long id, String reportContent) { - Optional report = this.reportRepository.findById(id); - if (report.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas"); - } - if (reportContent != null) { - report.get().setReportContent(reportContent); - } - return this.reportRepository.save(report.get()); - } - - */ -}