api: scope profile, workout-kind, Garmin auth, and progression handlers to userID
Pulled from userIDFromContext (never a URL/body parameter) and threaded into every store call plus the per-user garmin.Client accessor.
This commit is contained in:
@@ -61,6 +61,7 @@ func metricValue(metric string, a store.Activity) (float64, bool) {
|
||||
// handleProgression returns a time series of the requested metric for every
|
||||
// activity currently assigned to a workout kind, for progression charts.
|
||||
func (s *Server) handleProgression(w http.ResponseWriter, r *http.Request) {
|
||||
userID := userIDFromContext(r.Context())
|
||||
kindID, err := strconv.ParseInt(chi.URLParam(r, "kindID"), 10, 64)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, "invalid workout kind id")
|
||||
@@ -72,7 +73,7 @@ func (s *Server) handleProgression(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
from, to := r.URL.Query().Get("from"), r.URL.Query().Get("to")
|
||||
|
||||
assignments, err := s.DB.AssignmentsForKind(r.Context(), kindID)
|
||||
assignments, err := s.DB.AssignmentsForKind(r.Context(), userID, kindID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@@ -80,7 +81,7 @@ func (s *Server) handleProgression(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
points := []progressionPoint{}
|
||||
for _, a := range assignments {
|
||||
activity, ok, err := s.DB.GetActivity(r.Context(), a.ActivityID)
|
||||
activity, ok, err := s.DB.GetActivity(r.Context(), userID, a.ActivityID)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user