oc-catalog/controllers/datacenter.go
2024-07-30 10:07:34 +02:00

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