Y艒ten: A social tracker for your language learning journey built on the atproto.

feat(handlers/notification): use slogger #14

merged opened by brookjeynes.dev targeting master from push-trrpxxyxxmot
Labels

None yet.

Participants 1
AT URI
at://did:plc:4mj54vc4ha3lh32ksxwunnbh/sh.tangled.repo.pull/3m3bmdlgblt22
+10 -7
Diff #0
+10 -7
internal/server/handlers/notification.go
··· 1 1 package handlers 2 2 3 3 import ( 4 - "log" 5 4 "net/http" 6 5 "strconv" 7 6 ··· 12 11 ) 13 12 14 13 func (h *Handler) HandleNotificationFeed(w http.ResponseWriter, r *http.Request) { 14 + l := h.Logger.With("handler", "HandleNotificationFeed") 15 + 15 16 user, err := bsky.GetUserWithBskyProfile(h.Oauth, r) 16 17 if err != nil { 17 - log.Println("failed to get logged-in user:", err) 18 + l.Error("failed to get logged-in user", "err", err) 18 19 htmx.HxRedirect(w, "/login") 19 20 return 20 21 } ··· 25 26 } 26 27 page, err := strconv.ParseInt(pageStr, 10, 64) 27 28 if err != nil { 28 - log.Println("failed to parse page value:", err) 29 + l.Error("failed to parse page value", "err", err) 29 30 page = 1 30 31 } 31 32 if page == 0 { ··· 39 40 case http.MethodGet: 40 41 notifications, err := db.GetNotificationsByDid(h.Db, user.Did, pageSize+1, int(offset)) 41 42 if err != nil { 42 - log.Println("failed to retrieve notifications:", err) 43 + l.Error("failed to retrieve notifications", "err", err) 43 44 htmx.HxError(w, http.StatusInternalServerError, "Failed to get notifications, try again later.") 44 45 return 45 46 } 46 47 47 48 hydratedNotifications, err := h.getBskyProfileHydratedNotificationFeed(notifications) 48 49 if err != nil { 49 - log.Println("failed to hydrate notifications with bsky profile:", err) 50 + l.Error("failed to hydrate notifications with bsky profile", "err", err) 50 51 htmx.HxError(w, http.StatusInternalServerError, "Failed to get notifications, try again later.") 51 52 return 52 53 } ··· 66 67 } 67 68 68 69 func (h *Handler) HandleNotificationMarkAllRead(w http.ResponseWriter, r *http.Request) { 70 + l := h.Logger.With("handler", "HandleNotificationMarkAllRead") 71 + 69 72 user, err := bsky.GetUserWithBskyProfile(h.Oauth, r) 70 73 if err != nil { 71 - log.Println("failed to get logged-in user:", err) 74 + l.Error("failed to get logged-in user", "err", err) 72 75 htmx.HxRedirect(w, "/login") 73 76 return 74 77 } 75 78 76 79 err = db.MarkAllNotificationsAsRead(h.Db, user.Did) 77 80 if err != nil { 78 - log.Println("failed to mark all notifications:", err) 81 + l.Error("failed to mark all notifications", "err", err) 79 82 htmx.HxError(w, http.StatusInternalServerError, "Failed to mark all notifications as read, try again later.") 80 83 return 81 84 }

History

1 round 0 comments
sign up or login to add to the discussion
brookjeynes.dev submitted #0
1 commit
expand
feat(handlers/notification): use slogger
expand 0 comments
pull request successfully merged