Merge pull request '算法生命周期管理' (#10) from my-feature-one into main
Reviewed-on: #10
This commit is contained in:
@ -0,0 +1,60 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/algorithm")
|
||||
public class AlgorithmInfoController {
|
||||
|
||||
@Autowired
|
||||
private AlgorithmInfoService algorithmInfoService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<AlgorithmInfo> getById(@PathVariable Long id) {
|
||||
AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id);
|
||||
return algorithmInfo != null ?
|
||||
ResponseEntity.ok(algorithmInfo) :
|
||||
ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping("/name/{algorithmName}")
|
||||
public ResponseEntity<AlgorithmInfo> getByName(@PathVariable String algorithmName) {
|
||||
AlgorithmInfo algorithmInfo = algorithmInfoService.getByName(algorithmName);
|
||||
return algorithmInfo != null ?
|
||||
ResponseEntity.ok(algorithmInfo) :
|
||||
ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping("/type/{algorithmType}")
|
||||
public ResponseEntity<List<AlgorithmInfo>> getByType(@PathVariable String algorithmType) {
|
||||
List<AlgorithmInfo> algorithmInfos = algorithmInfoService.getByType(algorithmType);
|
||||
return ResponseEntity.ok(algorithmInfos);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<String> update(@PathVariable Long id, @RequestBody AlgorithmInfo algorithmInfo) {
|
||||
algorithmInfo.setId(id);
|
||||
if (!algorithmInfoService.validateAlgorithmInfo(algorithmInfo)) {
|
||||
return ResponseEntity.badRequest().body("Invalid algorithm information");
|
||||
}
|
||||
|
||||
boolean success = algorithmInfoService.update(algorithmInfo);
|
||||
return success ?
|
||||
ResponseEntity.ok("Update successful") :
|
||||
ResponseEntity.badRequest().body("Update failed");
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<String> delete(@PathVariable Long id) {
|
||||
boolean success = algorithmInfoService.delete(id);
|
||||
return success ?
|
||||
ResponseEntity.ok("Delete successful") :
|
||||
ResponseEntity.badRequest().body("Delete failed");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user