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:
2026-07-25 18:16:06 +02:00
parent 5930cc4ef5
commit eaca8e602b
4 changed files with 46 additions and 21 deletions

View File

@@ -36,7 +36,8 @@ func validateProfile(p store.Profile) error {
}
func (s *Server) handleGetProfile(w http.ResponseWriter, r *http.Request) {
p, err := s.DB.GetProfile(r.Context())
userID := userIDFromContext(r.Context())
p, err := s.DB.GetProfile(r.Context(), userID)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
@@ -45,6 +46,7 @@ func (s *Server) handleGetProfile(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) handleUpdateProfile(w http.ResponseWriter, r *http.Request) {
userID := userIDFromContext(r.Context())
var p store.Profile
if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
writeError(w, http.StatusBadRequest, "invalid request body")
@@ -55,13 +57,18 @@ func (s *Server) handleUpdateProfile(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.DB.UpdateProfile(r.Context(), p); err != nil {
if err := s.DB.UpdateProfile(r.Context(), userID, p); err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
s.Garmin.UpdateCredentials(p.GarminEmail, p.GarminPassword)
client, err := s.garminFor(r.Context(), userID)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
client.UpdateCredentials(p.GarminEmail, p.GarminPassword)
updated, err := s.DB.GetProfile(r.Context())
updated, err := s.DB.GetProfile(r.Context(), userID)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return