diff --git a/src/main/java/io/redlink/more/data/controller/ExternalDataApiV1Controller.java b/src/main/java/io/redlink/more/data/controller/ExternalDataApiV1Controller.java index 33d510f..f603cdb 100644 --- a/src/main/java/io/redlink/more/data/controller/ExternalDataApiV1Controller.java +++ b/src/main/java/io/redlink/more/data/controller/ExternalDataApiV1Controller.java @@ -13,7 +13,7 @@ import io.redlink.more.data.api.app.v1.model.ParticipantDTO; import io.redlink.more.data.api.app.v1.webservices.ExternalDataApi; import io.redlink.more.data.controller.transformer.DataTransformer; -import io.redlink.more.data.controller.transformer.StudyTransformer; +import io.redlink.more.data.controller.transformer.ParticipantTransformer; import io.redlink.more.data.exception.BadRequestException; import io.redlink.more.data.model.ApiRoutingInfo; import io.redlink.more.data.model.RoutingInfo; @@ -51,7 +51,7 @@ public ResponseEntity> listParticipants(String moreApiToken return ResponseEntity.ok( externalService.listParticipants(apiRoutingInfo.studyId(), apiRoutingInfo.studyGroupId()) .stream() - .map(StudyTransformer::toDTO) + .map(ParticipantTransformer::toDTO) .toList() ); } catch(IndexOutOfBoundsException | NumberFormatException e) { diff --git a/src/main/java/io/redlink/more/data/controller/transformer/ParticipantTransformer.java b/src/main/java/io/redlink/more/data/controller/transformer/ParticipantTransformer.java new file mode 100644 index 0000000..c59ade1 --- /dev/null +++ b/src/main/java/io/redlink/more/data/controller/transformer/ParticipantTransformer.java @@ -0,0 +1,23 @@ +package io.redlink.more.data.controller.transformer; + +import io.redlink.more.data.api.app.v1.model.ParticipantDTO; +import io.redlink.more.data.api.app.v1.model.ParticipantStatusDTO; +import io.redlink.more.data.model.Participant; + +public final class ParticipantTransformer { + + private ParticipantTransformer() {} + + public static ParticipantDTO toDTO(Participant participant) { + if(participant == null) { + return null; + } + return new ParticipantDTO( + String.valueOf(participant.id()), + participant.alias(), + ParticipantStatusDTO.fromValue(participant.status()), + participant.studyGroupId(), + BaseTransformers.toOffsetDateTime(participant.start()) + ); + } +} diff --git a/src/main/java/io/redlink/more/data/controller/transformer/StudyTransformer.java b/src/main/java/io/redlink/more/data/controller/transformer/StudyTransformer.java index 801b3e4..d46a2df 100644 --- a/src/main/java/io/redlink/more/data/controller/transformer/StudyTransformer.java +++ b/src/main/java/io/redlink/more/data/controller/transformer/StudyTransformer.java @@ -41,19 +41,6 @@ public static SimpleParticipantDTO toDTO(SimpleParticipant participant) { .alias(participant.alias()); } - public static ParticipantDTO toDTO(Participant participant) { - if(participant == null) { - return null; - } - return new ParticipantDTO( - participant.id(), - participant.alias(), - ParticipantStatusDTO.fromValue(participant.status()), - participant.studyGroupId(), - BaseTransformers.toOffsetDateTime(participant.start()) - ); - } - public static ContactInfoDTO toDTO(Contact contact) { return new ContactInfoDTO() .institute(contact.institute()) diff --git a/src/main/java/io/redlink/more/data/repository/StudyRepository.java b/src/main/java/io/redlink/more/data/repository/StudyRepository.java index 09b52cf..76de2ca 100644 --- a/src/main/java/io/redlink/more/data/repository/StudyRepository.java +++ b/src/main/java/io/redlink/more/data/repository/StudyRepository.java @@ -84,11 +84,7 @@ public class StudyRepository { private static final String SQL_LIST_PARTICIPANTS_BY_STUDY = "SELECT participant_id, alias, status, study_group_id, start FROM participants " + - "WHERE study_id = ?"; - - private static final String SQL_LIST_PARTICIPANTS_BY_STUDY_AND_GROUP = - "SELECT participant_id, alias, status, study_group_id, start FROM participants " + - "WHERE study_id = ? AND study_group_id = ?"; + "WHERE study_id = :study_id AND (study_group_id = :study_group_id OR :study_group_id::INT IS NULL)"; private static final String GET_OBSERVATION_PROPERTIES_FOR_PARTICIPANT = "SELECT properties FROM participant_observation_properties " + @@ -202,9 +198,19 @@ public Optional findParticipant(RoutingInfo routingInfo) { public List listParticipants(long studyId, int groupId) { if(groupId < 0) { - return jdbcTemplate.query(SQL_LIST_PARTICIPANTS_BY_STUDY, getParticipantRowMapper(), studyId); + return namedTemplate.query( + SQL_LIST_PARTICIPANTS_BY_STUDY, + new MapSqlParameterSource() + .addValue("study_id", studyId) + .addValue("study_group_id", null), + getParticipantRowMapper()); } else { - return jdbcTemplate.query(SQL_LIST_PARTICIPANTS_BY_STUDY_AND_GROUP, getParticipantRowMapper(), studyId, groupId); + return namedTemplate.query( + SQL_LIST_PARTICIPANTS_BY_STUDY, + new MapSqlParameterSource() + .addValue("study_id", studyId) + .addValue("study_group_id", groupId), + getParticipantRowMapper()); } } diff --git a/src/main/resources/openapi/ExternalAPI.yaml b/src/main/resources/openapi/ExternalAPI.yaml index 2fb6ea8..b125496 100644 --- a/src/main/resources/openapi/ExternalAPI.yaml +++ b/src/main/resources/openapi/ExternalAPI.yaml @@ -113,8 +113,7 @@ components: description: A participant for a study properties: participantId: - type: integer - format: int32 + type: string alias: type: string status: