Compare commits

..

No commits in common. "3890aed158e22f32408ce1d93fdd72b7c57d5048" and "024deeba418109e54d69923683884c1f518057cc" have entirely different histories.

5 changed files with 25 additions and 176 deletions

View File

@ -1,6 +1,6 @@
package enseirb.myinpulse.controller; package enseirb.myinpulse.controller;
import enseirb.myinpulse.model.SectionCell; import enseirb.myinpulse.model.LCSection;
import enseirb.myinpulse.model.Project; import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.service.EntrepreneurApiService; import enseirb.myinpulse.service.EntrepreneurApiService;
@ -29,12 +29,12 @@ public class EntrepreneurApi {
* @return status code * @return status code
*/ */
@PutMapping("/entrepreneur/lcsection/modify/{sectionId}") @PutMapping("/entrepreneur/lcsection/modify/{sectionId}")
public void editSectionCell( public void editLCSection(
@PathVariable Long sectionId, @PathVariable String sectionId,
@RequestBody SectionCell sectionCell, @RequestBody LCSection section,
@AuthenticationPrincipal Jwt principal) { @AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.editSectionCell( entrepreneurApiService.editLCSection(
sectionId, sectionCell, principal.getClaimAsString("email")); sectionId, section, principal.getClaimAsString("email"));
} }
/** /**
@ -45,9 +45,9 @@ public class EntrepreneurApi {
* @return status code * @return status code
*/ */
@DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}") @DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}")
public void removeSectionCell( public void removeLCSection(
@PathVariable Long sectionId, @AuthenticationPrincipal Jwt principal) { @PathVariable String sectionId, @AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.removeSectionCell(sectionId, principal.getClaimAsString("email")); entrepreneurApiService.removeLCSection(sectionId, principal.getClaimAsString("email"));
} }
/** /**
@ -57,10 +57,13 @@ public class EntrepreneurApi {
* *
* @return status code * @return status code
*/ */
@PostMapping("/entrepreneur/lcsection/add") // remove id from doc aswell @PostMapping("/entrepreneur/lcsection/add/{sectionId}")
public void addLCSection( public void addLCSection(
@RequestBody SectionCell sectionCell, @AuthenticationPrincipal Jwt principal) { @PathVariable String sectionId,
entrepreneurApiService.addSectionCell(sectionCell, principal.getClaimAsString("email")); @RequestBody LCSection section,
@AuthenticationPrincipal Jwt principal) {
entrepreneurApiService.addLCSection(
sectionId, section, principal.getClaimAsString("email"));
} }
/** /**

View File

@ -33,7 +33,7 @@ public class Annotation {
return comment; return comment;
} }
public void setComment(String comment) { public void setCommentary(String comment) {
this.comment = comment; this.comment = comment;
} }
} }

View File

@ -1,66 +1,29 @@
package enseirb.myinpulse.service; package enseirb.myinpulse.service;
import enseirb.myinpulse.model.LCSection;
import enseirb.myinpulse.model.Project; 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.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
@Service @Service
public class EntrepreneurApiService { public class EntrepreneurApiService {
private final SectionCellService sectionCellService; public void editLCSection(String sectionId, LCSection section, String mail) {
private final ProjectService projectService; throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
@Autowired
EntrepreneurApiService(SectionCellService sectionCellService, ProjectService projectService) {
this.sectionCellService = sectionCellService;
this.projectService = projectService;
} }
public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) { public void removeLCSection(String sectionId, String mail) {
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
if (editSectionCell == null) {
System.err.println("Trying to edit unknown section cell");
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
sectionCellService.updateSectionCell(
sectionCellId,
sectionCell.getTitle(),
sectionCell.getContentSectionCell(),
sectionCell.getModificationDate());
} }
public void removeSectionCell(Long sectionCellId, String mail) { public void addLCSection(String sectionId, LCSection section, String mail) {
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId); throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
if (editSectionCell == null) {
System.err.println("Trying to remove unknown section cell");
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
}
sectionCellService.removeSectionCellById(sectionCellId);
}
public void addSectionCell(SectionCell sectionCell, String mail) {
if (sectionCell == null) {
System.err.println("Trying to create an empty section cell");
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
}
sectionCellService.addNewSectionCell(sectionCell);
} }
public void requestNewProject(Project project, String mail) { public void requestNewProject(Project project, String mail) {
if (project == null) { throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
System.err.println("Trying to request the creation of a null project");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide");
}
project.setProjectStatus("PENDING");
projectService.addNewProject(project);
} }
} }

View File

@ -1,54 +0,0 @@
package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Annotation;
import enseirb.myinpulse.repository.AnnotationRepository;
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.util.Optional;
@Service
public class AnnotationService {
private final AnnotationRepository annotationRepository;
@Autowired
AnnotationService(AnnotationRepository annotationRepository) {
this.annotationRepository = annotationRepository;
}
public Iterable<Annotation> getAllAnnotations() {
return annotationRepository.findAll();
}
public Annotation getAnnotationById(Long id) {
Optional<Annotation> annotation = annotationRepository.findById(id);
if (annotation.isEmpty()) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND, "Cette annotation n'existe pas");
}
return annotation.get();
}
public Annotation addNewAnnotation(Annotation annotation) {
return this.annotationRepository.save(annotation);
}
public void deleteAnnotationById(Long id) {
this.annotationRepository.deleteById(id);
}
public Annotation updateAnnotation(Long id, String comment) {
Optional<Annotation> annotation = annotationRepository.findById(id);
if (annotation.isEmpty()) {
return null;
}
if (comment != null) {
annotation.get().setComment(comment);
}
return this.annotationRepository.save(annotation.get());
}
}

View File

@ -1,63 +0,0 @@
package enseirb.myinpulse.service.database;
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.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;
import java.util.Optional;
@Service
public class SectionCellService {
private final SectionCellRepository sectionCellRepository;
@Autowired
SectionCellService(SectionCellRepository sectionCellRepository) {
this.sectionCellRepository = sectionCellRepository;
}
public Iterable<SectionCell> getAllSectionCells() {
return this.sectionCellRepository.findAll();
}
public SectionCell getSectionCellById(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();
}
public SectionCell addNewSectionCell(SectionCell sectionCell) {
return this.sectionCellRepository.save(sectionCell);
}
public void removeSectionCellById(Long id) {
this.sectionCellRepository.deleteById(id);
}
public SectionCell updateSectionCell(
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());
}
}