- New users table (migration 004) with user_id on exercises, training_sets, sessions
- User CRUD endpoints (GET/POST /api/v1/users, DELETE /api/v1/users/{id})
- All existing endpoints scoped to X-User-ID header
- CSV export endpoint (GET /api/v1/export) for completed sessions
- UserGate in PageShell: blocks app until a user is selected
- Settings page for managing users (create, switch, delete)
- BottomNav/Sidebar updated with settings navigation
- Fix: nil pointer panic in handleDeleteUser on success path
- Fix: export download now uses fetch with X-User-ID header instead of window.location.href
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.5 KiB
Go
Executable File
64 lines
1.5 KiB
Go
Executable File
package handler
|
|
|
|
import "net/http"
|
|
|
|
func (h *Handler) handleGetLastLog(w http.ResponseWriter, r *http.Request) {
|
|
uid, err := userID(r)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
id, err := pathID(r, "id")
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "Ungültige ID")
|
|
return
|
|
}
|
|
|
|
lastLog, err := h.store.GetLastLog(id, uid)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "Fehler beim Laden des letzten Logs")
|
|
return
|
|
}
|
|
if lastLog == nil {
|
|
writeError(w, http.StatusNotFound, "Noch kein Log für diese Übung")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, lastLog)
|
|
}
|
|
|
|
func (h *Handler) handleGetExerciseHistory(w http.ResponseWriter, r *http.Request) {
|
|
uid, err := userID(r)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
id, err := pathID(r, "id")
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "Ungültige ID")
|
|
return
|
|
}
|
|
limit := queryInt(r, "limit", 30)
|
|
|
|
logs, err := h.store.GetExerciseHistory(id, uid, limit)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "Fehler beim Laden der Übungshistorie")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, logs)
|
|
}
|
|
|
|
func (h *Handler) handleGetStatsOverview(w http.ResponseWriter, r *http.Request) {
|
|
uid, err := userID(r)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, err.Error())
|
|
return
|
|
}
|
|
|
|
overview, err := h.store.GetStatsOverview(uid)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "Fehler beim Laden der Statistiken")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, overview)
|
|
}
|