package notification import ( "net/http" "strconv" "github.com/go-chi/chi/v5" "git.unsupervised.ca/walkies/internal/respond" "git.unsupervised.ca/walkies/internal/server/middleware" ) type Handler struct { store *Store } func NewHandler(store *Store) *Handler { return &Handler{store: store} } // GET /api/v1/notifications func (h *Handler) List(w http.ResponseWriter, r *http.Request) { claims := middleware.ClaimsFromContext(r.Context()) notifications, err := h.store.ListForVolunteer(claims.VolunteerID) if err != nil { respond.Error(w, http.StatusInternalServerError, "could not list notifications") return } if notifications == nil { notifications = []Notification{} } respond.JSON(w, http.StatusOK, notifications) } // PUT /api/v1/notifications/{id}/read func (h *Handler) MarkRead(w http.ResponseWriter, r *http.Request) { claims := middleware.ClaimsFromContext(r.Context()) id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) if err != nil { respond.Error(w, http.StatusBadRequest, "invalid id") return } n, err := h.store.MarkRead(id, claims.VolunteerID) if err != nil { respond.Error(w, http.StatusInternalServerError, "could not mark notification as read") return } if n == nil { respond.Error(w, http.StatusNotFound, "notification not found") return } respond.JSON(w, http.StatusOK, n) }