From 0d58e402f8ce7cac9ef85c3745714c8fdb701636 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Fri, 24 Dec 2021 22:31:29 +0800 Subject: [PATCH] update --- calendar/calendar.go | 1 - calendar/util.go | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/calendar/calendar.go b/calendar/calendar.go index 7ee03ac..b1ad079 100644 --- a/calendar/calendar.go +++ b/calendar/calendar.go @@ -19,7 +19,6 @@ type Calendar struct { Name string `gorm:"index:idx_cal,unique"` Description string - ExtLink string Timezone string diff --git a/calendar/util.go b/calendar/util.go index 1ba8a3a..62dd906 100644 --- a/calendar/util.go +++ b/calendar/util.go @@ -2,6 +2,7 @@ package calendar import ( "github.com/gin-gonic/gin" + "gorm.io/gorm" "kumoly.io/kumoly/app/auth" "kumoly.io/kumoly/app/errors" ) @@ -33,3 +34,18 @@ func HasEventAccess(c *gin.Context, e *Event, cid string) error { } return nil } + +func ChangeCalGroup(cal_id, to string) error { + return db.Transaction(func(tx *gorm.DB) error { + affected := tx.Exec(`update events set group_id = ( + select id from groups where name = ? + ) where calendar_id = ?`, to, cal_id).RowsAffected + if affected == 0 { + return errors.ErrorNotFound + } + tx.Exec(`update events set group_id = ( + select id from groups where name = ? + ) where calendar_id = ?`, to, cal_id) + return nil + }) +}