Scaffold full-stack volunteer scheduling application
Go backend with domain-based packages (volunteer, schedule, timeoff, checkin, notification), SQLite storage, JWT auth, and chi router. React TypeScript frontend with routing, auth context, and pages for all core features. Multi-stage Dockerfile and docker-compose included. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
52
internal/notification/handler.go
Normal file
52
internal/notification/handler.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user