lots of stuff, don't truly remember

This commit is contained in:
Blake Ridgway
2026-05-17 20:39:47 -05:00
parent 178ffb3425
commit dc4fe558b7
35 changed files with 3501 additions and 112 deletions

View File

@@ -110,6 +110,73 @@ func (h *Handler) GetMonthlyStats(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(stats)
}
// GetTrainingLoad GET /api/protected/stats/training-load?days=180
func (h *Handler) GetTrainingLoad(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value(middleware.UserContextKey).(*config.CustomClaims)
if claims == nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(map[string]string{"error": "unauthorized"})
return
}
days := 180
if dStr := r.URL.Query().Get("days"); dStr != "" {
if parsed, err := strconv.Atoi(dStr); err == nil {
days = parsed
}
}
data, ftp, err := h.service.GetTrainingLoad(claims.UserID, days)
if err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "failed to fetch training load"})
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]interface{}{
"ftp": ftp,
"daily_tss": data,
})
}
// GetPowerHistory GET /api/protected/stats/power-history?days=365
func (h *Handler) GetPowerHistory(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value(middleware.UserContextKey).(*config.CustomClaims)
if claims == nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(map[string]string{"error": "unauthorized"})
return
}
days := 365
if dStr := r.URL.Query().Get("days"); dStr != "" {
if parsed, err := strconv.Atoi(dStr); err == nil {
days = parsed
}
}
data, err := h.service.GetPowerHistory(claims.UserID, days)
if err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "failed to fetch power history"})
return
}
if data == nil {
data = []PowerPoint{}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(data)
}
// GetPersonalBests GET /api/protected/stats/personal-bests
func (h *Handler) GetPersonalBests(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value(middleware.UserContextKey).(*config.CustomClaims)