From dc55f9c0097e1c36b85d7666071b840b902920e9 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Mon, 20 Jan 2025 02:56:25 +0000 Subject: Add calendar support --- api/handlers/ical.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 api/handlers/ical.go (limited to 'api/handlers/ical.go') diff --git a/api/handlers/ical.go b/api/handlers/ical.go new file mode 100644 index 0000000..c4b3989 --- /dev/null +++ b/api/handlers/ical.go @@ -0,0 +1,43 @@ +package handlers + +import ( + "crypto/subtle" + + "github.com/LMBishop/confplanner/api/dto" + "github.com/LMBishop/confplanner/pkg/calendar" + "github.com/LMBishop/confplanner/pkg/ical" + "github.com/gofiber/fiber/v2" +) + +func GetIcal(icalService ical.Service, calendarService calendar.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + name := c.Query("name") + key := c.Query("key") + + if name == "" || key == "" { + return &dto.ErrorResponse{ + Code: fiber.StatusBadRequest, + Message: "Both name and key must be specified", + } + } + + calendar, err := calendarService.GetCalendarByName(name) + if err != nil { + return err + } + + if subtle.ConstantTimeCompare([]byte(key), []byte(calendar.Key)) != 1 { + return &dto.ErrorResponse{ + Code: fiber.StatusUnauthorized, + Message: "Invalid key", + } + } + + ical, err := icalService.GenerateIcalForCalendar(*calendar) + if err != nil { + return err + } + + return c.SendString(ical) + } +} -- cgit v1.2.3-70-g09d2