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:
@@ -2,6 +2,7 @@ package checkin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"git.unsupervised.ca/walkies/internal/respond"
|
||||
@@ -24,11 +25,15 @@ func (h *Handler) CheckIn(w http.ResponseWriter, r *http.Request) {
|
||||
respond.Error(w, http.StatusBadRequest, "invalid request body")
|
||||
return
|
||||
}
|
||||
ci, err := h.store.CheckIn(claims.VolunteerID, in)
|
||||
if err != nil {
|
||||
ci, err := h.store.CheckIn(r.Context(), claims.VolunteerID, in)
|
||||
if errors.Is(err, ErrAlreadyCheckedIn) {
|
||||
respond.Error(w, http.StatusConflict, err.Error())
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
respond.Error(w, http.StatusInternalServerError, "could not check in")
|
||||
return
|
||||
}
|
||||
respond.JSON(w, http.StatusCreated, ci)
|
||||
}
|
||||
|
||||
@@ -37,11 +42,15 @@ func (h *Handler) CheckOut(w http.ResponseWriter, r *http.Request) {
|
||||
claims := middleware.ClaimsFromContext(r.Context())
|
||||
var in CheckOutInput
|
||||
json.NewDecoder(r.Body).Decode(&in)
|
||||
ci, err := h.store.CheckOut(claims.VolunteerID, in)
|
||||
if err != nil {
|
||||
ci, err := h.store.CheckOut(r.Context(), claims.VolunteerID, in)
|
||||
if errors.Is(err, ErrNotCheckedIn) {
|
||||
respond.Error(w, http.StatusConflict, err.Error())
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
respond.Error(w, http.StatusInternalServerError, "could not check out")
|
||||
return
|
||||
}
|
||||
respond.JSON(w, http.StatusOK, ci)
|
||||
}
|
||||
|
||||
@@ -52,7 +61,7 @@ func (h *Handler) History(w http.ResponseWriter, r *http.Request) {
|
||||
if claims.Role != "admin" {
|
||||
volunteerID = claims.VolunteerID
|
||||
}
|
||||
history, err := h.store.History(volunteerID)
|
||||
history, err := h.store.History(r.Context(), volunteerID)
|
||||
if err != nil {
|
||||
respond.Error(w, http.StatusInternalServerError, "could not get history")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user