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:
64
internal/checkin/handler.go
Normal file
64
internal/checkin/handler.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package checkin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"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}
|
||||
}
|
||||
|
||||
// POST /api/v1/checkin
|
||||
func (h *Handler) CheckIn(w http.ResponseWriter, r *http.Request) {
|
||||
claims := middleware.ClaimsFromContext(r.Context())
|
||||
var in CheckInInput
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
respond.Error(w, http.StatusBadRequest, "invalid request body")
|
||||
return
|
||||
}
|
||||
ci, err := h.store.CheckIn(claims.VolunteerID, in)
|
||||
if err != nil {
|
||||
respond.Error(w, http.StatusConflict, err.Error())
|
||||
return
|
||||
}
|
||||
respond.JSON(w, http.StatusCreated, ci)
|
||||
}
|
||||
|
||||
// POST /api/v1/checkout
|
||||
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 {
|
||||
respond.Error(w, http.StatusConflict, err.Error())
|
||||
return
|
||||
}
|
||||
respond.JSON(w, http.StatusOK, ci)
|
||||
}
|
||||
|
||||
// GET /api/v1/checkin/history
|
||||
func (h *Handler) History(w http.ResponseWriter, r *http.Request) {
|
||||
claims := middleware.ClaimsFromContext(r.Context())
|
||||
volunteerID := int64(0)
|
||||
if claims.Role != "admin" {
|
||||
volunteerID = claims.VolunteerID
|
||||
}
|
||||
history, err := h.store.History(volunteerID)
|
||||
if err != nil {
|
||||
respond.Error(w, http.StatusInternalServerError, "could not get history")
|
||||
return
|
||||
}
|
||||
if history == nil {
|
||||
history = []CheckIn{}
|
||||
}
|
||||
respond.JSON(w, http.StatusOK, history)
|
||||
}
|
||||
Reference in New Issue
Block a user