From ce4646b060959e344e6b472b2310c87e13226f3e Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 8 Aug 2024 17:38:11 +0200 Subject: [PATCH] git commit --- controllers/workflow_execution.go | 47 +++++++++++++------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/controllers/workflow_execution.go b/controllers/workflow_execution.go index 035a43c..7d54a82 100644 --- a/controllers/workflow_execution.go +++ b/controllers/workflow_execution.go @@ -1,6 +1,7 @@ package controllers import ( + "errors" "time" oclib "cloud.o-forge.io/core/oc-lib" @@ -65,41 +66,31 @@ func (o *WorkflowExecutionController) 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 { + 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": err, + "error": errors.New("invalid date format"), } } 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, - } + 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()