You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.0 KiB
80 lines
3.0 KiB
|
9 months ago
|
package kr.re.etri.autoflow.controllers;
|
||
|
|
|
||
|
|
import io.swagger.v3.oas.annotations.Operation;
|
||
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
||
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
|
|
import kr.re.etri.autoflow.entity.ExperimentsEntity;
|
||
|
|
import kr.re.etri.autoflow.payload.request.ProjectBaseSearchRequest;
|
||
|
|
import kr.re.etri.autoflow.service.ExperimentsService;
|
||
|
|
import lombok.RequiredArgsConstructor;
|
||
|
|
import org.springdoc.core.annotations.ParameterObject;
|
||
|
|
import org.springframework.data.domain.Page;
|
||
|
|
import org.springframework.http.ResponseEntity;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Tag(name = "Experiments", description = "Kubeflow 및 MLflow Experiment API")
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/experiments")
|
||
|
|
@RequiredArgsConstructor
|
||
|
|
public class ExperimentsController {
|
||
|
|
|
||
|
|
private final ExperimentsService experimentsService;
|
||
|
|
|
||
|
|
@Operation(summary = "모든 Experiments 조회")
|
||
|
|
@GetMapping
|
||
|
|
public ResponseEntity<List<ExperimentsEntity>> getAllExperiments() {
|
||
|
|
return ResponseEntity.ok(experimentsService.findAll());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "Experiment 단건 조회")
|
||
|
|
@GetMapping("/{id}")
|
||
|
|
public ResponseEntity<ExperimentsEntity> getExperiment(
|
||
|
|
@Parameter(description = "Experiment ID", example = "1") @PathVariable("id") Long id) {
|
||
|
|
|
||
|
|
return experimentsService.findById(id)
|
||
|
|
.map(ResponseEntity::ok)
|
||
|
|
.orElse(ResponseEntity.notFound().build());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "Experiment 검색 및 페이지네이션")
|
||
|
|
@GetMapping("/search")
|
||
|
|
public ResponseEntity<Page<ExperimentsEntity>> searchExperiments(
|
||
|
|
@ParameterObject @ModelAttribute ProjectBaseSearchRequest request) {
|
||
|
|
Page<ExperimentsEntity> page = experimentsService.search(request);
|
||
|
|
return ResponseEntity.ok(page);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "Experiment 등록")
|
||
|
|
@PostMapping
|
||
|
|
public ResponseEntity<ExperimentsEntity> createExperiment(@RequestBody ExperimentsEntity experiment) {
|
||
|
|
return ResponseEntity.ok(experimentsService.save(experiment));
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "Experiment 수정")
|
||
|
|
@PutMapping("/{id}")
|
||
|
|
public ResponseEntity<ExperimentsEntity> updateExperiment(
|
||
|
|
@Parameter(description = "Experiment ID", example = "1") @PathVariable("id") Long id,
|
||
|
|
@RequestBody ExperimentsEntity experiment) {
|
||
|
|
|
||
|
|
return experimentsService.findById(id)
|
||
|
|
.map(existing -> {
|
||
|
|
experiment.setId(id);
|
||
|
|
return ResponseEntity.ok(experimentsService.save(experiment));
|
||
|
|
})
|
||
|
|
.orElse(ResponseEntity.notFound().build());
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "Experiment 삭제")
|
||
|
|
@DeleteMapping("/{id}")
|
||
|
|
public ResponseEntity<Void> deleteExperiment(
|
||
|
|
@Parameter(description = "Experiment ID", example = "1") @PathVariable("id") Long id) {
|
||
|
|
|
||
|
|
if (experimentsService.deleteById(id)) {
|
||
|
|
return ResponseEntity.noContent().build();
|
||
|
|
}
|
||
|
|
return ResponseEntity.notFound().build();
|
||
|
|
}
|
||
|
|
}
|