diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2025-01-20 02:56:25 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2025-01-20 02:56:25 +0000 |
| commit | dc55f9c0097e1c36b85d7666071b840b902920e9 (patch) | |
| tree | c8c8ae10a9e134810b3361aabc8a9d426d813808 /api/handlers/ical.go | |
| parent | 5e7ce6cbae81a1b6e46fe6738dc10039a06bec95 (diff) | |
Add calendar support
Diffstat (limited to 'api/handlers/ical.go')
| -rw-r--r-- | api/handlers/ical.go | 43 |
1 files changed, 43 insertions, 0 deletions
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) + } +} |
