oc-catalog/controllers/workflow.go

83 lines
2.4 KiB
Go

package controllers
import (
"encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about workflow
type WorkflowController struct {
beego.Controller
}
// @Title Update
// @Description create workflows
// @Param id path string true "the workflow id you want to get"
// @Param body body models.workflow true "The workflow content"
// @Success 200 {workflow} models.workflow
// @router /:id [put]
func (o *WorkflowController) Put() {
// 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)
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE), res, id)
o.ServeJSON()
}
// @Title Get
// @Description find workflow by key word
// @Param search path string true "the search you want to get"
// @Success 200 {workflow} models.workflow
// @router /:search [get]
func (o *WorkflowController) Search() {
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(search, oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE))
o.ServeJSON()
}
// @Title Create
// @Description create workflow
// @Param workflow body json true "body for workflow content (Json format)"
// @Success 200 {workflow} models.workflow
// @router / [post]
func (o *WorkflowController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE), res)
o.ServeJSON()
}
// @Title GetAll
// @Description find workflow by id
// @Success 200 {workflow} models.workflow
// @router / [get]
func (o *WorkflowController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find workflow by id
// @Param id path string true "the id you want to get"
// @Success 200 {workflow} models.workflow
// @router /:id [get]
func (o *WorkflowController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE), id)
o.ServeJSON()
}
// @Title Delete
// @Description delete the workflow
// @Param id path string true "The id you want to delete"
// @Success 200 {workflow} delete success!
// @router /:id [delete]
func (o *WorkflowController) Delete() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE), id)
o.ServeJSON()
}