aboutsummaryrefslogtreecommitdiff
path: root/plugins/caldav/routes.go
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-02-05 18:08:00 +0100
committerSimon Ser <contact@emersion.fr>2020-02-05 18:14:26 +0100
commit5b78cdc104961f8cbd870513dee75dd823c6e4c6 (patch)
treeafcda34b3fb5066bddce1d73bc861d5344bf848f /plugins/caldav/routes.go
parent1bd930f0438ebce5fd0e27aca0f5d5e1c5bcc750 (diff)
downloadalps-5b78cdc104961f8cbd870513dee75dd823c6e4c6.tar.gz
alps-5b78cdc104961f8cbd870513dee75dd823c6e4c6.zip
plugins/caldav: new plugin
For now it can only list events for the current month. References: https://todo.sr.ht/~sircmpwn/koushin/60
Diffstat (limited to 'plugins/caldav/routes.go')
-rw-r--r--plugins/caldav/routes.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/plugins/caldav/routes.go b/plugins/caldav/routes.go
new file mode 100644
index 0000000..acc879f
--- /dev/null
+++ b/plugins/caldav/routes.go
@@ -0,0 +1,66 @@
+package koushincaldav
+
+import (
+ "fmt"
+ "net/http"
+ "net/url"
+ "time"
+
+ "git.sr.ht/~emersion/koushin"
+ "github.com/emersion/go-webdav/caldav"
+)
+
+type CalendarRenderData struct {
+ koushin.BaseRenderData
+ Calendar *caldav.Calendar
+ Events []caldav.CalendarObject
+}
+
+func registerRoutes(p *koushin.GoPlugin, u *url.URL) {
+ p.GET("/calendar", func(ctx *koushin.Context) error {
+ // TODO: multi-calendar support
+ c, calendar, err := getCalendar(u, ctx.Session)
+ if err != nil {
+ return err
+ }
+
+ now := time.Now()
+ start := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
+ end := start.AddDate(0, 1, 0)
+
+ query := caldav.CalendarQuery{
+ CompRequest: caldav.CalendarCompRequest{
+ Name: "VCALENDAR",
+ Props: []string{"VERSION"},
+ Comps: []caldav.CalendarCompRequest{{
+ Name: "VEVENT",
+ Props: []string{
+ "SUMMARY",
+ "UID",
+ "DTSTART",
+ "DTEND",
+ "DURATION",
+ },
+ }},
+ },
+ CompFilter: caldav.CompFilter{
+ Name: "VCALENDAR",
+ Comps: []caldav.CompFilter{{
+ Name: "VEVENT",
+ Start: start,
+ End: end,
+ }},
+ },
+ }
+ events, err := c.QueryCalendar(calendar.Path, &query)
+ if err != nil {
+ return fmt.Errorf("failed to query calendar: %v", err)
+ }
+
+ return ctx.Render(http.StatusOK, "calendar.html", &CalendarRenderData{
+ BaseRenderData: *koushin.NewBaseRenderData(ctx),
+ Calendar: calendar,
+ Events: events,
+ })
+ })
+}