oc-catalog/controllers/datacenter.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 datacenter
2024-07-26 13:07:25 +02:00
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 [get]
func (o *DatacenterController) Search() {
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(search, oclib.LibDataEnum(oclib.DATACENTER_RESOURCE))
o.ServeJSON()
}
2024-07-26 13:07:25 +02:00
// @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()
}