feat: started test for EntrepreneurServiceApi
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package enseirb.myinpulse.controller;
|
||||
|
||||
import enseirb.myinpulse.model.SectionCell;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.model.SectionCell;
|
||||
import enseirb.myinpulse.service.EntrepreneurApiService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -31,10 +31,10 @@ public class EntrepreneurApi {
|
||||
@PutMapping("/entrepreneur/lcsection/modify/{sectionId}")
|
||||
public void editSectionCell(
|
||||
@PathVariable Long sectionId,
|
||||
@RequestBody SectionCell sectionCell,
|
||||
@RequestBody String content,
|
||||
@AuthenticationPrincipal Jwt principal) {
|
||||
entrepreneurApiService.editSectionCell(
|
||||
sectionId, sectionCell, principal.getClaimAsString("email"));
|
||||
sectionId, content, principal.getClaimAsString("email"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import jakarta.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "project")
|
||||
@ -66,6 +67,21 @@ public class Project {
|
||||
this.entrepreneurProposed = entrepreneurProposed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Project project = (Project) o;
|
||||
return Objects.equals(listEntrepreneurParticipation, project.listEntrepreneurParticipation)
|
||||
&& Objects.equals(listSectionCell, project.listSectionCell)
|
||||
&& Objects.equals(idProject, project.idProject)
|
||||
&& Objects.equals(projectName, project.projectName)
|
||||
&& Objects.deepEquals(logo, project.logo)
|
||||
&& Objects.equals(creationDate, project.creationDate)
|
||||
&& projectStatus == project.projectStatus
|
||||
&& Objects.equals(projectAdministrator, project.projectAdministrator)
|
||||
&& Objects.equals(entrepreneurProposed, project.entrepreneurProposed);
|
||||
}
|
||||
|
||||
public Long getIdProject() {
|
||||
return idProject;
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public class EntrepreneurApiService {
|
||||
this.utilsService = utilsService;
|
||||
}
|
||||
|
||||
public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) {
|
||||
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
|
||||
if (editSectionCell == null) {
|
||||
public void editSectionCell(Long sectionCellId, String content, String mail) {
|
||||
SectionCell sectionCell = sectionCellService.getSectionCellById(sectionCellId);
|
||||
if (sectionCell == null) {
|
||||
System.err.println("Trying to edit unknown section cell");
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
|
||||
@ -55,11 +55,7 @@ public class EntrepreneurApiService {
|
||||
mail,
|
||||
sectionCellId,
|
||||
this.sectionCellService.getProjectId(sectionCellId));
|
||||
sectionCellService.updateSectionCell(
|
||||
sectionCellId,
|
||||
sectionCell.getSectionId(),
|
||||
sectionCell.getContentSectionCell(),
|
||||
sectionCell.getModificationDate());
|
||||
sectionCellService.updateSectionCell(sectionCellId, content);
|
||||
}
|
||||
|
||||
public void removeSectionCell(Long sectionCellId, String mail) {
|
||||
|
@ -50,22 +50,16 @@ public class SectionCellService {
|
||||
this.sectionCellRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public SectionCell updateSectionCell(
|
||||
Long id, Long sectionId, String contentSectionCell, LocalDateTime modificationDate) {
|
||||
public SectionCell updateSectionCell(Long id, String contentSectionCell) {
|
||||
Optional<SectionCell> sectionCell = this.sectionCellRepository.findById(id);
|
||||
if (sectionCell.isEmpty()) {
|
||||
logger.error("updateSectionCell : No sectionCell found with id {}", id);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
|
||||
}
|
||||
if (sectionId != null) {
|
||||
sectionCell.get().setSectionId(sectionId);
|
||||
}
|
||||
if (contentSectionCell != null) {
|
||||
sectionCell.get().setContentSectionCell(contentSectionCell);
|
||||
}
|
||||
if (modificationDate != null) {
|
||||
sectionCell.get().setModificationDate(modificationDate);
|
||||
sectionCell.get().setModificationDate(LocalDateTime.now());
|
||||
}
|
||||
return this.sectionCellRepository.save(sectionCell.get());
|
||||
}
|
||||
|
Reference in New Issue
Block a user