aboutsummaryrefslogtreecommitdiffstats
path: root/api/handlers/ical.go
diff options
context:
space:
mode:
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))
}
}