This commit is contained in:
mr
2024-11-07 13:42:19 +01:00
parent 21b3041783
commit 5f5072f176
10 changed files with 182 additions and 177 deletions

82
controllers/compute.go Normal file
View File

@@ -0,0 +1,82 @@
package controllers
import (
"encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about compute
type ComputeController struct {
beego.Controller
}
// @Title Update
// @Description create computes
// @Param id path string true "the compute id you want to get"
// @Param body body models.compute true "The compute content"
// @Success 200 {compute} models.compute
// @router /:id [put]
func (o *ComputeController) 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.COMPUTE_RESOURCE), res, id)
o.ServeJSON()
}
// @Title Create
// @Description create compute
// @Param compute body json true "body for compute content (Json format)"
// @Success 200 {compute} models.compute
// @router / [post]
func (o *ComputeController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), res)
o.ServeJSON()
}
// @Title GetAll
// @Description find compute by id
// @Success 200 {compute} models.compute
// @router / [get]
func (o *ComputeController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find compute by key word
// @Param search path string true "the search you want to get"
// @Success 200 {compute} models.compute
// @router /search/:search [get]
func (o *ComputeController) Search() {
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.COMPUTE_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find compute by id
// @Param id path string true "the id you want to get"
// @Success 200 {compute} models.compute
// @router /:id [get]
func (o *ComputeController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), id)
o.ServeJSON()
}
// @Title Delete
// @Description delete the compute
// @Param id path string true "The id you want to delete"
// @Success 200 {compute} delete success!
// @router /:id [delete]
func (o *ComputeController) Delete() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), id)
o.ServeJSON()
}

View File

@@ -1,82 +0,0 @@
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(nil, 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()
}

View File

@@ -18,7 +18,7 @@ func (o *ResourceController) GetAll() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {
@@ -43,7 +43,7 @@ func (o *ResourceController) Search() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {
@@ -68,7 +68,7 @@ func (o *ResourceController) Get() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {
@@ -93,7 +93,7 @@ func (o *ResourceController) Delete() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {