From 48b66258eacf7ddbd3f62279590dd1200e704e75 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Tue, 21 Dec 2021 19:44:27 +0800 Subject: [PATCH] update --- calendar/basic.ics | 118 ++++++++++++++++++++++++++++++++++++++++ calendar/calendar.go | 31 ++++++----- calendar/event.go | 28 ++++++++++ calendar/event_group.go | 24 ++++++++ calendar/service.go | 12 ++++ 5 files changed, 199 insertions(+), 14 deletions(-) create mode 100644 calendar/basic.ics create mode 100644 calendar/event.go create mode 100644 calendar/event_group.go create mode 100644 calendar/service.go diff --git a/calendar/basic.ics b/calendar/basic.ics new file mode 100644 index 0000000..6fb72a1 --- /dev/null +++ b/calendar/basic.ics @@ -0,0 +1,118 @@ +BEGIN:VCALENDAR +PRODID:-//Google Inc//Google Calendar 70.9054//EN +VERSION:2.0 +CALSCALE:GREGORIAN +METHOD:PUBLISH +X-WR-CALNAME:A301 +X-WR-TIMEZONE:Asia/Taipei +X-WR-CALDESC:A301 +BEGIN:VTIMEZONE +TZID:Asia/Taipei +X-LIC-LOCATION:Asia/Taipei +BEGIN:STANDARD +TZOFFSETFROM:+0800 +TZOFFSETTO:+0800 +TZNAME:CST +DTSTART:19700101T000000 +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +DTSTART:20211221T020000Z +DTEND:20211221T023000Z +DTSTAMP:20211221T113213Z +UID:60gh4s8m1m672d0l808cp0kq96@google.com +CREATED:20211221T113106Z +DESCRIPTION:edadlk123 +LAST-MODIFIED:20211221T113106Z +LOCATION:T1-1 +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:數學 +TRANSP:TRANSPARENT +END:VEVENT +BEGIN:VEVENT +DTSTART;TZID=Asia/Taipei:20211104T102000 +DTEND;TZID=Asia/Taipei:20211104T121500 +RRULE:FREQ=WEEKLY;UNTIL=20211111T000000Z +DTSTAMP:20211221T113213Z +UID:ip9l2rk11sjr49sbhtcu0rrq7c@google.com +CREATED:20211102T063233Z +DESCRIPTION:{\n "name": "普通生物學乙"\,\n "teacher": "閔明源"\,\n "code": + "B01-101B0"\,\n "class": "01"\,\n "semester": "109-1"\,\n "locatio + n": "A301"\,\n "location_code": "a301"\n} +LAST-MODIFIED:20211102T063233Z +LOCATION:A301 +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:普通生物學乙 閔明源 +TRANSP:OPAQUE +END:VEVENT +BEGIN:VEVENT +DTSTART;TZID=Asia/Taipei:20211102T132000 +DTEND;TZID=Asia/Taipei:20211102T151500 +RRULE:FREQ=WEEKLY;UNTIL=20211111T000000Z +DTSTAMP:20211221T113213Z +UID:elfaolrnjqeqogsc2cbum2kku0@google.com +CREATED:20211102T063232Z +DESCRIPTION:{\n "name": "普通生物學乙"\,\n "teacher": "閔明源"\,\n "code": + "B01-101B0"\,\n "class": "01"\,\n "semester": "109-1"\,\n "locatio + n": "A301"\,\n "location_code": "a301"\n} +LAST-MODIFIED:20211102T063232Z +LOCATION:A301 +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:普通生物學乙 閔明源 +TRANSP:OPAQUE +END:VEVENT +BEGIN:VEVENT +DTSTART;TZID=Asia/Taipei:20211105T091000 +DTEND;TZID=Asia/Taipei:20211105T100500 +RRULE:FREQ=WEEKLY;UNTIL=20211111T000000Z +DTSTAMP:20211221T113213Z +UID:b6tqfns0oopvgvjtlvnca33j68@google.com +CREATED:20211102T063221Z +DESCRIPTION:{\n "name": "高等流體力學"\,\n "teacher": "謝之真"\,\n "code": + "524-M1210"\,\n "class": "02"\,\n "semester": "109-1"\,\n "locatio + n": "A301"\,\n "location_code": "a301"\n} +LAST-MODIFIED:20211102T063221Z +LOCATION:A301 +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:高等流體力學 謝之真 +TRANSP:OPAQUE +END:VEVENT +BEGIN:VEVENT +DTSTART;TZID=Asia/Taipei:20211102T102000 +DTEND;TZID=Asia/Taipei:20211102T121500 +RRULE:FREQ=WEEKLY;UNTIL=20211111T000000Z +DTSTAMP:20211221T113213Z +UID:unnca2j62u7l561lupqga2tc40@google.com +CREATED:20211102T063220Z +DESCRIPTION:{\n "name": "高等流體力學"\,\n "teacher": "謝之真"\,\n "code": + "524-M1210"\,\n "class": "02"\,\n "semester": "109-1"\,\n "locatio + n": "A301"\,\n "location_code": "a301"\n} +LAST-MODIFIED:20211102T063221Z +LOCATION:A301 +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:高等流體力學 謝之真 +TRANSP:OPAQUE +END:VEVENT +BEGIN:VEVENT +DTSTART;TZID=Asia/Taipei:20211104T142000 +DTEND;TZID=Asia/Taipei:20211104T172500 +RRULE:FREQ=WEEKLY;UNTIL=20211111T000000Z +DTSTAMP:20211221T113213Z +UID:paefk9l3jihei6hgocm65f72co@google.com +CREATED:20211102T063214Z +DESCRIPTION:{\n "name": "有限元素法"\,\n "teacher": "莊嘉揚"\,\n "code": " + 522-M2570"\,\n "class": "0"\,\n "semester": "109-1"\,\n "location" + : "A301"\,\n "location_code": "a301"\n} +LAST-MODIFIED:20211102T063214Z +LOCATION:A301 +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY:有限元素法 莊嘉揚 +TRANSP:OPAQUE +END:VEVENT +END:VCALENDAR diff --git a/calendar/calendar.go b/calendar/calendar.go index 6550ea7..b703941 100644 --- a/calendar/calendar.go +++ b/calendar/calendar.go @@ -1,24 +1,27 @@ package calendar -import "time" +import ( + "time" + + "github.com/rs/xid" + "github.com/rs/zerolog" + "gorm.io/gorm" +) + +var l zerolog.Logger type Calendar struct { - ID uint `gorm:"primaryKey"` + ID string `gorm:"primaryKey"` + + Events []Event CreatedAt time.Time UpdatedAt time.Time } -type EventGroup struct { - ID uint `gorm:"primaryKey"` - - CreatedAt time.Time - UpdatedAt time.Time -} - -type Event struct { - ID uint `gorm:"primaryKey"` - - CreatedAt time.Time - UpdatedAt time.Time +func (c *Calendar) BeforeCreate(tx *gorm.DB) (err error) { + if c.ID == "" { + c.ID = xid.New().String() + } + return } diff --git a/calendar/event.go b/calendar/event.go new file mode 100644 index 0000000..22ee078 --- /dev/null +++ b/calendar/event.go @@ -0,0 +1,28 @@ +package calendar + +import ( + "time" + + "github.com/rs/xid" + "gorm.io/gorm" +) + +type Event struct { + ID string `gorm:"primaryKey"` + + Start time.Time + End time.Time + + CalendarID string + EventGroupID string + + CreatedAt time.Time + UpdatedAt time.Time +} + +func (e *Event) BeforeCreate(tx *gorm.DB) (err error) { + if e.ID == "" { + e.ID = xid.New().String() + } + return +} diff --git a/calendar/event_group.go b/calendar/event_group.go new file mode 100644 index 0000000..536fcd0 --- /dev/null +++ b/calendar/event_group.go @@ -0,0 +1,24 @@ +package calendar + +import ( + "time" + + "github.com/rs/xid" + "gorm.io/gorm" +) + +type EventGroup struct { + ID string `gorm:"primaryKey"` + + Events []Event + + CreatedAt time.Time + UpdatedAt time.Time +} + +func (eg *EventGroup) BeforeCreate(tx *gorm.DB) (err error) { + if eg.ID == "" { + eg.ID = xid.New().String() + } + return +} diff --git a/calendar/service.go b/calendar/service.go new file mode 100644 index 0000000..a81b00f --- /dev/null +++ b/calendar/service.go @@ -0,0 +1,12 @@ +package calendar + +type Service struct{} + +func (srv Service) GetName() string { return "calendar.Service" } +func (srv Service) GetDependencies() []string { return []string{} } +func (srv Service) IsService() bool { return false } +func (srv Service) Init() error { return nil } +func (srv Service) Load() error { return nil } +func (srv Service) Main() error { return nil } +func (srv Service) Del() {} +func (srv Service) Health() error { return nil }