From 5888672ce5f9d7987e6d1337cb2431acfe60c320 Mon Sep 17 00:00:00 2001 From: brookjeynes Date: Wed, 15 Oct 2025 11:49:39 +1000 Subject: [PATCH] feat(handlers/notification): use slogger Change-Id: ryrmqnpsuytzmqulyvkwvxpvllvryxms Signed-off-by: brookjeynes --- internal/server/handlers/notification.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/server/handlers/notification.go b/internal/server/handlers/notification.go index 3cbc757..d7a59bd 100644 --- a/internal/server/handlers/notification.go +++ b/internal/server/handlers/notification.go @@ -1,7 +1,6 @@ package handlers import ( - "log" "net/http" "strconv" @@ -12,9 +11,11 @@ import ( ) func (h *Handler) HandleNotificationFeed(w http.ResponseWriter, r *http.Request) { + l := h.Logger.With("handler", "HandleNotificationFeed") + user, err := bsky.GetUserWithBskyProfile(h.Oauth, r) if err != nil { - log.Println("failed to get logged-in user:", err) + l.Error("failed to get logged-in user", "err", err) htmx.HxRedirect(w, "/login") return } @@ -25,7 +26,7 @@ func (h *Handler) HandleNotificationFeed(w http.ResponseWriter, r *http.Request) } page, err := strconv.ParseInt(pageStr, 10, 64) if err != nil { - log.Println("failed to parse page value:", err) + l.Error("failed to parse page value", "err", err) page = 1 } if page == 0 { @@ -39,14 +40,14 @@ func (h *Handler) HandleNotificationFeed(w http.ResponseWriter, r *http.Request) case http.MethodGet: notifications, err := db.GetNotificationsByDid(h.Db, user.Did, pageSize+1, int(offset)) if err != nil { - log.Println("failed to retrieve notifications:", err) + l.Error("failed to retrieve notifications", "err", err) htmx.HxError(w, http.StatusInternalServerError, "Failed to get notifications, try again later.") return } hydratedNotifications, err := h.getBskyProfileHydratedNotificationFeed(notifications) if err != nil { - log.Println("failed to hydrate notifications with bsky profile:", err) + l.Error("failed to hydrate notifications with bsky profile", "err", err) htmx.HxError(w, http.StatusInternalServerError, "Failed to get notifications, try again later.") return } @@ -66,16 +67,18 @@ func (h *Handler) HandleNotificationFeed(w http.ResponseWriter, r *http.Request) } func (h *Handler) HandleNotificationMarkAllRead(w http.ResponseWriter, r *http.Request) { + l := h.Logger.With("handler", "HandleNotificationMarkAllRead") + user, err := bsky.GetUserWithBskyProfile(h.Oauth, r) if err != nil { - log.Println("failed to get logged-in user:", err) + l.Error("failed to get logged-in user", "err", err) htmx.HxRedirect(w, "/login") return } err = db.MarkAllNotificationsAsRead(h.Db, user.Did) if err != nil { - log.Println("failed to mark all notifications:", err) + l.Error("failed to mark all notifications", "err", err) htmx.HxError(w, http.StatusInternalServerError, "Failed to mark all notifications as read, try again later.") return } -- 2.43.0