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