72 lines
2.1 KiB
Go
72 lines
2.1 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 data
|
|
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 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()
|
|
}
|