check booking

This commit is contained in:
mr 2024-08-08 09:54:05 +02:00
parent 47cd936131
commit f45ad91687

View File

@ -22,10 +22,10 @@ func New() *workflowMongoAccessor {
return &workflowMongoAccessor{} return &workflowMongoAccessor{}
} }
func (wfa *workflowMongoAccessor) CheckBooking(data *Workflow) bool { func (wfa *workflowMongoAccessor) CheckBooking(start *time.Time) bool {
accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor() accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor()
s := data.Schedule.Start.Add(time.Duration(-10) * time.Second) s := start.Add(time.Duration(-10) * time.Second)
e := data.Schedule.Start.Add(time.Duration(10) * time.Second) e := start.Add(time.Duration(10) * time.Second)
sd := primitive.NewDateTimeFromTime(s) sd := primitive.NewDateTimeFromTime(s)
ed := primitive.NewDateTimeFromTime(e) ed := primitive.NewDateTimeFromTime(e)
f := dbs.Filters{ f := dbs.Filters{
@ -96,7 +96,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
if r.Schedule.Start == realData.Schedule.Start && r.Schedule.End == realData.Schedule.End && r.Schedule.Cron == realData.Schedule.Cron { if r.Schedule.Start == realData.Schedule.Start && r.Schedule.End == realData.Schedule.End && r.Schedule.Cron == realData.Schedule.Cron {
return 200, nil return 200, nil
} }
if !wfa.CheckBooking(realData) { if !wfa.CheckBooking(realData.Schedule.Start) {
return 409, errors.New("the booking is already taken.") return 409, errors.New("the booking is already taken.")
} }
if delete { if delete {