diff options
author | Simon Ser <contact@emersion.fr> | 2020-02-05 18:39:53 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-02-05 18:39:53 +0100 |
commit | a1b43cc5a81c51c35590ed2ea8f47171dc38669c (patch) | |
tree | e13731314ca65f3cecc30adab55756d836c6bff8 /plugins | |
parent | 5b78cdc104961f8cbd870513dee75dd823c6e4c6 (diff) | |
download | alps-a1b43cc5a81c51c35590ed2ea8f47171dc38669c.tar.gz alps-a1b43cc5a81c51c35590ed2ea8f47171dc38669c.zip |
plugins/caldav: add basic event view
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/caldav/routes.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/plugins/caldav/routes.go b/plugins/caldav/routes.go index acc879f..7ff831d 100644 --- a/plugins/caldav/routes.go +++ b/plugins/caldav/routes.go @@ -16,6 +16,12 @@ type CalendarRenderData struct { Events []caldav.CalendarObject } +type EventRenderData struct { + koushin.BaseRenderData + Calendar *caldav.Calendar + Event *caldav.CalendarObject +} + func registerRoutes(p *koushin.GoPlugin, u *url.URL) { p.GET("/calendar", func(ctx *koushin.Context) error { // TODO: multi-calendar support @@ -63,4 +69,55 @@ func registerRoutes(p *koushin.GoPlugin, u *url.URL) { Events: events, }) }) + + p.GET("/calendar/:uid", func(ctx *koushin.Context) error { + uid := ctx.Param("uid") + + c, calendar, err := getCalendar(u, ctx.Session) + if err != nil { + return err + } + + query := caldav.CalendarQuery{ + CompRequest: caldav.CalendarCompRequest{ + Name: "VCALENDAR", + Props: []string{"VERSION"}, + Comps: []caldav.CalendarCompRequest{{ + Name: "VEVENT", + Props: []string{ + "SUMMARY", + "DESCRIPTION", + "UID", + "DTSTART", + "DTEND", + "DURATION", + }, + }}, + }, + CompFilter: caldav.CompFilter{ + Name: "VCALENDAR", + Comps: []caldav.CompFilter{{ + Name: "VEVENT", + Props: []caldav.PropFilter{{ + Name: "UID", + TextMatch: &caldav.TextMatch{Text: uid}, + }}, + }}, + }, + } + events, err := c.QueryCalendar(calendar.Path, &query) + if err != nil { + return fmt.Errorf("failed to query calendar: %v", err) + } + if len(events) != 1 { + return fmt.Errorf("expected exactly one calendar object with UID %q, got %v", uid, len(events)) + } + event := &events[0] + + return ctx.Render(http.StatusOK, "event.html", &EventRenderData{ + BaseRenderData: *koushin.NewBaseRenderData(ctx), + Calendar: calendar, + Event: event, + }) + }) } |