Replace per-kind reclassify with a single global reclassify that respects manual and Race locks

Manual assignments are the user's definitive word and Race assignments come
from a hard Garmin fact (eventType.typeKey), not a retunable rule -- neither
is ever touched by reclassify again, and Race can no longer be set by hand
via the review queue. Adds an Activities page so this locked/unlocked status
is visible per workout, since Review Queue only ever showed unresolved items.
This commit is contained in:
2026-07-19 11:11:50 +02:00
parent 8ff3d62b2f
commit 0610897541
15 changed files with 398 additions and 60 deletions

View File

@@ -9,6 +9,21 @@ import (
"smartrun/backend/internal/store"
)
// activityListItem is one row of the activities list, enriched with its
// current classification so the frontend can show what kind it's assigned
// to and whether that assignment is locked (see Locked's doc comment).
type activityListItem struct {
store.Activity
WorkoutKindID *int64 `json:"workout_kind_id"`
WorkoutKindName *string `json:"workout_kind_name"`
AssignmentSource *string `json:"assignment_source"`
AssignmentStatus *string `json:"assignment_status"`
// Locked is true when a global reclassify pass will never touch this
// activity again: a manual assignment is the user's definitive word, and
// a Race assignment comes from a hard Garmin fact, not a retunable rule.
Locked bool `json:"locked"`
}
func (s *Server) handleListActivities(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
filter := store.ActivityFilter{
@@ -27,7 +42,40 @@ func (s *Server) handleListActivities(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
writeJSON(w, http.StatusOK, activities)
kinds, err := s.DB.ListWorkoutKinds(r.Context(), false)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
kindNames := make(map[int64]string, len(kinds))
for _, k := range kinds {
kindNames[k.ID] = k.Name
}
resp := make([]activityListItem, 0, len(activities))
for _, a := range activities {
item := activityListItem{Activity: a}
assignment, ok, err := s.DB.CurrentAssignment(r.Context(), a.ID)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
if ok {
source, status := assignment.AssignmentSource, assignment.Status
item.AssignmentSource, item.AssignmentStatus = &source, &status
if assignment.WorkoutKindID != nil {
item.WorkoutKindID = assignment.WorkoutKindID
if name, found := kindNames[*assignment.WorkoutKindID]; found {
item.WorkoutKindName = &name
}
}
item.Locked = source == store.AssignmentSourceManual ||
(item.WorkoutKindName != nil && *item.WorkoutKindName == "Race")
}
resp = append(resp, item)
}
writeJSON(w, http.StatusOK, resp)
}
func (s *Server) handleGetActivity(w http.ResponseWriter, r *http.Request) {