feat: entrepreneur api and api service
This commit is contained in:
parent
e66fa33577
commit
dd5ca2cbd7
@ -1,6 +1,6 @@
|
||||
package enseirb.myinpulse.controller;
|
||||
|
||||
import enseirb.myinpulse.model.LCSection;
|
||||
import enseirb.myinpulse.model.SectionCell;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.service.EntrepreneurApiService;
|
||||
|
||||
@ -29,12 +29,12 @@ public class EntrepreneurApi {
|
||||
* @return status code
|
||||
*/
|
||||
@PutMapping("/entrepreneur/lcsection/modify/{sectionId}")
|
||||
public void editLCSection(
|
||||
@PathVariable String sectionId,
|
||||
@RequestBody LCSection section,
|
||||
public void editSectionCell(
|
||||
@PathVariable Long sectionId,
|
||||
@RequestBody SectionCell sectionCell,
|
||||
@AuthenticationPrincipal Jwt principal) {
|
||||
entrepreneurApiService.editLCSection(
|
||||
sectionId, section, principal.getClaimAsString("email"));
|
||||
entrepreneurApiService.editSectionCell(
|
||||
sectionId, sectionCell, principal.getClaimAsString("email"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,9 +45,9 @@ public class EntrepreneurApi {
|
||||
* @return status code
|
||||
*/
|
||||
@DeleteMapping("/entrepreneur/lcsection/remove/{sectionId}")
|
||||
public void removeLCSection(
|
||||
@PathVariable String sectionId, @AuthenticationPrincipal Jwt principal) {
|
||||
entrepreneurApiService.removeLCSection(sectionId, principal.getClaimAsString("email"));
|
||||
public void removeSectionCell(
|
||||
@PathVariable Long sectionId, @AuthenticationPrincipal Jwt principal) {
|
||||
entrepreneurApiService.removeSectionCell(sectionId, principal.getClaimAsString("email"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,13 +57,10 @@ public class EntrepreneurApi {
|
||||
*
|
||||
* @return status code
|
||||
*/
|
||||
@PostMapping("/entrepreneur/lcsection/add/{sectionId}")
|
||||
@PostMapping("/entrepreneur/lcsection/add") // remove id from doc aswell
|
||||
public void addLCSection(
|
||||
@PathVariable String sectionId,
|
||||
@RequestBody LCSection section,
|
||||
@AuthenticationPrincipal Jwt principal) {
|
||||
entrepreneurApiService.addLCSection(
|
||||
sectionId, section, principal.getClaimAsString("email"));
|
||||
@RequestBody SectionCell sectionCell, @AuthenticationPrincipal Jwt principal) {
|
||||
entrepreneurApiService.addSectionCell(sectionCell, principal.getClaimAsString("email"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ public class Annotation {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setCommentary(String comment) {
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,66 @@
|
||||
package enseirb.myinpulse.service;
|
||||
|
||||
import enseirb.myinpulse.model.LCSection;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
@Service
|
||||
public class EntrepreneurApiService {
|
||||
|
||||
public void editLCSection(String sectionId, LCSection section, String mail) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||
private final SectionCellService sectionCellService;
|
||||
private final ProjectService projectService;
|
||||
|
||||
@Autowired
|
||||
EntrepreneurApiService(SectionCellService sectionCellService, ProjectService projectService) {
|
||||
this.sectionCellService = sectionCellService;
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
public void removeLCSection(String sectionId, String mail) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||
public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) {
|
||||
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
|
||||
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 addLCSection(String sectionId, LCSection section, String mail) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||
public void removeSectionCell(Long sectionCellId, String mail) {
|
||||
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
|
||||
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) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
||||
if (project == null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
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());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user