diff --git a/controllers/booking.go b/controllers/booking.go index 5b248ee..e5e0049 100644 --- a/controllers/booking.go +++ b/controllers/booking.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "time" - + "fmt" oclib "cloud.o-forge.io/core/oc-lib" "cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/models/booking" @@ -52,12 +52,14 @@ func (o *BookingController) Get() { // @Title Check // @Description check booking +// @Param id path string "id of the datacenter" // @Param start_date path string "the booking start date" format "2006-01-02T15:04:05" // @Param end_date path string "the booking end date" format "2006-01-02T15:04:05" // @Success 200 {object} models.object -// @router /check/:start_date/:end_date [get] +// @router /check/:id/:start_date/:end_date [get] func (o *BookingController) Check() { // store and return Id or post with UUID + id := o.Ctx.Input.Param(":id") date, err := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":start_date")) date2, err2 := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":end_date")) if err != nil || err2 != nil { @@ -70,7 +72,7 @@ func (o *BookingController) Check() { } } else { booking := &b.Booking{} - isAvailable, err2 := booking.CheckBooking(date, &date2) + isAvailable, err2 := booking.CheckBooking(id, date, &date2) code := 200 err := "" if !isAvailable { @@ -120,7 +122,7 @@ func (o *BookingController) Post() { books := make([]interface{}, 0) errormsg := "" for _, exec := range resp.Executions { - if ok, _ := (&booking.Booking{}).CheckBooking(*exec.ExecDate, exec.EndDate); !ok { + if ok, _ := (&booking.Booking{}).CheckBooking(dc_id, *exec.ExecDate, exec.EndDate); !ok { res.Err += " -> the booking from " + exec.ExecDate.String() + " is already taken." o.Data["json"] = map[string]interface{}{ "data": nil, diff --git a/go.mod b/go.mod index ab90244..5b46ad4 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 // indirect + cloud.o-forge.io/core/oc-lib v0.0.0-20240823210057-8e80fa88beeb // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/beego/bee/v2 v2.1.0 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index b0f3136..2b08d4d 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,10 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240813123326-2d9b4587ac95 h1:YxgRbjwoBYMW/ cloud.o-forge.io/core/oc-lib v0.0.0-20240813123326-2d9b4587ac95/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 h1:sYveE1C/0mpSr+ZmOYxuZ3fTWID7mr5hPiq0jQenv3Q= cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b h1:A7NBwTXoHTg/oDbnxnnSdiT85kZY4VvhcbUeb3q7Irk= +cloud.o-forge.io/core/oc-lib v0.0.0-20240822065024-fb80e05d6a7b/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823210057-8e80fa88beeb h1:7/GQRm485qUHpuJnW1QayD0jk4RTmf5PAOqM0xBwM7E= +cloud.o-forge.io/core/oc-lib v0.0.0-20240823210057-8e80fa88beeb/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/main.go b/main.go index 95ddde3..ee59f9e 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" _ "oc-datacenter/routers" oclib "cloud.o-forge.io/core/oc-lib" @@ -25,14 +24,12 @@ func main() { } else { o = onion.New(l2, l3) } - fmt.Println("BSLDMqlkd", o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), - o.GetStringDefault("MONGO_DATABASE", "DC_myDC")) tools.SetConfig( o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), "", ) - oclib.Init("oc-datacenter") + oclib.Init("oc-datacenter", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8092")) // Normal beego init //if beego.BConfig.RunMode == "dev" { beego.BConfig.WebConfig.DirectoryIndex = true diff --git a/oc-datacenter b/oc-datacenter index 188509b..af3c789 100755 Binary files a/oc-datacenter and b/oc-datacenter differ diff --git a/routers/commentsRouter.go b/routers/commentsRouter.go index f7c198c..acdea86 100644 --- a/routers/commentsRouter.go +++ b/routers/commentsRouter.go @@ -37,7 +37,7 @@ func init() { beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"] = append(beego.GlobalControllerRouter["oc-datacenter/controllers:BookingController"], beego.ControllerComments{ Method: "Check", - Router: `/check/:start_date/:end_date`, + Router: `/check/:datacenter_id/:start_date/:end_date`, AllowHTTPMethods: []string{"get"}, MethodParams: param.Make(), Filters: nil, diff --git a/swagger/swagger.json b/swagger/swagger.json index bcae095..a9ffcb6 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -56,7 +56,7 @@ } } }, - "/booking/check/{start_date}/{end_date}": { + "/booking/check/{datacenter_id}/{start_date}/{end_date}": { "get": { "tags": [ "booking" @@ -64,6 +64,12 @@ "description": "check booking\n\u003cbr\u003e", "operationId": "BookingController.Check", "parameters": [ + { + "in": "path", + "name": "datacenter_id", + "description": "id of the datacenter", + "type": "string" + }, { "in": "path", "name": "start_date", diff --git a/swagger/swagger.yml b/swagger/swagger.yml index 22fbb75..da6ebd3 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -60,7 +60,7 @@ paths: responses: "200": description: '{booking} models.booking' - /booking/check/{start_date}/{end_date}: + /booking/check/{datacenter_id}/{start_date}/{end_date}: get: tags: - booking @@ -69,6 +69,10 @@ paths:
operationId: BookingController.Check parameters: + - in: path + name: datacenter_id + description: id of the datacenter + type: string - in: path name: start_date description: 2006-01-02T15:04:05