fix: more tests working, still need fixes
This commit is contained in:
@ -2,6 +2,9 @@ package enseirb.myinpulse.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import org.hibernate.annotations.Generated;
|
||||
import org.hibernate.generator.EventType;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -20,6 +23,10 @@ public class SectionCell {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long idSectionCell;
|
||||
|
||||
@Column(columnDefinition = "serial")
|
||||
@Generated(event = EventType.INSERT)
|
||||
private Long idReference;
|
||||
|
||||
@Column() private long sectionId;
|
||||
private String contentSectionCell;
|
||||
|
||||
@ -56,6 +63,14 @@ public class SectionCell {
|
||||
this.idSectionCell = idSectionCell;
|
||||
}
|
||||
|
||||
public Long getIdReference() {
|
||||
return idReference;
|
||||
}
|
||||
|
||||
public void setIdReference(Long idReference) {
|
||||
this.idReference = idReference;
|
||||
}
|
||||
|
||||
public Long getSectionId() {
|
||||
return sectionId;
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class EntrepreneurApiService {
|
||||
|
||||
@ -64,7 +66,28 @@ public class EntrepreneurApiService {
|
||||
mail,
|
||||
sectionCellId,
|
||||
this.sectionCellService.getProjectId(sectionCellId));
|
||||
sectionCellService.updateSectionCell(sectionCellId, content, null, null, null);
|
||||
SectionCell newSectionCell =
|
||||
new SectionCell(
|
||||
null,
|
||||
sectionCell.getSectionId(),
|
||||
content,
|
||||
LocalDateTime.now(),
|
||||
sectionCell.getProjectSectionCell());
|
||||
newSectionCell.setIdReference(sectionCell.getIdReference());
|
||||
sectionCell
|
||||
.getAppointmentSectionCell()
|
||||
.forEach(
|
||||
appointment -> {
|
||||
newSectionCell.updateAppointmentSectionCell(appointment);
|
||||
});
|
||||
sectionCell
|
||||
.getListAnnotation()
|
||||
.forEach(
|
||||
annotation -> {
|
||||
newSectionCell.updateListAnnotation(annotation);
|
||||
});
|
||||
this.addSectionCell(newSectionCell, mail);
|
||||
// sectionCellService.updateSectionCell(sectionCellId, content, null, null, null);
|
||||
}
|
||||
|
||||
public void removeSectionCell(Long sectionCellId, String mail) {
|
||||
@ -89,7 +112,12 @@ public class EntrepreneurApiService {
|
||||
mail,
|
||||
sectionCellId,
|
||||
this.sectionCellService.getProjectId(sectionCellId));
|
||||
sectionCellService.removeSectionCellById(sectionCellId);
|
||||
SectionCell removedSectionCell = new SectionCell(null, -1L, "", LocalDateTime.now(), null);
|
||||
removedSectionCell.setIdReference(editSectionCell.getIdReference());
|
||||
sectionCellService.addNewSectionCell(removedSectionCell);
|
||||
projectService.updateProjectListSectionCell(
|
||||
sectionCellService.getProjectId(sectionCellId), removedSectionCell);
|
||||
// sectionCellService.removeSectionCellById(sectionCellId);
|
||||
}
|
||||
|
||||
public void addSectionCell(SectionCell sectionCell, String mail) {
|
||||
@ -98,6 +126,11 @@ public class EntrepreneurApiService {
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
|
||||
}
|
||||
if (sectionCell.getSectionId() == -1) {
|
||||
System.err.println("Trying to create an illegal section cell");
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.BAD_REQUEST, "La cellule de section fournie n'est pas valide");
|
||||
}
|
||||
if (!utilsService.isAllowedToCheckProject(
|
||||
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
|
||||
logger.warn(
|
||||
@ -112,7 +145,9 @@ public class EntrepreneurApiService {
|
||||
mail,
|
||||
sectionCell.getIdSectionCell(),
|
||||
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
|
||||
SectionCell newSectionCell = sectionCellService.addNewSectionCell(sectionCell);
|
||||
SectionCell newSectionCell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
sectionCell); // if here, logger fails cause id is null (not added yet)
|
||||
newSectionCell.getProjectSectionCell().updateListSectionCell(newSectionCell);
|
||||
newSectionCell
|
||||
.getAppointmentSectionCell()
|
||||
@ -135,7 +170,14 @@ public class EntrepreneurApiService {
|
||||
}
|
||||
logger.info("User {} created a new project with id {}", mail, project.getIdProject());
|
||||
project.setProjectStatus(PENDING);
|
||||
project.setEntrepreneurProposed((Entrepreneur) this.userService.getUserByEmail(mail));
|
||||
projectService.addNewProject(project);
|
||||
project.getProjectAdministrator().updateListProject(project);
|
||||
project.getEntrepreneurProposed().setProjectProposed(project);
|
||||
project.getListEntrepreneurParticipation()
|
||||
.forEach(entrepreneur -> entrepreneur.setProjectParticipation(project));
|
||||
project.getListSectionCell()
|
||||
.forEach(sectionCell -> sectionCell.setProjectSectionCell(project));
|
||||
}
|
||||
|
||||
public void createAccount(Entrepreneur e) {
|
||||
|
@ -25,6 +25,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Service
|
||||
public class SharedApiService {
|
||||
@ -73,6 +74,45 @@ public class SharedApiService {
|
||||
project, sectionId, dateTime);
|
||||
}
|
||||
|
||||
// Retrieve all up to date (for every sectionId) sectionCells of a project
|
||||
public Iterable<SectionCell> getAllSectionCells(long projectId, String mail) {
|
||||
if (!utilsService.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);
|
||||
List<SectionCell> allSectionCells = new ArrayList<SectionCell>();
|
||||
project.getListSectionCell()
|
||||
.forEach(
|
||||
projectCell -> {
|
||||
AtomicBoolean sameReferenceId =
|
||||
new AtomicBoolean(false); // side effect lambdas
|
||||
allSectionCells.forEach(
|
||||
selectedCell -> {
|
||||
if (projectCell
|
||||
.getIdReference()
|
||||
.equals(selectedCell.getIdReference())) {
|
||||
sameReferenceId.set(true);
|
||||
if (projectCell
|
||||
.getModificationDate()
|
||||
.isAfter(selectedCell.getModificationDate())) {
|
||||
allSectionCells.remove(selectedCell);
|
||||
allSectionCells.add(projectCell);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!sameReferenceId.get()) {
|
||||
allSectionCells.add(projectCell);
|
||||
}
|
||||
});
|
||||
return allSectionCells;
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
public Iterable<Entrepreneur> getEntrepreneursByProjectId(long projectId, String mail) {
|
||||
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||
|
@ -62,11 +62,7 @@ public class EntrepreneurService {
|
||||
|
||||
public void updateEntrepreneurProjectParticipation(
|
||||
long idEntrepreneur, Project projectParticipation) {
|
||||
System.out.println("expected");
|
||||
System.out.println(getEntrepreneurById(idEntrepreneur));
|
||||
Entrepreneur entrepreneur = getEntrepreneurById(idEntrepreneur);
|
||||
System.out.println("test");
|
||||
System.out.println(entrepreneur);
|
||||
entrepreneur.setProjectParticipation(projectParticipation);
|
||||
this.entrepreneurRepository.save(entrepreneur);
|
||||
}
|
||||
|
@ -51,6 +51,12 @@ public class SectionCellService {
|
||||
this.sectionCellRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public void updateSectionCellReferenceId(Long idSectionCell, Long referenceId) {
|
||||
SectionCell sectionCell = this.getSectionCellById(idSectionCell);
|
||||
sectionCell.setIdReference(referenceId);
|
||||
this.sectionCellRepository.save(sectionCell);
|
||||
}
|
||||
|
||||
public void updateSectionCellContent(long idSectionCell, String content) {
|
||||
SectionCell sectionCell = getSectionCellById(idSectionCell);
|
||||
sectionCell.setContentSectionCell(content);
|
||||
|
Reference in New Issue
Block a user