neo datacenter

This commit is contained in:
mr
2024-11-13 08:10:20 +01:00
parent 38e7910e09
commit fe42651686
6 changed files with 59 additions and 22 deletions

View File

@@ -11,6 +11,7 @@ import (
b "cloud.o-forge.io/core/oc-lib/models/booking"
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
beego "github.com/beego/beego/v2/server/web"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Operations about workspace
@@ -19,14 +20,32 @@ type BookingController struct {
}
// @Title Search
// @Description search booking
// @Param search path string true "the word search you want to get"
// @Success 200 {booking} models.booking
// @router /search/:search [get]
// @Description search bookings
// @Param start_date path string true "the word search you want to get"
// @Param end_date path string true "the word search you want to get"
// @Success 200 {workspace} models.workspace
// @router /search/:start_date/:end_date [get]
func (o *BookingController) Search() {
/*
* This is a sample of how to use the search function
* The search function is used to search for data in the database
* The search function takes in a filter and a data type
* The filter is a struct that contains the search parameters
* The data type is an enum that specifies the type of data to search for
* The search function returns a list of data that matches the filter
* The data is then returned as a json object
*/
// store and return Id or post with UUID
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.BOOKING))
start_date, _ := time.Parse("2006-01-02", o.Ctx.Input.Param(":start_date"))
end_date, _ := time.Parse("2006-01-02", o.Ctx.Input.Param(":end_date"))
sd := primitive.NewDateTimeFromTime(start_date)
ed := primitive.NewDateTimeFromTime(end_date)
f := dbs.Filters{
And: map[string][]dbs.Filter{
"workflowexecution.execution_date": {{Operator: "gte", Value: sd}, {Operator: "lte", Value: ed}},
},
}
o.Data["json"] = oclib.Search(&f, "", oclib.LibDataEnum(oclib.BOOKING))
o.ServeJSON()
}
@@ -148,8 +167,8 @@ func (o *BookingController) Post() {
return
}
new := &b.Booking{
DatacenterResourceID: dc_id,
WorkflowExecution: *exec,
ComputeResourceID: dc_id,
WorkflowExecution: *exec,
}
// store the booking
b := oclib.StoreOne(oclib.LibDataEnum(oclib.BOOKING), new.Serialize())