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"
|
|
|
|
)
|
|
|
|
|
2024-07-26 14:39:57 +02:00
|
|
|
// Operations about storage
|
2024-07-26 13:07:25 +02:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2024-07-26 14:39:57 +02:00
|
|
|
// @Title Get
|
|
|
|
// @Description find storage by key word
|
|
|
|
// @Param search path string true "the search you want to get"
|
|
|
|
// @Success 200 {storage} models.storage
|
2024-07-30 10:07:34 +02:00
|
|
|
// @router /search/:search [get]
|
2024-07-26 14:39:57 +02:00
|
|
|
func (o *StorageController) 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.STORAGE_RESOURCE))
|
2024-07-26 14:39:57 +02:00
|
|
|
o.ServeJSON()
|
|
|
|
}
|
|
|
|
|
2024-07-26 13:07:25 +02:00
|
|
|
// @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()
|
|
|
|
}
|