init oc-scheduler

This commit is contained in:
mr
2024-08-08 17:31:17 +02:00
parent 273fc878f7
commit ff54f69127
20 changed files with 186 additions and 1708 deletions

View File

@@ -5,6 +5,7 @@ import (
oclib "cloud.o-forge.io/core/oc-lib"
dbs "cloud.o-forge.io/core/oc-lib/dbs"
w "cloud.o-forge.io/core/oc-lib/models/workflow"
beego "github.com/beego/beego/v2/server/web"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@@ -54,3 +55,52 @@ func (o *WorkflowExecutionController) Get() {
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), id)
o.ServeJSON()
}
// @Title Check
// @Description check booking
// @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]
func (o *WorkflowExecutionController) Check() {
// store and return Id or post with UUID
date, err := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":start_date"))
if err != nil {
o.Data["json"] = map[string]interface{}{
"data": map[string]interface{}{
"is_available": false,
},
"code": 400,
"error": err,
}
} else {
date2, err := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":end_date"))
if err != nil {
o.Data["json"] = map[string]interface{}{
"data": map[string]interface{}{
"is_available": false,
},
"code": 400,
"error": err,
}
} else {
workflow := &w.Workflow{}
workflow.Schedule = &w.WorkflowSchedule{Start: &date, End: &date2}
isAvailable := workflow.CheckBooking()
code := 200
err := ""
if !isAvailable {
code = 409
err = "booking not available"
}
o.Data["json"] = map[string]interface{}{
"data": map[string]interface{}{
"is_available": isAvailable,
},
"code": code,
"error": err,
}
}
}
o.ServeJSON()
}