From 72a783bdd3459fa0c4455224a2fd7327358f205e Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Sun, 9 Jan 2022 16:48:10 +0800 Subject: [PATCH] update --- calendar/event.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/calendar/event.go b/calendar/event.go index ccec497..286d517 100644 --- a/calendar/event.go +++ b/calendar/event.go @@ -37,6 +37,16 @@ func (e *Event) BeforeSave(tx *gorm.DB) (err error) { tx.Raw("select name from calendars where id = ?", e.CalendarID).Scan(&loc) e.Location = loc } + + // test for collide + cnt := 0 + db.Raw(`select count(*) from events e where + (? >= "start" and ? <= "end" ) + or + (? >= "start" and ? <= "end" ) + and calendar_id = ?`, + e.End, e.End, e.Start, e.Start, e.CalendarID).Scan(&cnt) + return }