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 data
|
|
|
|
type DataController struct {
|
|
|
|
beego.Controller
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Title Update
|
|
|
|
// @Description create datas
|
|
|
|
// @Param id path string true "the data id you want to get"
|
|
|
|
// @Param body body models.data true "The data content"
|
|
|
|
// @Success 200 {data} models.data
|
|
|
|
// @router /:id [put]
|
|
|
|
func (o *DataController) 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.DATA_RESOURCE), res, id)
|
|
|
|
o.ServeJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Title Create
|
|
|
|
// @Description create data
|
|
|
|
// @Param data body json true "body for data content (Json format)"
|
|
|
|
// @Success 200 {data} models.data
|
|
|
|
// @router / [post]
|
|
|
|
func (o *DataController) Post() {
|
|
|
|
var res map[string]interface{}
|
|
|
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
|
|
|
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.DATA_RESOURCE), res)
|
|
|
|
o.ServeJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Title GetAll
|
|
|
|
// @Description find data by id
|
|
|
|
// @Success 200 {data} models.data
|
|
|
|
// @router / [get]
|
|
|
|
func (o *DataController) GetAll() {
|
|
|
|
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.DATA_RESOURCE))
|
|
|
|
o.ServeJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Title Get
|
2024-07-26 14:39:57 +02:00
|
|
|
// @Description find data by key word
|
|
|
|
// @Param search path string true "the search you want to get"
|
|
|
|
// @Success 200 {data} models.data
|
2024-07-30 10:07:34 +02:00
|
|
|
// @router /search/:search [get]
|
2024-07-26 14:39:57 +02:00
|
|
|
func (o *DataController) 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.DATA_RESOURCE))
|
2024-07-26 14:39:57 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Title Get
|
|
|
|
// @Description find data by id
|
2024-07-26 13:07:25 +02:00
|
|
|
// @Param id path string true "the id you want to get"
|
|
|
|
// @Success 200 {data} models.data
|
|
|
|
// @router /:id [get]
|
|
|
|
func (o *DataController) Get() {
|
|
|
|
id := o.Ctx.Input.Param(":id")
|
|
|
|
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.DATA_RESOURCE), id)
|
|
|
|
o.ServeJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Title Delete
|
|
|
|
// @Description delete the data
|
|
|
|
// @Param id path string true "The id you want to delete"
|
|
|
|
// @Success 200 {data} delete success!
|
|
|
|
// @router /:id [delete]
|
|
|
|
func (o *DataController) Delete() {
|
|
|
|
id := o.Ctx.Input.Param(":id")
|
|
|
|
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.DATA_RESOURCE), id)
|
|
|
|
o.ServeJSON()
|
|
|
|
}
|