-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInterrogationController.java
More file actions
69 lines (55 loc) · 3.17 KB
/
Copy pathInterrogationController.java
File metadata and controls
69 lines (55 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package fr.insee.genesis.controller.rest.responses;
import fr.insee.genesis.controller.dto.InterrogationId;
import fr.insee.genesis.controller.rest.CommonApiResponse;
import fr.insee.genesis.domain.ports.api.SurveyUnitApiPort;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@RequestMapping(path = "/interrogations" )
@Controller
@Slf4j
public class InterrogationController implements CommonApiResponse {
private final SurveyUnitApiPort surveyUnitService;
public InterrogationController(SurveyUnitApiPort surveyUnitService) {
this.surveyUnitService = surveyUnitService;
}
@Operation(summary = "Retrieve all interrogations for a given questionnaire")
@GetMapping(path = "/by-questionnaire")
public ResponseEntity<List<InterrogationId>> getAllInterrogationIdsByQuestionnaire(@RequestParam("questionnaireId") String questionnaireId) {
List<InterrogationId> responses = surveyUnitService.findDistinctInterrogationIdsByQuestionnaireId(questionnaireId);
return ResponseEntity.ok(responses);
}
//========= OPTIMISATIONS PERFS (START) ==========
/**
* @author Adrien Marchal
*/
@Operation(summary = "Retrieve number of interrogations for a given questionnaire")
@GetMapping(path = "/by-questionnaire/{questionnaireId}/count")
public ResponseEntity<Long> countAllInterrogationIdsByQuestionnaire(
@Parameter(description = "questionnaireId", required = true) @PathVariable("questionnaireId") String questionnaireId
) {
Long response = surveyUnitService.countInterrogationIdsByQuestionnaireId(questionnaireId);
return ResponseEntity.ok(response);
}
/**
* @author Adrien Marchal
*/
@Operation(summary = "Retrieve paginated interrogations for a given questionnaire")
@GetMapping(path = "/by-questionnaire/{questionnaireId}/paginated")
public ResponseEntity<List<InterrogationId>> getPaginatedInterrogationIdsByQuestionnaire(
@Parameter(description = "questionnaireId", required = true) @PathVariable("questionnaireId") String questionnaireId,
@Parameter(description = "if totalSize is 0, a count query is made to get the real totalSize to process", required = false) @RequestParam(defaultValue = "0") long totalSize,
@Parameter(description = "blockSize", required = false) @RequestParam(defaultValue = "1000") long blockSize,
@Parameter(description = "page number / block index", required = false) @RequestParam(defaultValue = "0") long page) {
List<InterrogationId> responses = surveyUnitService.findDistinctPageableInterrogationIdsByQuestionnaireId(questionnaireId, totalSize, blockSize, page);
return ResponseEntity.ok(responses);
}
//======== OPTIMISATIONS PERFS (END) ===========
}