git commit

This commit is contained in:
mr 2024-08-08 17:38:11 +02:00
parent ff54f69127
commit ce4646b060

View File

@ -1,6 +1,7 @@
package controllers package controllers
import ( import (
"errors"
"time" "time"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
@ -65,41 +66,31 @@ func (o *WorkflowExecutionController) Get() {
func (o *WorkflowExecutionController) Check() { func (o *WorkflowExecutionController) Check() {
// store and return Id or post with UUID // store and return Id or post with UUID
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"))
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{}{ o.Data["json"] = map[string]interface{}{
"data": map[string]interface{}{ "data": map[string]interface{}{
"is_available": false, "is_available": false,
}, },
"code": 400, "code": 400,
"error": err, "error": errors.New("invalid date format"),
} }
} else { } else {
date2, err := time.Parse("2006-01-02T15:04:05", o.Ctx.Input.Param(":end_date")) workflow := &w.Workflow{}
if err != nil { workflow.Schedule = &w.WorkflowSchedule{Start: &date, End: &date2}
o.Data["json"] = map[string]interface{}{ isAvailable := workflow.CheckBooking()
"data": map[string]interface{}{ code := 200
"is_available": false, err := ""
}, if !isAvailable {
"code": 400, code = 409
"error": err, err = "booking not available"
} }
} else { o.Data["json"] = map[string]interface{}{
workflow := &w.Workflow{} "data": map[string]interface{}{
workflow.Schedule = &w.WorkflowSchedule{Start: &date, End: &date2} "is_available": isAvailable,
isAvailable := workflow.CheckBooking() },
code := 200 "code": code,
err := "" "error": 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() o.ServeJSON()