feat: renamex title to sectionId and added a new shared API call

This commit is contained in:
Pierre Tellier
2025-02-26 15:55:33 +01:00
parent 8d4dc7916d
commit 5c3b2b138d
7 changed files with 61 additions and 108 deletions
MyINPulse-back/src/main/java/enseirb/myinpulse

@ -2,9 +2,9 @@ package enseirb.myinpulse.service;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.SectionCellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@ -31,7 +31,7 @@ public class EntrepreneurApiService {
}
sectionCellService.updateSectionCell(
sectionCellId,
sectionCell.getTitle(),
sectionCell.getSectionId(),
sectionCell.getContentSectionCell(),
sectionCell.getModificationDate());
}

@ -1,10 +1,7 @@
package enseirb.myinpulse.service;
import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.AdministratorService;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.UserService;
import enseirb.myinpulse.service.database.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -22,17 +19,20 @@ public class SharedApiService {
private final UserService userService;
private final ProjectService projectService;
private final EntrepreneurService entrepreneurService;
private final SectionCellService sectionCellService;
@Autowired
SharedApiService(
AdministratorService administratorService,
UserService userService,
ProjectService projectService,
EntrepreneurService entrepreneurService) {
EntrepreneurService entrepreneurService,
SectionCellService sectionCellService) {
this.administratorService = administratorService;
this.userService = userService;
this.projectService = projectService;
this.entrepreneurService = entrepreneurService;
this.sectionCellService = sectionCellService;
}
// TODO: test
@ -58,13 +58,23 @@ public class SharedApiService {
return entrepreneur.getProjectParticipation() == project;
}
// TODO
public Iterable<SectionCell> getLCSection(
String projectId, String title, String date, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
// TODO filter this with date
public Iterable<SectionCell> getSectionCells(
long projectId, long sectionId, String date, String mail) {
if (!isAllowedToCheckProject(mail, projectId)) {
logger.warn(
"User {} tried to check section cells of the project {} but is not allowed to.",
mail,
projectId);
throw new ResponseStatusException(
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
}
Project project = this.projectService.getProjectById(projectId);
return this.sectionCellService.getSectionCellsByProject(project, sectionId);
}
// TODO: test, protect via email
// TODO: test
public Iterable<Entrepreneur> getEntrepreneursByProjectId(long projectId, String mail) {
if (!isAllowedToCheckProject(mail, projectId)) {
logger.warn(
@ -92,14 +102,17 @@ public class SharedApiService {
return project.getAdministrator();
}
// TODO
public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
}
// TODO
public void getPDFReport(int appointmentId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
}
// TODO
public void createAppointmentRequest(Appointment appointment, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
}

@ -1,5 +1,6 @@
package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.repository.SectionCellRepository;
@ -43,14 +44,14 @@ public class SectionCellService {
}
public SectionCell updateSectionCell(
Long id, String title, String contentSectionCell, LocalDateTime modificationDate) {
Long id, Long sectionId, String contentSectionCell, LocalDateTime modificationDate) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
if (title != null) {
sectionCell.get().setTitle(title);
if (sectionId != null) {
sectionCell.get().setSectionId(sectionId);
}
if (contentSectionCell != null) {
sectionCell.get().setContentSectionCell(contentSectionCell);
@ -60,4 +61,8 @@ public class SectionCellService {
}
return this.sectionCellRepository.save(sectionCell.get());
}
public Iterable<SectionCell> getSectionCellsByProject(Project project, Long sectionId) {
return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId);
}
}

@ -1,62 +0,0 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
import enseirb.myinpulse.model.SectionCell;
import enseirb.myinpulse.repository.SectionCellRepository;
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.LocalDateTime;
import java.util.Optional;
@RestController
public class SectionCellController {
@Autowired SectionCellRepository sectionCellRepository;
@GetMapping("/SectionCell")
@ResponseBody
public Iterable<SectionCell> allSectionCells() {
return this.sectionCellRepository.findAll();
}
@GetMapping("/SectionCell/{id}")
public SectionCell getSectionCellById(@PathVariable Long id) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
return sectionCell.get();
}
@PostMapping("/SectionCell")
public SectionCell addSectionCell(@RequestBody SectionCell sectionCell) {
return this.sectionCellRepository.save(sectionCell);
}
@PostMapping("/SectionCell/{id}")
public SectionCell updateSectionCell(
@PathVariable Long id,
String title,
String contentSectionCell,
LocalDateTime modificationDate) {
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
if (sectionCell.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
if (title != null) {
sectionCell.get().setTitle(title);
}
if (contentSectionCell != null) {
sectionCell.get().setContentSectionCell(contentSectionCell);
}
if (modificationDate != null) {
sectionCell.get().setModificationDate(modificationDate);
}
return this.sectionCellRepository.save(sectionCell.get());
}
}