adapt on booking new struct + instance of a resource
This commit is contained in:
@@ -163,6 +163,7 @@ func (o *BookingController) Check() {
|
||||
// @Success 200 {object} models.object
|
||||
// @router / [post]
|
||||
func (o *BookingController) Post() {
|
||||
fmt.Println("POST")
|
||||
/*
|
||||
* This function is used to create a booking.
|
||||
* It takes the following parameters:
|
||||
@@ -173,7 +174,7 @@ func (o *BookingController) Post() {
|
||||
*/
|
||||
var resp booking.Booking
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000000), &resp)
|
||||
dc_id := resp.ResourceID
|
||||
// delete all previous bookings
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
|
||||
85
controllers/datacenter.go
Normal file
85
controllers/datacenter.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about workspace
|
||||
type DatacenterController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find booking by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {booking} models.booking
|
||||
// @router / [get]
|
||||
func (o *DatacenterController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
storages := oclib.NewRequest(oclib.LibDataEnum(oclib.STORAGE_RESOURCE), user, peerID, groups, nil).Search(&dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.creator_id": {{Operator: dbs.EQUAL.String(), Value: peerID}},
|
||||
},
|
||||
}, "", isDraft == "true")
|
||||
computes := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), user, peerID, groups, nil).Search(&dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.creator_id": {{Operator: dbs.EQUAL.String(), Value: peerID}},
|
||||
},
|
||||
}, "", isDraft == "true")
|
||||
storages.Data = append(storages.Data, computes.Data...)
|
||||
if storages.Err != "" {
|
||||
storages.Err += " - " + computes.Err
|
||||
}
|
||||
o.Data["json"] = storages
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find booking by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {booking} models.booking
|
||||
// @router /:id [get]
|
||||
func (o *DatacenterController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
storages := oclib.NewRequest(oclib.LibDataEnum(oclib.STORAGE_RESOURCE), user, peerID, groups, nil).Search(&dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.creator_id": {{Operator: dbs.EQUAL.String(), Value: peerID}},
|
||||
},
|
||||
}, "", isDraft == "true")
|
||||
if len(storages.Data) == 0 {
|
||||
computes := oclib.NewRequest(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), user, peerID, groups, nil).Search(&dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||
"abstractintanciatedresource.abstractresource.abstractobject.creator_id": {{Operator: dbs.EQUAL.String(), Value: peerID}},
|
||||
},
|
||||
}, "", isDraft == "true")
|
||||
if len(computes.Data) == 0 {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": computes.Code,
|
||||
"err": computes.Err,
|
||||
}
|
||||
} else {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": computes.Data[0],
|
||||
"code": computes.Code,
|
||||
"err": computes.Err,
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": storages.Data[0],
|
||||
"code": storages.Code,
|
||||
"err": storages.Err,
|
||||
}
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user