Skip to content

Commit

Permalink
[backend] refact
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 authored and johanah29 committed Oct 25, 2024
1 parent 5361ea0 commit bc3ae33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,12 @@ public Page<ExerciseSimple> exercises(@RequestBody @Valid final SearchPagination

if (currentUser().isAdmin()) {
return buildPaginationCriteriaBuilder(
this.exerciseService::exercises,
(Specification<Exercise> specification, Specification<Exercise> specificationCount, Pageable pageable) -> this.exerciseService.exercises(
findGrantedFor(currentUser().getId()).and(specification),
findGrantedFor(currentUser().getId()).and(specificationCount),
pageable,
joinMap
),
searchPaginationInput,
Exercise.class,
joinMap
Expand All @@ -648,7 +653,8 @@ public Page<ExerciseSimple> exercises(@RequestBody @Valid final SearchPagination
(Specification<Exercise> specification, Specification<Exercise> specificationCount, Pageable pageable) -> this.exerciseService.exercises(
findGrantedFor(currentUser().getId()).and(specification),
findGrantedFor(currentUser().getId()).and(specificationCount),
pageable
pageable,
joinMap
),
searchPaginationInput,
Exercise.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.openbas.rest.scenario;

import io.openbas.aop.LogExecutionTime;
import io.openbas.database.model.Base;
import io.openbas.database.model.Exercise;
import io.openbas.rest.exercise.service.ExerciseService;
import io.openbas.rest.exercise.form.ExerciseSimple;
import io.openbas.utils.pagination.SearchPaginationInput;
import jakarta.persistence.criteria.Join;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,6 +16,9 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

import static io.openbas.database.model.User.ROLE_USER;
import static io.openbas.database.specification.ExerciseSpecification.fromScenario;
import static io.openbas.rest.scenario.ScenarioApi.SCENARIO_URI;
Expand All @@ -39,11 +44,13 @@ public Iterable<ExerciseSimple> scenarioExercises(@PathVariable @NotBlank final
public Iterable<ExerciseSimple> scenarioExercises(
@PathVariable @NotBlank final String scenarioId,
@RequestBody @Valid final SearchPaginationInput searchPaginationInput) {
Map<String, Join<Base, Base>> joinMap = new HashMap<>();
return buildPaginationCriteriaBuilder(
(Specification<Exercise> specification, Specification<Exercise> specificationCount, Pageable pageable) -> this.exerciseService.exercises(
fromScenario(scenarioId).and(specification),
fromScenario(scenarioId).and(specificationCount),
pageable
pageable,
joinMap
),
searchPaginationInput,
Exercise.class
Expand Down

0 comments on commit bc3ae33

Please sign in to comment.