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" b "cloud.o-forge.io/core/oc-lib/models/booking"
"cloud.o-forge.io/core/oc-lib/models/workflow_execution" "cloud.o-forge.io/core/oc-lib/models/workflow_execution"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
"go.mongodb.org/mongo-driver/bson/primitive"
) )
// Operations about workspace // Operations about workspace
@ -19,14 +20,32 @@ type BookingController struct {
} }
// @Title Search // @Title Search
// @Description search booking // @Description search bookings
// @Param search path string true "the word search you want to get" // @Param start_date path string true "the word search you want to get"
// @Success 200 {booking} models.booking // @Param end_date path string true "the word search you want to get"
// @router /search/:search [get] // @Success 200 {workspace} models.workspace
// @router /search/:start_date/:end_date [get]
func (o *BookingController) Search() { 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 // store and return Id or post with UUID
search := o.Ctx.Input.Param(":search") start_date, _ := time.Parse("2006-01-02", o.Ctx.Input.Param(":start_date"))
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.BOOKING)) 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() o.ServeJSON()
} }
@ -148,8 +167,8 @@ func (o *BookingController) Post() {
return return
} }
new := &b.Booking{ new := &b.Booking{
DatacenterResourceID: dc_id, ComputeResourceID: dc_id,
WorkflowExecution: *exec, WorkflowExecution: *exec,
} }
// store the booking // store the booking
b := oclib.StoreOne(oclib.LibDataEnum(oclib.BOOKING), new.Serialize()) b := oclib.StoreOne(oclib.LibDataEnum(oclib.BOOKING), new.Serialize())

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.4 toolchain go1.22.4
require ( require (
cloud.o-forge.io/core/oc-lib v0.0.0-20241108104423-7fd44a55cb28 cloud.o-forge.io/core/oc-lib v0.0.0-20241112141026-06c3af5d4d61
github.com/beego/beego/v2 v2.3.1 github.com/beego/beego/v2 v2.3.1
) )

6
go.sum
View File

@ -18,6 +18,12 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20241107122526-f3df1e42b9ba h1:MGd8N7bY1LWXM
cloud.o-forge.io/core/oc-lib v0.0.0-20241107122526-f3df1e42b9ba/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo= cloud.o-forge.io/core/oc-lib v0.0.0-20241107122526-f3df1e42b9ba/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
cloud.o-forge.io/core/oc-lib v0.0.0-20241108104423-7fd44a55cb28 h1:jekSPkD/b59kJ9Bp/trBWnahkdd1FkX4csQOcSaZa8I= cloud.o-forge.io/core/oc-lib v0.0.0-20241108104423-7fd44a55cb28 h1:jekSPkD/b59kJ9Bp/trBWnahkdd1FkX4csQOcSaZa8I=
cloud.o-forge.io/core/oc-lib v0.0.0-20241108104423-7fd44a55cb28/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo= cloud.o-forge.io/core/oc-lib v0.0.0-20241108104423-7fd44a55cb28/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
cloud.o-forge.io/core/oc-lib v0.0.0-20241112123618-6497e7dbdd51 h1:AlOfOFWKVC/lUpLfCbw/QeQ5Epax/bK+ltZSr5vzUe0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241112123618-6497e7dbdd51/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
cloud.o-forge.io/core/oc-lib v0.0.0-20241112134441-8a21a7c803de h1:faiwXaNsohYkPILHr21la3j2lnSsr1crPBeTteo2zqE=
cloud.o-forge.io/core/oc-lib v0.0.0-20241112134441-8a21a7c803de/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
cloud.o-forge.io/core/oc-lib v0.0.0-20241112141026-06c3af5d4d61 h1:wAuOQAbv2uAie1QulHvbBzlZWMUE6hQ0kjhnP4OXFqQ=
cloud.o-forge.io/core/oc-lib v0.0.0-20241112141026-06c3af5d4d61/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I= github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo= github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo=

View File

@ -46,7 +46,7 @@ func init() {
beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"] = append(beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"], beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"] = append(beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"],
beego.ControllerComments{ beego.ControllerComments{
Method: "Search", Method: "Search",
Router: `/search/:search`, Router: `/search/:start_date/:end_date`,
AllowHTTPMethods: []string{"get"}, AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(), MethodParams: param.Make(),
Filters: nil, Filters: nil,

View File

@ -9,8 +9,8 @@
"email": "admin@o-cloud.io" "email": "admin@o-cloud.io"
}, },
"license": { "license": {
"name": "MIT", "name": "AGPL",
"url": "https://opensource.org/license/mit" "url": "https://www.gnu.org/licenses/agpl-3.0.html"
} }
}, },
"basePath": "/oc/", "basePath": "/oc/",
@ -95,17 +95,24 @@
} }
} }
}, },
"/booking/search/{search}": { "/booking/search/{start_date}/{end_date}": {
"get": { "get": {
"tags": [ "tags": [
"booking" "booking"
], ],
"description": "search booking\n\u003cbr\u003e", "description": "search bookings\n\u003cbr\u003e",
"operationId": "BookingController.Search", "operationId": "BookingController.Search",
"parameters": [ "parameters": [
{ {
"in": "path", "in": "path",
"name": "search", "name": "start_date",
"description": "the word search you want to get",
"required": true,
"type": "string"
},
{
"in": "path",
"name": "end_date",
"description": "the word search you want to get", "description": "the word search you want to get",
"required": true, "required": true,
"type": "string" "type": "string"
@ -113,7 +120,7 @@
], ],
"responses": { "responses": {
"200": { "200": {
"description": "{booking} models.booking" "description": "{workspace} models.workspace"
} }
} }
} }

View File

@ -8,8 +8,8 @@ info:
contact: contact:
email: admin@o-cloud.io email: admin@o-cloud.io
license: license:
name: MIT name: AGPL
url: https://opensource.org/license/mit url: https://www.gnu.org/licenses/agpl-3.0.html
basePath: /oc/ basePath: /oc/
paths: paths:
/booking/: /booking/:
@ -88,23 +88,28 @@ paths:
description: "" description: ""
schema: schema:
$ref: '#/definitions/models.object' $ref: '#/definitions/models.object'
/booking/search/{search}: /booking/search/{start_date}/{end_date}:
get: get:
tags: tags:
- booking - booking
description: |- description: |-
search booking search bookings
<br> <br>
operationId: BookingController.Search operationId: BookingController.Search
parameters: parameters:
- in: path - in: path
name: search name: start_date
description: the word search you want to get
required: true
type: string
- in: path
name: end_date
description: the word search you want to get description: the word search you want to get
required: true required: true
type: string type: string
responses: responses:
"200": "200":
description: '{booking} models.booking' description: '{workspace} models.workspace'
/version/: /version/:
get: get:
tags: tags: