pcm-octopus/http/apis/trainjob.go

144 lines
3.2 KiB
Go

package apis
import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/JointCloud/pcm-octopus/http/common"
"gitlink.org.cn/JointCloud/pcm-octopus/http/model"
"gitlink.org.cn/JointCloud/pcm-octopus/http/service"
"net/http"
)
func CreateTrainJob(ctx *gin.Context) {
var param model.CreateTrainJobParam
if err := ctx.BindJSON(&param); err != nil {
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, err)
return
}
ip := ctx.Query(common.IPADDR)
if ip == "" {
model.Response(ctx, 401, "addr为必填字段", nil)
return
}
token := ctx.Query(common.ACCESSTOKEN)
if token == "" {
model.Response(ctx, 401, "token为必填字段", nil)
return
}
resp, err := service.CreateTrainJob(ip, token, &param)
if err != nil {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
}
if !resp.Success {
if resp.Error != nil {
model.Response(ctx, 500, common.INVOKEERROR, resp.Error)
return
}
}
model.Response(ctx, http.StatusOK, common.SUCCESS, resp.Payload)
}
func GetTrainJobList(ctx *gin.Context) {
var param model.TrainJobListParam
if err := ctx.BindJSON(&param); err != nil {
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, err)
return
}
ip := ctx.Query(common.IPADDR)
if ip == "" {
model.Response(ctx, 401, "addr为必填字段", nil)
return
}
token := ctx.Query(common.ACCESSTOKEN)
if token == "" {
model.Response(ctx, 401, "token为必填字段", nil)
return
}
resp, err := service.GetTrainJobList(ip, token, &param)
if err != nil {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
}
if !resp.Success {
if resp.Error != nil {
model.Response(ctx, 500, common.INVOKEERROR, resp.Error)
return
}
}
model.Response(ctx, http.StatusOK, common.SUCCESS, resp.Payload)
}
func TrainJobDetail(ctx *gin.Context) {
var param model.TrainJobDetailParam
if err := ctx.BindJSON(&param); err != nil {
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, err)
return
}
ip := ctx.Query(common.IPADDR)
if ip == "" {
model.Response(ctx, 401, "addr为必填字段", nil)
return
}
token := ctx.Query(common.ACCESSTOKEN)
if token == "" {
model.Response(ctx, 401, "token为必填字段", nil)
return
}
resp, err := service.TrainJobDetail(ip, token, &param)
if err != nil {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
}
if !resp.Success {
if resp.Error != nil {
model.Response(ctx, 500, common.INVOKEERROR, resp.Error)
return
}
}
model.Response(ctx, http.StatusOK, common.SUCCESS, resp.Payload)
}
func TrainJobLog(ctx *gin.Context) {
var param model.TrainJobLog
if err := ctx.BindJSON(&param); err != nil {
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, err)
return
}
ip := ctx.Query(common.IPADDR)
if ip == "" {
model.Response(ctx, 401, "addr为必填字段", nil)
return
}
token := ctx.Query(common.ACCESSTOKEN)
if token == "" {
model.Response(ctx, 401, "token为必填字段", nil)
return
}
resp, err := service.TrainJobLog(ip, token, &param)
if err != nil {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
}
if resp == "" {
model.Response(ctx, 500, common.INVOKEERROR, nil)
}
model.Response(ctx, http.StatusOK, common.SUCCESS, resp)
}