97 lines
2.6 KiB
Java
97 lines
2.6 KiB
Java
package tech.easyflow.manuagent.model;
|
|
|
|
import jakarta.validation.Valid;
|
|
import java.security.Principal;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
/**
|
|
* 提供模型配置与连接测试接口。
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/models")
|
|
public class ModelController {
|
|
|
|
private final ModelService modelService;
|
|
|
|
/**
|
|
* 创建模型控制器。
|
|
*
|
|
* @param modelService 模型服务
|
|
*/
|
|
public ModelController(ModelService modelService) {
|
|
this.modelService = modelService;
|
|
}
|
|
|
|
/**
|
|
* 列出模型。
|
|
*
|
|
* @return 模型列表
|
|
*/
|
|
@GetMapping
|
|
public List<ModelService.ModelView> list() {
|
|
return modelService.list();
|
|
}
|
|
|
|
/**
|
|
* 新增模型。
|
|
*
|
|
* @param input 模型输入
|
|
* @param principal 当前用户
|
|
* @return 新模型
|
|
*/
|
|
@PostMapping
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public ModelService.ModelView create(@Valid @RequestBody ModelService.ModelInput input, Principal principal) {
|
|
return modelService.save(null, input, principal);
|
|
}
|
|
|
|
/**
|
|
* 更新模型。
|
|
*
|
|
* @param id 模型 ID
|
|
* @param input 模型输入
|
|
* @param principal 当前用户
|
|
* @return 更新后的模型
|
|
*/
|
|
@PutMapping("/{id}")
|
|
public ModelService.ModelView update(
|
|
@PathVariable UUID id,
|
|
@Valid @RequestBody ModelService.ModelInput input,
|
|
Principal principal) {
|
|
return modelService.save(id, input, principal);
|
|
}
|
|
|
|
/**
|
|
* 测试模型连接。
|
|
*
|
|
* @param id 模型 ID
|
|
* @return 测试结果
|
|
*/
|
|
@PostMapping("/{id}/test")
|
|
public ModelService.ConnectionResult test(@PathVariable UUID id) {
|
|
return modelService.test(id);
|
|
}
|
|
|
|
/**
|
|
* 设置默认模型。
|
|
*
|
|
* @param id 模型 ID
|
|
* @param principal 当前用户
|
|
*/
|
|
@PostMapping("/{id}/default")
|
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
public void setDefault(@PathVariable UUID id, Principal principal) {
|
|
modelService.setDefault(id, principal);
|
|
}
|
|
}
|