diff --git a/src/main/java/org/gridsuite/study/server/SupervisionController.java b/src/main/java/org/gridsuite/study/server/SupervisionController.java new file mode 100644 index 000000000..1b4a986a7 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/SupervisionController.java @@ -0,0 +1,33 @@ +package org.gridsuite.study.server; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; +import org.gridsuite.study.server.service.SupervisionService; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping(value = "/" + StudyApi.API_VERSION + "/supervision") +@Tag(name = "Study server - Supervision") +public class SupervisionController { + private final SupervisionService supervisionService; + + public SupervisionController(SupervisionService supervisionService) { + this.supervisionService = supervisionService; + } + + @GetMapping(value = "/studies") + @Operation(summary = "Get all studies") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of studies")}) + public ResponseEntity> getStudyList() { + return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getStudies()); + } +} diff --git a/src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java b/src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java new file mode 100644 index 000000000..e3296d0eb --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java @@ -0,0 +1,19 @@ +package org.gridsuite.study.server.dto.supervision; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.gridsuite.study.server.dto.StudyInfos; + +import java.util.UUID; + +@SuperBuilder +@NoArgsConstructor +@Getter +@ToString(callSuper = true) +@Schema(description = "Supervision Study attributes") +public class SupervisionStudyInfos extends StudyInfos { + private UUID networkUuid; +} diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java new file mode 100644 index 000000000..8149b7da6 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -0,0 +1,33 @@ +package org.gridsuite.study.server.service; + +import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; +import org.gridsuite.study.server.repository.StudyEntity; +import org.gridsuite.study.server.repository.StudyRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class SupervisionService { + private final StudyRepository studyRepository; + + public SupervisionService(StudyRepository studyRepository) { + this.studyRepository = studyRepository; + } + + public List getStudies() { + return studyRepository.findAll().stream() + .map(SupervisionService::toSupervisionStudyInfos) + .collect(Collectors.toList()); + } + + private static SupervisionStudyInfos toSupervisionStudyInfos(StudyEntity entity) { + return SupervisionStudyInfos.builder() + .id(entity.getId()) + .caseFormat(entity.getCaseFormat()) + .networkUuid(entity.getNetworkUuid()) + .build(); + } + +}