生命周期

This commit is contained in:
2025-05-16 23:21:04 +08:00
parent 64abd2d824
commit 84b9711c57
5 changed files with 247 additions and 0 deletions

View File

@ -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");
}
}