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

GET/api/beacons

Retrieves all beacon devices in the database. This will be used in the admin interface to manage beacon devices.

GET/api/beacons/:id

Retrieves a specific beacon by ID, including its proximity threshold settings and location information.

POST/api/beacons

Creates a new beacon in the system. Requires beaconId, name, location, proximityThreshold, and stationId fields.

PUT/api/beacons/:id

Updates an existing beacon's information (name, proximity threshold, location, etc.).

DELETE/api/beacons/:id

Removes a beacon from the system.

Beacon Usage Endpoints

GET/api/beacons-in-use

Retrieves all beacons and their current usage status.

GET/api/beacons-in-use/:id

Retrieves the usage status of a specific beacon.

POST/api/beacons-in-use

Creates or updates a beacon's usage status. Requires beaconId and inUse fields.

PUT/api/beacons-in-use/:id

Updates a beacon's usage status. Requires inUse field.

DELETE/api/beacons-in-use/:id

Removes a beacon's usage status from the system.

Station Endpoints

GET/api/stations

Retrieves all workout stations with their details.

GET/api/stations/:id

Retrieves detailed information about a specific workout station by stationId.

POST/api/stations

Creates a new workout station. Requires stationId, name, type, equipmentName, and location fields.

PUT/api/stations/:id

Updates an existing station's details.

DELETE/api/stations/:id

Removes a station from the system.

GET/api/stations/area/:areaName

Retrieves all stations within a specific area (e.g., "Free Weights").

GET/api/stations/type/:typeName

Retrieves all stations of a specific type (e.g., "strength").

Exercise Endpoints

GET/api/exercises

Retrieves all exercises in the database.

GET/api/exercises/:id

Retrieves details about a specific exercise including instructions and target muscle groups.

POST/api/exercises

Adds a new exercise to the library. Requires exerciseId, name, description, targetMuscleGroups, defaultRepRange, and defaultSets fields.

PUT/api/exercises/:id

Updates an existing exercise's details or instructions.

DELETE/api/exercises/:id

Removes an exercise from the system.

GET/api/exercises/muscle/:group

Retrieves all exercises that target a specific muscle group.

Station-Exercise Mapping Endpoints

GET/api/station-exercises

Retrieves all station-exercise mappings.

GET/api/station-exercises/station/:stationId

Retrieves all exercises associated with a specific station, ordered by display order.

GET/api/station-exercises/exercise/:exerciseId

Retrieves all stations that feature a specific exercise.

POST/api/station-exercises

Creates a new station-exercise mapping. Requires stationId, exerciseId, displayOrder, recommendedRepRange, and recommendedSets fields.

PUT/api/station-exercises/:stationId/:exerciseId

Updates an existing station-exercise mapping's details.

DELETE/api/station-exercises/:stationId/:exerciseId

Removes a station-exercise mapping from the system.

User Endpoints

GET/api/users

Retrieves all users (admin function).

GET/api/users/:id

Retrieves a specific user's profile by userId.

POST/api/users

Registers a new user in the system. Requires userId, email, and name fields.

PUT/api/users/:id

Updates a user's profile information.

DELETE/api/users/:id

Removes a user from the system.

PUT/api/users/:id/active

Updates a user's last active timestamp.

Workout History Endpoints

GET/api/workout-history

Retrieves all workout history entries (admin function).

GET/api/workout-history/:id

Retrieves a specific workout history entry by ID.

POST/api/workout-history

Creates a new workout history entry when a user completes a workout. Requires userId, date, startTime, endTime, and completedStations fields.

PUT/api/workout-history/:id

Updates an existing workout history entry.

DELETE/api/workout-history/:id

Removes a workout history entry from the system.

GET/api/workout-history/user/:userId

Retrieves all workout history for a specific user, sorted by date (most recent first).

GET/api/workout-history/range/:userId/:startDate/:endDate

Retrieves workout history for a specific user within a date range.

POST/api/workout-history/:id/station/:stationId/exercise

Adds a completed exercise to a station within a workout history entry.

PUT/api/workout-history/:id/station/:stationId/exercise/:exerciseId

Updates the sets for an exercise within a station in a workout history entry.

Links

  • Store Data from API
  • 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.