oc-catalog/controllers/processing.go

83 lines
2.5 KiB
Go
Raw Normal View History

2024-07-26 13:07:25 +02:00
package controllers
import (
"encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about processing
2024-07-26 13:07:25 +02:00
type ProcessingController struct {
beego.Controller
}
// @Title Update
// @Description create processings
// @Param id path string true "the processing id you want to get"
// @Param body body models.processing true "The processing content"
// @Success 200 {processing} models.processing
// @router /:id [put]
func (o *ProcessingController) 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.PROCESSING_RESOURCE), res, id)
o.ServeJSON()
}
// @Title Create
// @Description create processing
// @Param processing body json true "body for processing content (Json format)"
// @Success 200 {processing} models.processing
// @router / [post]
func (o *ProcessingController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.PROCESSING_RESOURCE), res)
o.ServeJSON()
}
// @Title GetAll
// @Description find processing by id
// @Success 200 {processing} models.processing
// @router / [get]
func (o *ProcessingController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.PROCESSING_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find processing by key word
// @Param search path string true "the search you want to get"
// @Success 200 {processing} models.processing
2024-07-30 10:07:34 +02:00
// @router /search/:search [get]
func (o *ProcessingController) Search() {
search := o.Ctx.Input.Param(":search")
2024-08-01 09:27:38 +02:00
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.PROCESSING_RESOURCE))
o.ServeJSON()
}
2024-07-26 13:07:25 +02:00
// @Title Get
// @Description find processing by id
// @Param id path string true "the id you want to get"
// @Success 200 {processing} models.processing
// @router /:id [get]
func (o *ProcessingController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.PROCESSING_RESOURCE), id)
o.ServeJSON()
}
// @Title Delete
// @Description delete the processing
// @Param id path string true "The id you want to delete"
// @Success 200 {processing} delete success!
// @router /:id [delete]
func (o *ProcessingController) Delete() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.PROCESSING_RESOURCE), id)
o.ServeJSON()
}