package controllers import ( "errors" "time" 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" ) // Operations about workflow type WorkflowExecutionController struct { beego.Controller } // @Title Search // @Description search workspace // @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 *WorkflowExecutionController) Search() { // store and return Id or post with UUID 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{ "execution_date": {{Operator: "gte", Value: sd}, {Operator: "lte", Value: ed}}, }, } o.Data["json"] = oclib.Search(&f, "", oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION)) o.ServeJSON() } // @Title GetAll // @Description find workflow by workflowid // @Success 200 {workflow} models.workflow // @router / [get] func (o *WorkflowExecutionController) GetAll() { o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION)) o.ServeJSON() } // @Title Get // @Description find workflow by workflowid // @Param id path string true "the workflowid you want to get" // @Success 200 {workflow} models.workflow // @router /:id [get] func (o *WorkflowExecutionController) Get() { id := o.Ctx.Input.Param(":id") 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")) date2, err2 := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":end_date")) if err != nil || err2 != nil { o.Data["json"] = map[string]interface{}{ "data": map[string]interface{}{ "is_available": false, }, "code": 400, "error": errors.New("invalid date format"), } } 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() }