69 lines
2.5 KiB
Go
69 lines
2.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"oc-scheduler/infrastructure"
|
|
|
|
oclib "cloud.o-forge.io/core/oc-lib"
|
|
"cloud.o-forge.io/core/oc-lib/models/execution_verification"
|
|
"cloud.o-forge.io/core/oc-lib/models/resources/native_tools"
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
)
|
|
|
|
// Operations about workspace
|
|
type ExecutionVerificationController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
// @Title GetAll
|
|
// @Description find verification by id
|
|
// @Param is_draft query string false "draft wished"
|
|
// @Success 200 {booking} models.booking
|
|
// @router / [get]
|
|
func (o *ExecutionVerificationController) GetAll() {
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
|
isDraft := o.Ctx.Input.Query("is_draft")
|
|
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.EXECUTION_VERIFICATION), user, peerID, groups, nil).LoadAll(isDraft == "true")
|
|
o.ServeJSON()
|
|
}
|
|
|
|
// @Title Get
|
|
// @Description find verification by id
|
|
// @Param id path string true "the id you want to get"
|
|
// @Success 200 {booking} models.booking
|
|
// @router /:id [get]
|
|
func (o *ExecutionVerificationController) Get() {
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
|
id := o.Ctx.Input.Param(":id")
|
|
o.Data["json"] = oclib.NewRequest(oclib.LibDataEnum(oclib.EXECUTION_VERIFICATION), user, peerID, groups, nil).LoadOne(id)
|
|
o.ServeJSON()
|
|
}
|
|
|
|
// @Title Update
|
|
// @Description create computes
|
|
// @Param id path string true "the compute id you want to get"
|
|
// @Param body body models.compute true "The compute content"
|
|
// @Success 200 {compute} models.compute
|
|
// @router /:id [put]
|
|
func (o *ExecutionVerificationController) Put() {
|
|
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
|
// store and return Id or post with UUID
|
|
var res map[string]interface{}
|
|
id := o.Ctx.Input.Param(":id")
|
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
|
data := oclib.NewRequest(oclib.LibDataEnum(oclib.EXECUTION_VERIFICATION), user, peerID, groups, nil).UpdateOne(res, id)
|
|
if data.Err == "" && data.Data != nil && data.Data.(*execution_verification.ExecutionVerification).Validate {
|
|
data, _ := json.Marshal(&native_tools.WorkflowEventParams{
|
|
WorkflowResourceID: data.Data.(*execution_verification.ExecutionVerification).WorkflowID,
|
|
})
|
|
infrastructure.EmitNATS(peerID, tools.PropalgationMessage{
|
|
Action: tools.PubSubAction(tools.WORKFLOW_EVENT),
|
|
DataType: tools.EXECUTION_VERIFICATION.EnumIndex(),
|
|
Payload: data,
|
|
})
|
|
}
|
|
o.Data["json"] = data
|
|
o.ServeJSON()
|
|
}
|