package handlers import ( "net/http" "github.com/go-chi/chi/v5" "sneak.berlin/go/upaas/internal/models" "sneak.berlin/go/upaas/templates" ) // webhookEventsLimit is the number of webhook events to show in history. const webhookEventsLimit = 100 // HandleAppWebhookEvents returns the webhook event history handler. func (h *Handlers) HandleAppWebhookEvents() http.HandlerFunc { tmpl := templates.GetParsed() return func(writer http.ResponseWriter, request *http.Request) { appID := chi.URLParam(request, "id") application, findErr := models.FindApp(request.Context(), h.db, appID) if findErr != nil { h.log.Error("failed to find app", "error", findErr) http.Error(writer, "Internal Server Error", http.StatusInternalServerError) return } if application == nil { http.NotFound(writer, request) return } events, eventsErr := application.GetWebhookEvents( request.Context(), webhookEventsLimit, ) if eventsErr != nil { h.log.Error("failed to get webhook events", "error", eventsErr, "app", appID, ) events = []*models.WebhookEvent{} } data := h.addGlobals(map[string]any{ "App": application, "Events": events, }, request) h.renderTemplate(writer, tmpl, "webhook_events.html", data) } }