Skip to content

Commit

Permalink
feat: add get param value for source
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Sep 6, 2024
1 parent 178d10c commit dfa392a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ private Constants() {
public static final String API_SURVEYS = "/api/surveys";
public static final String API_SOURCE_ID_OPENED = "/api/source/{id}/is-opened";
public static final String API_SOURCES_ID_PARAMS = "/api/sources/{id}/params";
public static final String API_SOURCES_ID_PARAMS_ID = "/api/sources/{id}/params/{paramId}";



public static final String API_SURVEYS_SEARCH = "/api/surveys/search";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fr.insee.survey.datacollectionmanagement.metadata.dto.SourceOnlineStatusDto;
import fr.insee.survey.datacollectionmanagement.metadata.service.*;
import fr.insee.survey.datacollectionmanagement.metadata.util.ParamValidator;
import fr.insee.survey.datacollectionmanagement.metadata.validation.ParameterEnumValid;
import fr.insee.survey.datacollectionmanagement.questioning.service.QuestioningService;
import fr.insee.survey.datacollectionmanagement.view.service.ViewService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -180,6 +181,14 @@ public ResponseEntity<List<ParamsDto>> getParams(@PathVariable("id") String id)
return ResponseEntity.ok().body(listParams);
}

@Operation(summary = "Get source parameters")
@GetMapping(value = Constants.API_SOURCES_ID_PARAMS_ID, produces = "application/json")
public ParamsDto getSourceParam(@PathVariable("id") String sourceId, @ParameterEnumValid @PathVariable("paramId") String paramId) {
Source source = sourceService.findById(StringUtils.upperCase(sourceId));
List<Parameters> listParams = source.getParams().stream().filter(parameters -> parameters.getParamId().name().equals(paramId)).toList();
return listParams.isEmpty() ? null : parametersService.convertToDto(listParams.get(0));
}


@Operation(summary = "Create a parameter for a source")
@PutMapping(value = Constants.API_SOURCES_ID_PARAMS, produces = "application/json")
Expand All @@ -189,7 +198,7 @@ public void putParams(@PathVariable("id") String id, @RequestBody @Valid ParamsD
ParamValidator.validateParams(paramsDto);
Parameters param = parametersService.convertToEntity(paramsDto);
param.setMetadataId(StringUtils.upperCase(id));
Set<Parameters> updatedParams = parametersService.updateSourceParams(source,param);
Set<Parameters> updatedParams = parametersService.updateSourceParams(source, param);
source.setParams(updatedParams);
sourceService.insertOrUpdateSource(source);
}
Expand All @@ -208,22 +217,12 @@ private Source convertToEntity(SourceOnlineStatusDto sourceOnlineStatusDto) {
return modelmapper.map(sourceOnlineStatusDto, Source.class);
}

class SourcePage extends PageImpl<SourceDto> {
static class SourcePage extends PageImpl<SourceDto> {

public SourcePage(List<SourceDto> content, Pageable pageable, long total) {
super(content, pageable, total);
}
}

private Parameters convertToEntity(ParamsDto paramsDto) {

Parameters params = modelmapper.map(paramsDto, Parameters.class);
params.setParamId(Parameters.ParameterEnum.valueOf(paramsDto.getParamId()));
return params;
}
private ParamsDto convertToDto(Parameters params) {
return modelmapper.map(params, ParamsDto.class);
}


}

0 comments on commit dfa392a

Please sign in to comment.