fix: more tests working, still need fixes
Some checks failed
Format / formatting (push) Failing after 4s
Build / build (push) Failing after 5m8s
CI / build (push) Successful in 10s

This commit is contained in:
Théo Le Lez
2025-04-16 10:36:59 +02:00
parent 55112c8508
commit 6029457735
6 changed files with 168 additions and 18 deletions

View File

@ -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)) {