Conform Go code to project conventions

- Propagate context.Context through all exported store/service methods
  that perform I/O; use QueryContext/ExecContext/QueryRowContext throughout
- Add package-level sentinel errors (ErrNotFound, ErrAlreadyCheckedIn,
  ErrNotCheckedIn) and replace nil,nil returns with explicit errors
- Update handlers to use errors.Is() instead of nil checks, with correct
  HTTP status codes per error type
- Fix SQLite datetime('now') → MySQL NOW() in volunteer, schedule,
  timeoff, and checkin stores
- Refactor db.Migrate to execute schema statements individually (MySQL
  driver does not support multi-statement Exec)
- Fix import grouping in handler files (stdlib, external, internal)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 16:20:23 -04:00
parent 55f68c571e
commit 87caf478df
14 changed files with 180 additions and 145 deletions

View File

@@ -1,12 +1,13 @@
package notification
import (
"errors"
"net/http"
"strconv"
"github.com/go-chi/chi/v5"
"git.unsupervised.ca/walkies/internal/respond"
"git.unsupervised.ca/walkies/internal/server/middleware"
"github.com/go-chi/chi/v5"
)
type Handler struct {
@@ -20,7 +21,7 @@ func NewHandler(store *Store) *Handler {
// 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)
notifications, err := h.store.ListForVolunteer(r.Context(), claims.VolunteerID)
if err != nil {
respond.Error(w, http.StatusInternalServerError, "could not list notifications")
return
@@ -39,14 +40,14 @@ func (h *Handler) MarkRead(w http.ResponseWriter, r *http.Request) {
respond.Error(w, http.StatusBadRequest, "invalid id")
return
}
n, err := h.store.MarkRead(id, claims.VolunteerID)
n, err := h.store.MarkRead(r.Context(), id, claims.VolunteerID)
if errors.Is(err, ErrNotFound) {
respond.Error(w, http.StatusNotFound, "notification not found")
return
}
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)
}