Initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
backend/internal/model/exercise.go
Executable file
47
backend/internal/model/exercise.go
Executable file
@@ -0,0 +1,47 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Exercise repräsentiert eine Kraftübung.
|
||||
type Exercise struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
MuscleGroup string `json:"muscle_group"`
|
||||
WeightStepKg float64 `json:"weight_step_kg"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// CreateExerciseRequest enthält die Felder zum Anlegen einer Übung.
|
||||
type CreateExerciseRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
MuscleGroup string `json:"muscle_group"`
|
||||
WeightStepKg *float64 `json:"weight_step_kg"`
|
||||
}
|
||||
|
||||
// Validate prüft und normalisiert den Request. Setzt Default für WeightStepKg.
|
||||
func (r *CreateExerciseRequest) Validate() error {
|
||||
r.Name = strings.TrimSpace(r.Name)
|
||||
if len(r.Name) == 0 || len(r.Name) > 100 {
|
||||
return errors.New("Name muss 1–100 Zeichen lang sein")
|
||||
}
|
||||
if !ValidMuscleGroup(r.MuscleGroup) {
|
||||
return errors.New("Ungültige Muskelgruppe")
|
||||
}
|
||||
if r.WeightStepKg != nil {
|
||||
if *r.WeightStepKg <= 0 {
|
||||
return errors.New("Gewichtsschritt muss > 0 sein")
|
||||
}
|
||||
} else {
|
||||
def := 2.5
|
||||
r.WeightStepKg = &def
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user