oc-catalog/controllers/storage.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 storage
type StorageController struct {
beego.Controller
}
// @Title Update
// @Description create storages
// @Param id path string true "the storage id you want to get"
// @Param body body models.storage true "The storage content"
// @Success 200 {storage} models.storage
// @router /:id [put]
func (o *StorageController) 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.STORAGE_RESOURCE), res, id)
o.ServeJSON()
}
// @Title Get
// @Description find storage by key word
// @Param search path string true "the search you want to get"
// @Success 200 {storage} models.storage
// @router /:search [get]
func (o *StorageController) Search() {
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(search, oclib.LibDataEnum(oclib.STORAGE_RESOURCE))
o.ServeJSON()
}
// @Title Create
// @Description create storage
// @Param storage body json true "body for storage content (Json format)"
// @Success 200 {storage} models.storage
// @router / [post]
func (o *StorageController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.STORAGE_RESOURCE), res)
o.ServeJSON()
}
// @Title GetAll
// @Description find storage by id
// @Success 200 {storage} models.storage
// @router / [get]
func (o *StorageController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.STORAGE_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find storage by id
// @Param id path string true "the id you want to get"
// @Success 200 {storage} models.storage
// @router /:id [get]
func (o *StorageController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.STORAGE_RESOURCE), id)
o.ServeJSON()
}
// @Title Delete
// @Description delete the storage
// @Param id path string true "The id you want to delete"
// @Success 200 {storage} delete success!
// @router /:id [delete]
func (o *StorageController) Delete() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.STORAGE_RESOURCE), id)
o.ServeJSON()
}