# Workout Plans API
Add a `workoutPlan` field when `POST`ing a new class:
Example POST with timed and set exercises
```json
{
"active": true,
"classID": 333,
"name": "Workn' it",
"setExercises": [
{
"index": 1,
"name": "Curls for the girls",
"sets": 3,
"reps": 12,
},
{
"index": 3,
"name": "Tris for the guys",
"sets": 3,
"reps": 12,
},
],
"timedExercises": [
{
"index": 2,
"name": "Plank n stank",
"duration": 60
}
]
}
```
Proposed GET schema per workout plan
```json
{
"active": true,
"classID": 333,
"name": "Workn' it",
"exercises": [
{
"index": 1,
"name": "Curls for the girls",
"sets": 3,
"reps": 12,
},
{
"index": 2,
"name": "Plank n stank",
"duration": 60
},
{
"index": 3,
"name": "Tris for the guys",
"sets": 3,
"reps": 12,
},
],
}
```
Database schema:
```sql
CREATE TABLE workout_plans(
id SERIAL NOT NULL PRIMARY KEY,
uuid VARCHAR(50) NOT NULL,
name VARCHAR(100) NOT NULL,
active BOOLEAN NOT NULL DEFAULT false,
deleted BOOLEAN NOT NULL DEFAULT false,
);
CREATE TABLE workout_plan_to_class(
id SERIAL NOT NULL PRIMARY KEY,
workout_plan_id INT NOT NULL REFERENCES workout_plans(id),
class_id INT NOT NULL REFERENCES classes(id)
);
CREATE TABLE set_exercises(
id SERIAL NOT NULL PRIMARY KEY,
workout_plan_id INT NOT NULL REFERENCES workout_plans(id),
name VARCHAR(50) NOT NULL,
workout_plan_index INT NOT NULL,
sets INT NOT NULL,
reps INT NOT NULL
);
CREATE TABLE timed_exercises(
id SERIAL NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
workout_plan_id INT NOT NULL REFERENCES workout_plans(id),
workout_plan_index INT NOT NULL,
duration INT NOT NULL,
);
```
Considerations @uPrUrRzIRz-19hBKroZl9g
- In our discussions, a workout plan has a name. So, when a workout plan is created as part of a class (as above), should we just give it the same name as the class for now? Pros of this approach:
- the backend supports names for workout plans from the start, then once we wan to create workout plans independent of clases we can just include a `name` field in the API that will already have a place in the DB
- we have (what seems to be) a sensible default in the case of creating a new class for now
- We discussed tagging exercises with their respective pieces of equipment. However, the dashboard doesn't currently have a way to associate exercises with equipment. Equipment tags are added to a class, then a workout plan is added to that class. How should we handle this? Two options seem to be:
1. Associate all equipment tags for a class with the workout plan for now, rather than specific exercises (easy, no updates to frontend, may require clarification to users as to which exercises use which equipment but it also might be obvious in most cases)
2. Have a way to specific equipment per-exercise (very involved, requires designs + frontend changes)
Daniel: I think we should do both, #1 and #2 listed below. We can start with #1.
Regarding the Workout Plan within a class that can work for creation, however when we return Workout Plans we need to include an array of class_ids it relates to.
For Workout Plans I'd like to see the array of exercises under a key called exercises, that way we can add top level metadata to the workout plan.