Documentation
¶
Index ¶
- Variables
- type Exercise
- type HealthChecker
- type PauseOptions
- type Store
- func (s *Store) BackfillCoreExercises(ctx context.Context) error
- func (s *Store) Close()
- func (s *Store) CreateExercise(ctx context.Context, name, ownerUserID string, isCore bool) (*Exercise, error)
- func (s *Store) CreateTemplateFromWorkout(ctx context.Context, workoutID string, nameOverride string) (*Workout, error)
- func (s *Store) CreateUser(ctx context.Context, email, avatarURL, passwordHash string) (*User, error)
- func (s *Store) CreateWorkout(ctx context.Context, w *Workout) (*Workout, error)
- func (s *Store) CreateWorkoutFromTemplate(ctx context.Context, templateID, userID, name string) (*Workout, error)
- func (s *Store) DeleteExercise(ctx context.Context, id string) error
- func (s *Store) DeleteWorkout(ctx context.Context, workoutID string) error
- func (s *Store) EnsureSchema(ctx context.Context, logger *slog.Logger) error
- func (s *Store) GetExercise(ctx context.Context, id string) (*Exercise, error)
- func (s *Store) GetUser(ctx context.Context, id string) (*User, error)
- func (s *Store) GetUserWithPassword(ctx context.Context, id string) (*User, string, error)
- func (s *Store) ListExercises(ctx context.Context, userID string) ([]Exercise, error)
- func (s *Store) ListTemplates(ctx context.Context) ([]Workout, error)
- func (s *Store) ListUsers(ctx context.Context) ([]User, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) RecordTraining(ctx context.Context, log TrainingLog, steps []TrainingStepLog) error
- func (s *Store) RenameExercise(ctx context.Context, id, name string) (*Exercise, error)
- func (s *Store) ReplaceExerciseForUser(ctx context.Context, userID, fromID, toID, toName string) error
- func (s *Store) TrainingHistory(ctx context.Context, userID string, limit int) ([]TrainingLog, error)
- func (s *Store) TrainingStepTimings(ctx context.Context, trainingID string) ([]TrainingStepLog, error)
- func (s *Store) UpdateUserAdmin(ctx context.Context, userID string, isAdmin bool) error
- func (s *Store) UpdateUserName(ctx context.Context, userID, name string) error
- func (s *Store) UpdateUserPassword(ctx context.Context, userID, passwordHash string) error
- func (s *Store) UpdateWorkout(ctx context.Context, w *Workout) (*Workout, error)
- func (s *Store) UpsertAdminUser(ctx context.Context, email, passwordHash string) (*User, bool, error)
- func (s *Store) WorkoutSteps(ctx context.Context, workoutID string) ([]WorkoutStep, error)
- func (s *Store) WorkoutWithSteps(ctx context.Context, workoutID string) (*Workout, error)
- func (s *Store) WorkoutsByUser(ctx context.Context, userID string) ([]Workout, error)
- type SubsetExercise
- type TrainingLog
- type TrainingStepLog
- type User
- type Workout
- type WorkoutStep
- type WorkoutSubset
Constants ¶
This section is empty.
Variables ¶
var ErrWorkoutNotFound = errors.New("workout not found")
ErrWorkoutNotFound indicates that the referenced workout does not exist.
Functions ¶
This section is empty.
Types ¶
type Exercise ¶
type Exercise struct {
ID string `json:"id"` // ID is the unique catalog identifier.
Name string `json:"name"` // Name is the exercise label.
OwnerUserID string `json:"ownerUserId,omitempty"` // OwnerUserID is set for user-owned entries.
IsCore bool `json:"isCore"` // IsCore marks built-in exercises.
CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the entry was created.
}
Exercise represents a reusable exercise catalog entry.
type HealthChecker ¶ added in v0.0.20
HealthChecker is the minimal interface needed for health checks.
type PauseOptions ¶
type PauseOptions struct {
AutoAdvance bool `json:"autoAdvance,omitempty"` // AutoAdvance skips to the next step on completion.
}
PauseOptions captures optional behaviour for pause steps.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps all database access.
func (*Store) BackfillCoreExercises ¶
BackfillCoreExercises creates core exercises from existing workout data and links them.
func (*Store) CreateExercise ¶
func (s *Store) CreateExercise(ctx context.Context, name, ownerUserID string, isCore bool) (*Exercise, error)
CreateExercise inserts a new exercise entry.
func (*Store) CreateTemplateFromWorkout ¶
func (s *Store) CreateTemplateFromWorkout(ctx context.Context, workoutID string, nameOverride string) (*Workout, error)
CreateTemplateFromWorkout clones an existing workout as a template.
func (*Store) CreateUser ¶
func (s *Store) CreateUser(ctx context.Context, email, avatarURL, passwordHash string) (*User, error)
CreateUser inserts a new user with the provided password hash.
func (*Store) CreateWorkout ¶
CreateWorkout inserts a workout and its steps for a user.
func (*Store) CreateWorkoutFromTemplate ¶
func (s *Store) CreateWorkoutFromTemplate(ctx context.Context, templateID, userID, name string) (*Workout, error)
CreateWorkoutFromTemplate copies an existing template to a user.
func (*Store) DeleteExercise ¶
DeleteExercise removes an exercise and clears linked workout rows.
func (*Store) DeleteWorkout ¶
DeleteWorkout removes a workout and cascades its steps.
func (*Store) EnsureSchema ¶
EnsureSchema applies the baseline schema and any pending migrations.
func (*Store) GetExercise ¶
GetExercise fetches a single exercise by id.
func (*Store) GetUserWithPassword ¶
GetUserWithPassword fetches a user and password hash by id.
func (*Store) ListExercises ¶
ListExercises returns core exercises plus user-owned exercises.
func (*Store) ListTemplates ¶
ListTemplates returns all workout templates.
func (*Store) RecordTraining ¶ added in v0.0.28
func (s *Store) RecordTraining(ctx context.Context, log TrainingLog, steps []TrainingStepLog) error
RecordTraining stores a completed workout training and optional step timings. Duplicate IDs are ignored.
func (*Store) RenameExercise ¶
RenameExercise updates the catalog name and linked workout exercise names.
func (*Store) ReplaceExerciseForUser ¶
func (s *Store) ReplaceExerciseForUser(ctx context.Context, userID, fromID, toID, toName string) error
ReplaceExerciseForUser swaps a user workout's exercise references to a new exercise id.
func (*Store) TrainingHistory ¶ added in v0.0.28
func (s *Store) TrainingHistory(ctx context.Context, userID string, limit int) ([]TrainingLog, error)
TrainingHistory returns recent trainings for a user.
func (*Store) TrainingStepTimings ¶ added in v0.0.28
func (s *Store) TrainingStepTimings(ctx context.Context, trainingID string) ([]TrainingStepLog, error)
TrainingStepTimings returns stored step durations for a training.
func (*Store) UpdateUserAdmin ¶
UpdateUserAdmin sets the admin flag for a user.
func (*Store) UpdateUserName ¶ added in v0.0.18
UpdateUserName changes the display name for a user.
func (*Store) UpdateUserPassword ¶
UpdateUserPassword sets the password hash for a user.
func (*Store) UpdateWorkout ¶
UpdateWorkout replaces the workout name and steps.
func (*Store) UpsertAdminUser ¶
func (s *Store) UpsertAdminUser(ctx context.Context, email, passwordHash string) (*User, bool, error)
UpsertAdminUser ensures the admin user exists with the given password hash.
func (*Store) WorkoutSteps ¶
WorkoutSteps fetches all steps for a workout ordered by step order.
func (*Store) WorkoutWithSteps ¶
WorkoutWithSteps retrieves a workout by id.
type SubsetExercise ¶ added in v0.0.20
type SubsetExercise struct {
ID string `json:"id"` // ID is the unique exercise row identifier.
SubsetID string `json:"subsetId"` // SubsetID links to the parent subset.
Order int `json:"order"` // Order is the exercise sequence within the subset.
ExerciseID string `json:"exerciseId"` // ExerciseID links to the catalog entry.
Name string `json:"name"` // Name is the exercise label.
Type string `json:"type"` // Type is rep, stopwatch, or countdown.
Reps string `json:"reps"` // Reps is the repetition text.
Weight string `json:"weight"` // Weight is optional load text.
Duration string `json:"duration"` // Duration is a stopwatch/countdown value.
SoundKey string `json:"soundKey"` // SoundKey overrides the subset sound.
}
type TrainingLog ¶ added in v0.0.28
type TrainingLog struct {
ID string `json:"id"` // ID is the unique training identifier.
WorkoutID string `json:"workoutId"` // WorkoutID links to the workout.
WorkoutName string `json:"workoutName"` // WorkoutName is the display name at completion time.
UserID string `json:"userId"` // UserID owns the training.
StartedAt time.Time `json:"startedAt"` // StartedAt is when the training began.
CompletedAt time.Time `json:"completedAt"` // CompletedAt is when the training finished.
}
TrainingLog represents a completed workout training.
type TrainingStepLog ¶ added in v0.0.28
type TrainingStepLog struct {
ID string `json:"id"` // ID is the unique log row identifier.
TrainingID string `json:"trainingId"` // TrainingID links to the training.
StepOrder int `json:"stepOrder"` // StepOrder preserves training ordering.
Type string `json:"type"` // Type is the step kind.
Name string `json:"name"` // Name is the step label.
EstimatedSeconds int `json:"estimatedSeconds"` // EstimatedSeconds is the target duration.
ElapsedMillis int64 `json:"elapsedMillis"` // ElapsedMillis is the observed duration.
}
TrainingStepLog captures actual timing for a completed step.
type User ¶
type User struct {
ID string `json:"id"` // ID is the unique user identifier.
Name string `json:"name"` // Name is the display name.
IsAdmin bool `json:"isAdmin"` // IsAdmin marks admin privileges.
AvatarURL string `json:"avatarUrl"` // AvatarURL is the optional avatar image.
CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the user was created.
}
User represents an account owner.
type Workout ¶
type Workout struct {
ID string `json:"id"` // ID is the unique workout identifier.
UserID string `json:"userId"` // UserID owns the workout.
Name string `json:"name"` // Name is the workout title.
IsTemplate bool `json:"isTemplate"` // IsTemplate marks shared templates.
CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the workout was created.
Steps []WorkoutStep `json:"steps"` // Steps defines the workout flow.
}
Workout groups stopwatch steps.
type WorkoutStep ¶
type WorkoutStep struct {
ID string `json:"id"` // ID is the unique step identifier.
WorkoutID string `json:"workoutId"` // WorkoutID links to the parent workout.
Order int `json:"order"` // Order defines the step sequence.
Type string `json:"type"` // Type is set or pause.
Name string `json:"name"` // Name is the step label.
EstimatedSeconds int `json:"estimatedSeconds"` // EstimatedSeconds is the target duration.
SoundKey string `json:"soundKey"` // SoundKey plays on step completion.
Subsets []WorkoutSubset `json:"subsets"` // Subsets hold exercises for set steps.
PauseOptions PauseOptions `json:"pauseOptions,omitempty"` // PauseOptions configure pause behavior.
RepeatCount int `json:"repeatCount,omitempty"` // RepeatCount repeats the step group.
RepeatRestSeconds int `json:"repeatRestSeconds,omitempty"` // RepeatRestSeconds is rest between repeats.
RepeatRestAfterLast bool `json:"repeatRestAfterLast,omitempty"` // RepeatRestAfterLast includes rest after last repeat.
RepeatRestSoundKey string `json:"repeatRestSoundKey,omitempty"` // RepeatRestSoundKey plays during repeat rest.
RepeatRestAutoAdvance bool `json:"repeatRestAutoAdvance,omitempty"` // RepeatRestAutoAdvance skips repeat rest automatically.
RepeatRestName string `json:"repeatRestName,omitempty"` // RepeatRestName overrides the repeat pause label.
CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the step was created.
}
WorkoutStep defines a single part of the workout.
func (*WorkoutStep) NormalizeRepeatSettings ¶ added in v0.0.18
func (w *WorkoutStep) NormalizeRepeatSettings()
NormalizeRepeatSettings clamps and clears repeat rest settings for a step.
type WorkoutSubset ¶ added in v0.0.20
type WorkoutSubset struct {
ID string `json:"id"` // ID is the unique subset identifier.
StepID string `json:"stepId"` // StepID links to the parent step.
Order int `json:"order"` // Order is the subset sequence within the step.
Name string `json:"name"` // Name is the subset label.
EstimatedSeconds int `json:"estimatedSeconds"` // EstimatedSeconds is the subset target.
SoundKey string `json:"soundKey"` // SoundKey plays at the subset target.
Superset bool `json:"superset"` // Superset skips to the next subset on Next.
Exercises []SubsetExercise `json:"exercises"` // Exercises belong to the subset.
CreatedAt time.Time `json:"createdAt"` // CreatedAt records when the subset was created.
}