-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Supervision controller and service to be used by supervision tools #407
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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.CreatedStudyBasicInfos; | ||
import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; | ||
import org.gridsuite.study.server.service.StudyService; | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add author |
||
@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<List<SupervisionStudyInfos>> getStudyList() { | ||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getStudies()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.gridsuite.study.server.dto.supervision; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add licence header |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add author |
||
@NoArgsConstructor | ||
@Getter | ||
@ToString(callSuper = true) | ||
@Schema(description = "Supervision Study attributes") | ||
public class SupervisionStudyInfos extends StudyInfos { | ||
private UUID networkUuid; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.gridsuite.study.server.service; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add licence header |
||
|
||
import org.gridsuite.study.server.dto.CreatedStudyBasicInfos; | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add author |
||
public class SupervisionService { | ||
private final StudyRepository studyRepository; | ||
|
||
public SupervisionService (StudyRepository studyRepository) { | ||
this.studyRepository = studyRepository; | ||
} | ||
|
||
public List<SupervisionStudyInfos> getStudies() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add @transactional(readOnly) |
||
return studyRepository.findAll().stream() | ||
.map(SupervisionService::toSupervisionStudyInfos) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static SupervisionStudyInfos toSupervisionStudyInfos(StudyEntity entity) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toDto ? |
||
return SupervisionStudyInfos.builder() | ||
.id(entity.getId()) | ||
.caseFormat(entity.getCaseFormat()) | ||
.networkUuid(entity.getNetworkUuid()) | ||
.build(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add licence header