From b6f4beb21024d5014df12f9486b724dff1b89dd5 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Sun, 9 Jan 2022 16:49:50 +0800 Subject: [PATCH] update --- calendar/event.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/calendar/event.go b/calendar/event.go index 286d517..227e2c2 100644 --- a/calendar/event.go +++ b/calendar/event.go @@ -39,13 +39,16 @@ func (e *Event) BeforeSave(tx *gorm.DB) (err error) { } // test for collide - cnt := 0 - db.Raw(`select count(*) from events e where + cnt := "" + db.Raw(`select id from events e where (? >= "start" and ? <= "end" ) or (? >= "start" and ? <= "end" ) - and calendar_id = ?`, + and calendar_id = ? limit 1`, e.End, e.End, e.Start, e.Start, e.CalendarID).Scan(&cnt) + if cnt != "" { + return errors.New(500, "event collide with existing") + } return }