添加普通根据功能获取模型列表
This commit is contained in:
parent
2e2fbf60a0
commit
5592e47f72
|
|
@ -3,7 +3,6 @@ package handler
|
||||||
import (
|
import (
|
||||||
"StuAcaWorksAI/proto"
|
"StuAcaWorksAI/proto"
|
||||||
"StuAcaWorksAI/service"
|
"StuAcaWorksAI/service"
|
||||||
"encoding/json"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
@ -22,12 +21,12 @@ type FunctionModelIDs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type FuncModelReq struct {
|
type FuncModelReq struct {
|
||||||
ID int `json:"id" form:"id"`
|
ID int `json:"id" form:"id"`
|
||||||
ModelID int `json:"model_id" form:"model_id"`
|
ModelID int `json:"model_id" form:"model_id"`
|
||||||
Function string `json:"function" form:"function"`
|
Function string `json:"function" form:"function"`
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Info string `json:"info" form:"info"`
|
Info string `json:"info" form:"info"`
|
||||||
ModelIDS []FunctionModelIDs `json:"model_ids" form:"model_ids"`
|
ModelIDS string `json:"model_ids" form:"model_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFuncModel(c *gin.Context) {
|
func CreateFuncModel(c *gin.Context) {
|
||||||
|
|
@ -35,13 +34,13 @@ func CreateFuncModel(c *gin.Context) {
|
||||||
userID := int(id.(float64))
|
userID := int(id.(float64))
|
||||||
var req FuncModelReq
|
var req FuncModelReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
modelIDs, err3 := json.Marshal(req.ModelIDS)
|
//modelIDs, err3 := json.Marshal(req.ModelIDS)
|
||||||
if err3 != nil {
|
//if err3 != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
|
// c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
// 创建功能模型
|
// 创建功能模型
|
||||||
err2, mid := service.CreateFuncModel(int(uint(userID)), req.ModelID, req.Name, req.Info, req.Function, string(modelIDs))
|
err2, mid := service.CreateFuncModel(int(uint(userID)), req.ModelID, req.Name, req.Info, req.Function, req.ModelIDS)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": mid})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": mid})
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -84,13 +83,13 @@ func UpdateFuncModel(c *gin.Context) {
|
||||||
userID := int(id.(float64))
|
userID := int(id.(float64))
|
||||||
var req FuncModelReq
|
var req FuncModelReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
modelIDs, err3 := json.Marshal(req.ModelIDS)
|
//modelIDs, err3 := json.Marshal(req.ModelIDS)
|
||||||
if err3 != nil {
|
//if err3 != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
|
// c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
// 修改功能模型
|
// 修改功能模型
|
||||||
err2 := service.UpdateFuncModelByID(req.ID, uint(userID), uint(req.ModelID), req.Name, req.Info, req.Function, string(modelIDs))
|
err2 := service.UpdateFuncModelByID(req.ID, uint(userID), uint(req.ModelID), req.Name, req.Info, req.Function, req.ModelIDS)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue