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,7 +167,7 @@ func (o *BookingController) Post() {
return
}
new := &b.Booking{
DatacenterResourceID: dc_id,
ComputeResourceID: dc_id,
WorkflowExecution: *exec,
}
// store the booking

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.4
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
)

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-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-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/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
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.ControllerComments{
Method: "Search",
Router: `/search/:search`,
Router: `/search/:start_date/:end_date`,
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: nil,

View File

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

View File

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