backend-api #6

Merged
piair merged 107 commits from backend-api into main 2025-03-26 19:04:09 +01:00
7 changed files with 61 additions and 108 deletions
Showing only changes of commit 5c3b2b138d - Show all commits

View File

@ -21,22 +21,18 @@ public class SharedApi {
} }
/** /**
* TODO: It does not looks like a good id to have the title and the date in the url. What even * Endpoint used to get the data inside the lean canvas
* TODO: is the title btw ? if this is the LC section, wouldn't it be better to use an ID ?
* TODO: choose return type, cf comment in LCSection
*
* <p>Endpoint used to get the data inside the lean canvas
* *
* @return a list of lean canvas sections * @return a list of lean canvas sections
*/ */
@GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}") @GetMapping("/shared/project/lcsection/{projectId}/{sectionId}/{date}")
public Iterable<SectionCell> getLCSection( public Iterable<SectionCell> getLCSection(
@PathVariable("projectId") String projectId, @PathVariable("projectId") Long projectId,
@PathVariable("title") String title, @PathVariable("sectionId") Long sectionId,
@PathVariable("date") String date, @PathVariable("date") String date,
@AuthenticationPrincipal Jwt principal) { @AuthenticationPrincipal Jwt principal) {
return sharedApiService.getLCSection( return sharedApiService.getSectionCells(
projectId, title, date, principal.getClaimAsString("email")); projectId, sectionId, date, principal.getClaimAsString("email"));
} }
/** /**

View File

@ -11,42 +11,39 @@ import java.util.List;
@Table(name = "section_cell") @Table(name = "section_cell")
public class SectionCell { public class SectionCell {
@ManyToMany(mappedBy = "listSectionCell")
private final List<Appointment> appointment = new ArrayList<>();
@OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
private final List<Annotation> listAnnotation = new ArrayList<>();
@Id @Id
@NotNull @NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idSectionCell; private Long idSectionCell;
@Column(length = 255) @Column() private long sectionId;
private String title;
private String contentSectionCell; private String contentSectionCell;
/*@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idAdministrator")
private Administrator administratorSectionCell;*/
// should now be useless
private LocalDateTime modificationDate; private LocalDateTime modificationDate;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idProject") @JoinColumn(name = "idProject")
private Project projectSectionCell; private Project projectSectionCell;
/*@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idAdministrator")
private Administrator administratorSectionCell;*/
// should now be useless
@ManyToMany(mappedBy = "listSectionCell")
private List<Appointment> appointment = new ArrayList<>();
@OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
private List<Annotation> listAnnotation = new ArrayList<>();
public SectionCell() {} public SectionCell() {}
public SectionCell( public SectionCell(
Long idSectionCell, Long idSectionCell,
String title, Long sectionId,
String contentSectionCell, String contentSectionCell,
LocalDateTime modificationDate) { LocalDateTime modificationDate) {
this.idSectionCell = idSectionCell; this.idSectionCell = idSectionCell;
this.title = title; this.sectionId = sectionId;
this.contentSectionCell = contentSectionCell; this.contentSectionCell = contentSectionCell;
this.modificationDate = modificationDate; this.modificationDate = modificationDate;
} }
@ -59,12 +56,12 @@ public class SectionCell {
this.idSectionCell = idSectionCell; this.idSectionCell = idSectionCell;
} }
public String getTitle() { public Long getSectionId() {
return title; return sectionId;
} }
public void setTitle(String title) { public void setSectionId(Long sectionId) {
this.title = title; this.sectionId = sectionId;
} }
public String getContentSectionCell() { public String getContentSectionCell() {

View File

@ -1,9 +1,13 @@
package enseirb.myinpulse.repository; package enseirb.myinpulse.repository;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.model.SectionCell;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource @RepositoryRestResource
public interface SectionCellRepository extends JpaRepository<SectionCell, Long> {} public interface SectionCellRepository extends JpaRepository<SectionCell, Long> {
Iterable<SectionCell> findByProjectSectionCellAndSectionId(Project project, long sectionId);
}

View File

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

View File

@ -1,10 +1,7 @@
package enseirb.myinpulse.service; package enseirb.myinpulse.service;
import enseirb.myinpulse.model.*; import enseirb.myinpulse.model.*;
import enseirb.myinpulse.service.database.AdministratorService; import enseirb.myinpulse.service.database.*;
import enseirb.myinpulse.service.database.EntrepreneurService;
import enseirb.myinpulse.service.database.ProjectService;
import enseirb.myinpulse.service.database.UserService;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -22,17 +19,20 @@ public class SharedApiService {
private final UserService userService; private final UserService userService;
private final ProjectService projectService; private final ProjectService projectService;
private final EntrepreneurService entrepreneurService; private final EntrepreneurService entrepreneurService;
private final SectionCellService sectionCellService;
@Autowired @Autowired
SharedApiService( SharedApiService(
AdministratorService administratorService, AdministratorService administratorService,
UserService userService, UserService userService,
ProjectService projectService, ProjectService projectService,
EntrepreneurService entrepreneurService) { EntrepreneurService entrepreneurService,
SectionCellService sectionCellService) {
this.administratorService = administratorService; this.administratorService = administratorService;
this.userService = userService; this.userService = userService;
this.projectService = projectService; this.projectService = projectService;
this.entrepreneurService = entrepreneurService; this.entrepreneurService = entrepreneurService;
this.sectionCellService = sectionCellService;
} }
// TODO: test // TODO: test
@ -58,13 +58,23 @@ public class SharedApiService {
return entrepreneur.getProjectParticipation() == project; return entrepreneur.getProjectParticipation() == project;
} }
// TODO // TODO filter this with date
public Iterable<SectionCell> getLCSection( public Iterable<SectionCell> getSectionCells(
String projectId, String title, String date, String mail) { long projectId, long sectionId, String date, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
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) { public Iterable<Entrepreneur> getEntrepreneursByProjectId(long projectId, String mail) {
if (!isAllowedToCheckProject(mail, projectId)) { if (!isAllowedToCheckProject(mail, projectId)) {
logger.warn( logger.warn(
@ -92,14 +102,17 @@ public class SharedApiService {
return project.getAdministrator(); return project.getAdministrator();
} }
// TODO
public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) { public Iterable<Appointment> getAppointmentsByProjectId(int projectId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
// TODO
public void getPDFReport(int appointmentId, String mail) { public void getPDFReport(int appointmentId, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }
// TODO
public void createAppointmentRequest(Appointment appointment, String mail) { public void createAppointmentRequest(Appointment appointment, String mail) {
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet"); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
} }

View File

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

View File

@ -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());
}
}