Documentation ¶
Index ¶
- Variables
- func NewCreateHandler(l *slog.Logger, exercises Storer) http.Handler
- func NewDeleteHandler(l *slog.Logger, exercises Deleter) http.Handler
- func NewDownHandler(l *slog.Logger, exercises Orderer) http.Handler
- func NewFetchAllHandler(l *slog.Logger, exercises Retreiver) http.Handler
- func NewFetchHandler(l *slog.Logger, exercises Retreiver) http.Handler
- func NewSwapHandler(l *slog.Logger, exercises Orderer) http.Handler
- func NewUpHandler(l *slog.Logger, exercises Orderer) http.Handler
- func NewUpdateHandler(l *slog.Logger, exercises Updater) http.Handler
- type ByIndex
- type Deleter
- type Exercise
- type ExerciseRef
- type ExerciseStore
- type Orderer
- type Retreiver
- type SQLExerciseStore
- func (xs *SQLExerciseStore) ByID(owner string, workout int, exercise int) (Exercise, error)
- func (xs *SQLExerciseStore) ByWorkout(owner string, workout int) ([]Exercise, error)
- func (xs *SQLExerciseStore) ChangeName(owner string, workout int, exercise int, name string) (Exercise, error)
- func (xs *SQLExerciseStore) Delete(owner string, workout int, exercise int) (Exercise, error)
- func (xs *SQLExerciseStore) Len(owner string, workout int) (int, error)
- func (xs *SQLExerciseStore) New(owner string, workout int, name string, weight float64, repetitions int) (Exercise, error)
- func (xs *SQLExerciseStore) Swap(owner string, workout int, e1 int, e2 int) error
- func (xs *SQLExerciseStore) UpdateRepetitions(owner string, workout int, exercise int, repetitions int) (Exercise, error)
- func (xs *SQLExerciseStore) UpdateWeight(owner string, workout int, exercise int, weight float64) (Exercise, error)
- type Storer
- type Updater
- type With
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") // TODO: custom error containing which fields are invalid ErrInvalidFields = errors.New("contains invalid fields") )
Functions ¶
func NewDownHandler ¶
HandleMoveDownExercise moves a workout exercise one position down increasing the exercise index with 1 but never higher than the exercise count requires {username}, {workout}, and {exercise} path variables
func NewSwapHandler ¶
HandleSwapExercises swaps the index of the exercise with one provided requires {username}, {workout}, and {exercise} path variables requires json payload {"with": INDEX}
func NewUpHandler ¶
HandleMoveUpExercise moves a workout exercise one position up reducing the index with 1 but never lower than 1 requires {username}, {workout}, and {exercise} path variables
Types ¶
type ByIndex ¶
type ByIndex []Exercise
ByIndex implements sort.Interface, sorting exercises according to their index
type Exercise ¶
type Exercise struct { Owner string `json:"owner"` Workout int `json:"workout"` Index int `json:"index"` Name string `json:"name"` Weight float64 `json:"weight"` Repetitions int `json:"repetitions"` }
Exercise contains details of a single workout exercise an exercise is a node in a linked list, determining the order
type ExerciseRef ¶
ExerciseRef represents the unique key that references an Exercise
func ParseRef ¶
func ParseRef(s string) (ExerciseRef, error)
func (ExerciseRef) String ¶
func (er ExerciseRef) String() string
type Retreiver ¶
type Retreiver interface { // ByID takes an excercise id and returns the exercise // from the exercises repository if it exists ByID(owner string, workout int, exercise int) (Exercise, error) // ByWorkout returns all exercises belongign to an user's workout ByWorkout(owner string, workout int) ([]Exercise, error) }
Implementation of the Retreiver interface enables querying exercises
type SQLExerciseStore ¶
type SQLExerciseStore struct {
*storage.SqliteDatastore
}
func NewSQLExerciseStore ¶
func NewSQLExerciseStore(db *storage.SqliteDatastore) *SQLExerciseStore
func (*SQLExerciseStore) ByID ¶
ExerciseByID returns an exercise from the database if exists otherwise returns NotFound error
func (*SQLExerciseStore) ByWorkout ¶
func (xs *SQLExerciseStore) ByWorkout(owner string, workout int) ([]Exercise, error)
func (*SQLExerciseStore) ChangeName ¶
func (*SQLExerciseStore) Len ¶
func (xs *SQLExerciseStore) Len(owner string, workout int) (int, error)
func (*SQLExerciseStore) UpdateRepetitions ¶
func (*SQLExerciseStore) UpdateWeight ¶
type Storer ¶
type Storer interface { // New stores an exercise at the tail, // updating the references and returns the exercise. // user and workout must exist before adding exercise New(owner string, workout int, name string, weight float64, repetitions int) (Exercise, error) }
Implementation of the Storer interface enables creating new exercises
type Updater ¶
type Updater interface { // ChangeName updates the name of an existing exercise ChangeName(owner string, workout int, exercise int, newName string) (Exercise, error) // UpdateWeight updates the weight of an existing exercise UpdateWeight(owner string, workout int, exercise int, newWeight float64) (Exercise, error) // UpdateRepetitions updates the repetitions of an existing exercise UpdateRepetitions(owner string, workout int, exercise int, newRepetitions int) (Exercise, error) }
Implemention of Updater interface enables updating exercises
type With ¶
type With struct {
Exercise ExerciseRef
}
With is used to represent the target exercise used to swap exercises