fix: more tests working, still need fixes
This commit is contained in:
@ -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)) {
|
||||
|
Reference in New Issue
Block a user