| 12 | "github.com/go-playground/validator/v10" |
| 13 | ) |
| 14 | |
| 15 | // Days/Exercises/Sets in CreateProgramRequest each cap at max=500 independently |
| 16 | // (models.go), which doesn't bound their product across three nested levels — a |
| 17 | // request with 500 days x 500 exercises x 500 sets still passes those tags. This |
| 18 | // struct-level check enforces the total-rows bound (models.MaxProgramRows) that |
| 19 | // insertProgramDays's single-transaction processing actually needs, since |
| 20 | // db.DB.SetMaxOpenConns(1) means that transaction holds the process's only SQLite |
| 21 | // connection for the whole request. Mirrors controllers/workouts.go's init(). |
| 22 | func init() { |
| 23 | validate.RegisterStructValidation(func(sl validator.StructLevel) { |
| 24 | req := sl.Current().Interface().(models.CreateProgramRequest) |
| 25 | total := 0 |
| 26 | for _, d := range req.Days { |
| 27 | total++ |
| 28 | for _, ex := range d.Exercises { |
| 29 | total++ |
| 30 | total += len(ex.Sets) |
| 31 | } |