aboutsummaryrefslogtreecommitdiffstats
path: root/api/handlers/ical.go
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2025-08-14 18:07:12 +0100
committerLeonardo Bishop <me@leonardobishop.com>2025-08-14 18:07:12 +0100
commit4697556cac819c47d068819b9fc9c3b4ea84e279 (patch)
treeb832d8fc6b643a8b9d0eeca35c1268e1649da731 /api/handlers/ical.go
parentdd49c9205bb04844b686b9c3396c40eb49d25826 (diff)
Merge confplanner-web and replace fiber with native net/http
Diffstat (limited to 'api/handlers/ical.go')
-rw-r--r--api/handlers/ical.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/api/handlers/ical.go b/api/handlers/ical.go
index 52dfcdb..bcbf42b 100644
--- a/api/handlers/ical.go
+++ b/api/handlers/ical.go
@@ -2,43 +2,47 @@ package handlers
import (
"crypto/subtle"
+ "net/http"
"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")
+func GetIcal(icalService ical.Service, calendarService calendar.Service) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ name := r.URL.Query().Get("name")
+ key := r.URL.Query().Get("key")
if name == "" || key == "" {
- return &dto.ErrorResponse{
- Code: fiber.StatusBadRequest,
+ dto.WriteDto(w, r, &dto.ErrorResponse{
+ Code: http.StatusBadRequest,
Message: "Both name and key must be specified",
- }
+ })
+ return
}
calendar, err := calendarService.GetCalendarByName(name)
if err != nil {
- return err
+ dto.WriteDto(w, r, err)
+ return
}
if subtle.ConstantTimeCompare([]byte(key), []byte(calendar.Key)) != 1 {
- return &dto.ErrorResponse{
- Code: fiber.StatusUnauthorized,
+ dto.WriteDto(w, r, &dto.ErrorResponse{
+ Code: http.StatusUnauthorized,
Message: "Invalid key",
- }
+ })
+ return
}
ical, err := icalService.GenerateIcalForCalendar(*calendar)
if err != nil {
- return err
+ dto.WriteDto(w, r, err)
+ return
}
- c.Set("Content-Type", "text/calendar")
- return c.SendString(ical)
+ w.Header().Add("Content-Type", "text/calendar")
+ w.Write([]byte(ical))
}
}