lots of stuff, don't truly remember
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user