diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java
index 883cc9f..3d17290 100644
--- a/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java
+++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/controller/SharedApi.java
@@ -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
- * 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
- *
- *
Endpoint used to get the data inside the lean canvas
+ * Endpoint used to get the data inside the lean canvas
*
* @return a list of lean canvas sections
*/
- @GetMapping("/shared/project/lcsection/{projectId}/{title}/{date}")
+ @GetMapping("/shared/project/lcsection/{projectId}/{sectionId}/{date}")
public Iterable getLCSection(
- @PathVariable("projectId") String projectId,
- @PathVariable("title") String title,
+ @PathVariable("projectId") Long projectId,
+ @PathVariable("sectionId") Long sectionId,
@PathVariable("date") String date,
@AuthenticationPrincipal Jwt principal) {
- return sharedApiService.getLCSection(
- projectId, title, date, principal.getClaimAsString("email"));
+ return sharedApiService.getSectionCells(
+ projectId, sectionId, date, principal.getClaimAsString("email"));
}
/**
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 aec0a0e..9a03393 100644
--- a/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java
+++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/model/SectionCell.java
@@ -11,42 +11,39 @@ import java.util.List;
@Table(name = "section_cell")
public class SectionCell {
+ @ManyToMany(mappedBy = "listSectionCell")
+ private final List appointment = new ArrayList<>();
+
+ @OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
+ private final List listAnnotation = new ArrayList<>();
+
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idSectionCell;
- @Column(length = 255)
- private String title;
-
+ @Column() private long sectionId;
private String contentSectionCell;
+ /*@ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "idAdministrator")
+ private Administrator administratorSectionCell;*/
+ // should now be useless
private LocalDateTime modificationDate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idProject")
private Project projectSectionCell;
- /*@ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "idAdministrator")
- private Administrator administratorSectionCell;*/
- // should now be useless
-
- @ManyToMany(mappedBy = "listSectionCell")
- private List appointment = new ArrayList<>();
-
- @OneToMany(mappedBy = "sectionCellAnnotation", fetch = FetchType.LAZY, orphanRemoval = true)
- private List listAnnotation = new ArrayList<>();
-
public SectionCell() {}
public SectionCell(
Long idSectionCell,
- String title,
+ Long sectionId,
String contentSectionCell,
LocalDateTime modificationDate) {
this.idSectionCell = idSectionCell;
- this.title = title;
+ this.sectionId = sectionId;
this.contentSectionCell = contentSectionCell;
this.modificationDate = modificationDate;
}
@@ -59,12 +56,12 @@ public class SectionCell {
this.idSectionCell = idSectionCell;
}
- public String getTitle() {
- return title;
+ public Long getSectionId() {
+ return sectionId;
}
- public void setTitle(String title) {
- this.title = title;
+ public void setSectionId(Long sectionId) {
+ this.sectionId = sectionId;
}
public String getContentSectionCell() {
diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java
index 66ce004..674c549 100644
--- a/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java
+++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/repository/SectionCellRepository.java
@@ -1,9 +1,13 @@
package enseirb.myinpulse.repository;
+import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.model.SectionCell;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource
-public interface SectionCellRepository extends JpaRepository {}
+public interface SectionCellRepository extends JpaRepository {
+
+ Iterable findByProjectSectionCellAndSectionId(Project project, long sectionId);
+}
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 d22a6a9..95f0b79 100644
--- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java
+++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/EntrepreneurApiService.java
@@ -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());
}
diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java
index e104cdd..1fe9335 100644
--- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java
+++ b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/SharedApiService.java
@@ -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 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 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 getEntrepreneursByProjectId(long projectId, String mail) {
if (!isAllowedToCheckProject(mail, projectId)) {
logger.warn(
@@ -92,14 +102,17 @@ public class SharedApiService {
return project.getAdministrator();
}
+ // TODO
public Iterable 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");
}
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 c65f770..6f998ca 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.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 = 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 getSectionCellsByProject(Project project, Long sectionId) {
+ return this.sectionCellRepository.findByProjectSectionCellAndSectionId(project, sectionId);
+ }
}
diff --git a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java b/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java
deleted file mode 100644
index 519fd90..0000000
--- a/MyINPulse-back/src/main/java/enseirb/myinpulse/service/database/old_controllers_to_convert_to_services/SectionCellController.java
+++ /dev/null
@@ -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 allSectionCells() {
- return this.sectionCellRepository.findAll();
- }
-
- @GetMapping("/SectionCell/{id}")
- public SectionCell getSectionCellById(@PathVariable Long id) {
- Optional 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 = 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());
- }
-}