From 1bb46c638d176233350d1e054738116e2f3820b2 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Sun, 26 Dec 2021 16:19:18 +0800 Subject: [PATCH] update --- calendar/calendar.go | 2 +- calendar/event.go | 9 +++++---- calendar/event_group.go | 10 +++++----- calendar/util.go | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/calendar/calendar.go b/calendar/calendar.go index 0dbc0d8..961b9c2 100644 --- a/calendar/calendar.go +++ b/calendar/calendar.go @@ -14,7 +14,7 @@ var l zerolog.Logger var db *gorm.DB -var color []string = []string{ +var Color []string = []string{ "red", "pink", "purple", "deep-purple", "indigo", "blue", "light-blue", "cyan", "teal", "green", "light-green", "lime", "yellow", "amber", "orange", "deep-orange", "blue-grey", } diff --git a/calendar/event.go b/calendar/event.go index 3569031..5942b66 100644 --- a/calendar/event.go +++ b/calendar/event.go @@ -11,9 +11,10 @@ import ( type Event struct { ID string `gorm:"primaryKey"` - Start time.Time - End time.Time - Name string `gorm:"not null"` + Start time.Time + End time.Time + Name string `gorm:"not null"` + Location string Color string `gorm:"-"` @@ -48,6 +49,6 @@ func (e *Event) AfterFind(tx *gorm.DB) (err error) { return err } e.EventGroup = eg - e.Color = color[e.EventGroup.Color%len(color)] + e.Color = Color[e.EventGroup.Color%len(Color)] return } diff --git a/calendar/event_group.go b/calendar/event_group.go index 94bb387..47ef90a 100644 --- a/calendar/event_group.go +++ b/calendar/event_group.go @@ -18,12 +18,12 @@ type EventGroup struct { // event header Hosts string Description string - Location string // ntu - Class string - CourseID string - Semester string + Class string + CourseID string + Semester string + IsRegular bool // UI Color int @@ -48,7 +48,6 @@ func (eg *EventGroup) BeforeSave(tx *gorm.DB) (err error) { } else { eg.GroupID = 0 } - eg.Color = GetNewColor(eg.GroupName) return } @@ -56,6 +55,7 @@ func (eg *EventGroup) BeforeCreate(tx *gorm.DB) (err error) { if eg.ID == "" { eg.ID = xid.New().String() } + eg.Color = GetNewColor(eg.GroupName) return } diff --git a/calendar/util.go b/calendar/util.go index c8cad58..1b0f6a0 100644 --- a/calendar/util.go +++ b/calendar/util.go @@ -23,8 +23,8 @@ func HasCalAccess(c *gin.Context, cal *Calendar, cid string) error { return nil } -func HasEventAccess(c *gin.Context, e *Event, cid string) error { - err := db.First(e, "id = ?", cid).Error +func HasEventAccess(c *gin.Context, e *Event, eid string) error { + err := db.First(e, "id = ?", eid).Error if err != nil { return errors.NewError(404, err) } @@ -57,7 +57,7 @@ func GetNewColor(GroupName string) int { if err := db.Select("color"). Where("group_id = (select id from groups where name = ? )", GroupName). Last(eg).Error; err != nil { - return rand.Intn(len(color)) + return rand.Intn(len(Color)) } return eg.Color + 1 }