Week 9: API Final Touches
April 6, 2025
Thoughts of the week
This week, I finished creating all the routes for the API. I didn't realize it would have taken me that long, but I am glad I did it to start implementing the API calls within the app. I also started to research more on storing the data on the device after calling the API. This will be important for the first calls, as it will retrieve the user's data and thresholds for the beacons, along with what workouts are tied to them.Beacon Endpoints
/api/beacons
Retrieves all beacon devices in the database. This will be used in the admin interface to manage beacon devices.
/api/beacons/:id
Retrieves a specific beacon by ID, including its proximity threshold settings and location information.
/api/beacons
Creates a new beacon in the system. Requires beaconId, name, location, proximityThreshold, and stationId fields.
/api/beacons/:id
Updates an existing beacon's information (name, proximity threshold, location, etc.).
/api/beacons/:id
Removes a beacon from the system.
Beacon Usage Endpoints
/api/beacons-in-use
Retrieves all beacons and their current usage status.
/api/beacons-in-use/:id
Retrieves the usage status of a specific beacon.
/api/beacons-in-use
Creates or updates a beacon's usage status. Requires beaconId and inUse fields.
/api/beacons-in-use/:id
Updates a beacon's usage status. Requires inUse field.
/api/beacons-in-use/:id
Removes a beacon's usage status from the system.
Station Endpoints
/api/stations
Retrieves all workout stations with their details.
/api/stations/:id
Retrieves detailed information about a specific workout station by stationId.
/api/stations
Creates a new workout station. Requires stationId, name, type, equipmentName, and location fields.
/api/stations/:id
Updates an existing station's details.
/api/stations/:id
Removes a station from the system.
/api/stations/area/:areaName
Retrieves all stations within a specific area (e.g., "Free Weights").
/api/stations/type/:typeName
Retrieves all stations of a specific type (e.g., "strength").
Exercise Endpoints
/api/exercises
Retrieves all exercises in the database.
/api/exercises/:id
Retrieves details about a specific exercise including instructions and target muscle groups.
/api/exercises
Adds a new exercise to the library. Requires exerciseId, name, description, targetMuscleGroups, defaultRepRange, and defaultSets fields.
/api/exercises/:id
Updates an existing exercise's details or instructions.
/api/exercises/:id
Removes an exercise from the system.
/api/exercises/muscle/:group
Retrieves all exercises that target a specific muscle group.
Station-Exercise Mapping Endpoints
/api/station-exercises
Retrieves all station-exercise mappings.
/api/station-exercises/station/:stationId
Retrieves all exercises associated with a specific station, ordered by display order.
/api/station-exercises/exercise/:exerciseId
Retrieves all stations that feature a specific exercise.
/api/station-exercises
Creates a new station-exercise mapping. Requires stationId, exerciseId, displayOrder, recommendedRepRange, and recommendedSets fields.
/api/station-exercises/:stationId/:exerciseId
Updates an existing station-exercise mapping's details.
/api/station-exercises/:stationId/:exerciseId
Removes a station-exercise mapping from the system.
User Endpoints
/api/users
Retrieves all users (admin function).
/api/users/:id
Retrieves a specific user's profile by userId.
/api/users
Registers a new user in the system. Requires userId, email, and name fields.
/api/users/:id
Updates a user's profile information.
/api/users/:id
Removes a user from the system.
/api/users/:id/active
Updates a user's last active timestamp.
Workout History Endpoints
/api/workout-history
Retrieves all workout history entries (admin function).
/api/workout-history/:id
Retrieves a specific workout history entry by ID.
/api/workout-history
Creates a new workout history entry when a user completes a workout. Requires userId, date, startTime, endTime, and completedStations fields.
/api/workout-history/:id
Updates an existing workout history entry.
/api/workout-history/:id
Removes a workout history entry from the system.
/api/workout-history/user/:userId
Retrieves all workout history for a specific user, sorted by date (most recent first).
/api/workout-history/range/:userId/:startDate/:endDate
Retrieves workout history for a specific user within a date range.
/api/workout-history/:id/station/:stationId/exercise
Adds a completed exercise to a station within a workout history entry.
/api/workout-history/:id/station/:stationId/exercise/:exerciseId
Updates the sets for an exercise within a station in a workout history entry.
Links
Fun Facts
When defining the model definitions for the API to read from the MongoDB database, it automatically pluralizes the collection name when it searches for a collection. So when I was trying to find the workoutHistory collection, it was trying to find workoutHistories. Wow.