neo datacenter

This commit is contained in:
mr 2024-08-26 12:08:43 +02:00
parent ae0b2098ec
commit a07db36d99
8 changed files with 25 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"time" "time"
"fmt"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/dbs" "cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/models/booking" "cloud.o-forge.io/core/oc-lib/models/booking"
@ -52,12 +52,14 @@ func (o *BookingController) Get() {
// @Title Check // @Title Check
// @Description check booking // @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 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" // @Param end_date path string "the booking end date" format "2006-01-02T15:04:05"
// @Success 200 {object} models.object // @Success 200 {object} models.object
// @router /check/:start_date/:end_date [get] // @router /check/:id/:start_date/:end_date [get]
func (o *BookingController) Check() { func (o *BookingController) Check() {
// store and return Id or post with UUID // 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")) 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")) date2, err2 := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":end_date"))
if err != nil || err2 != nil { if err != nil || err2 != nil {
@ -70,7 +72,7 @@ func (o *BookingController) Check() {
} }
} else { } else {
booking := &b.Booking{} booking := &b.Booking{}
isAvailable, err2 := booking.CheckBooking(date, &date2) isAvailable, err2 := booking.CheckBooking(id, date, &date2)
code := 200 code := 200
err := "" err := ""
if !isAvailable { if !isAvailable {
@ -120,7 +122,7 @@ func (o *BookingController) Post() {
books := make([]interface{}, 0) books := make([]interface{}, 0)
errormsg := "" errormsg := ""
for _, exec := range resp.Executions { 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." res.Err += " -> the booking from " + exec.ExecDate.String() + " is already taken."
o.Data["json"] = map[string]interface{}{ o.Data["json"] = map[string]interface{}{
"data": nil, "data": nil,

2
go.mod
View File

@ -11,7 +11,7 @@ require (
) )
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 filippo.io/edwards25519 v1.1.0 // indirect
github.com/beego/bee/v2 v2.1.0 // indirect github.com/beego/bee/v2 v2.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect

4
go.sum
View File

@ -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-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 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-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= 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 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
_ "oc-datacenter/routers" _ "oc-datacenter/routers"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
@ -25,14 +24,12 @@ func main() {
} else { } else {
o = onion.New(l2, l3) 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( tools.SetConfig(
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), 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 // Normal beego init
//if beego.BConfig.RunMode == "dev" { //if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true

Binary file not shown.

View File

@ -37,7 +37,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: "Check", Method: "Check",
Router: `/check/:start_date/:end_date`, Router: `/check/:datacenter_id/:start_date/:end_date`,
AllowHTTPMethods: []string{"get"}, AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(), MethodParams: param.Make(),
Filters: nil, Filters: nil,

View File

@ -56,7 +56,7 @@
} }
} }
}, },
"/booking/check/{start_date}/{end_date}": { "/booking/check/{datacenter_id}/{start_date}/{end_date}": {
"get": { "get": {
"tags": [ "tags": [
"booking" "booking"
@ -64,6 +64,12 @@
"description": "check booking\n\u003cbr\u003e", "description": "check booking\n\u003cbr\u003e",
"operationId": "BookingController.Check", "operationId": "BookingController.Check",
"parameters": [ "parameters": [
{
"in": "path",
"name": "datacenter_id",
"description": "id of the datacenter",
"type": "string"
},
{ {
"in": "path", "in": "path",
"name": "start_date", "name": "start_date",

View File

@ -60,7 +60,7 @@ paths:
responses: responses:
"200": "200":
description: '{booking} models.booking' description: '{booking} models.booking'
/booking/check/{start_date}/{end_date}: /booking/check/{datacenter_id}/{start_date}/{end_date}:
get: get:
tags: tags:
- booking - booking
@ -69,6 +69,10 @@ paths:
<br> <br>
operationId: BookingController.Check operationId: BookingController.Check
parameters: parameters:
- in: path
name: datacenter_id
description: id of the datacenter
type: string
- in: path - in: path
name: start_date name: start_date
description: 2006-01-02T15:04:05 description: 2006-01-02T15:04:05