Skip to content

Repository files navigation

API Reference

Complete catalog of available endpoints, authentication, and expected payloads. All routes are mounted under http://localhost:3000/api/v1.

Auth & Environment

  • JWT bearer: Authorization: Bearer <token> (validated by authToken).
  • Env: JWT_SECRET, GEMINI_API_KEY (for AI), DB_URL, NODE_ENV.
  • File uploads use multipart/form-data (Cloudinary via uploadFiles).

Services & Endpoints

Auth (/auth)

  • GET /login/success — returns logged-in user + JWT cookie after OAuth.
  • GET /login/failed — login failure.
  • GET /google — start Google OAuth.
  • GET /google/callback — Google OAuth callback, issues JWT cookie + JSON.
  • GET /logout — clears auth cookie.

Users (/users)

  • POST /signup — create user. Body (validated): name, email, password (≥6 unless googleId provided), optional googleId, profilePic, age, height, weight, fitnessGoal, activityLevel.
  • POST /login — email/password login.
  • POST /admin-login — admin credentials login.
  • PUT /change-password (auth) — body: currentPassword, password, confirmPassword.
  • POST /forgot-password — start reset (sends code).
  • POST /check-otp — verify reset code.
  • POST /reset-password — complete reset.
  • GET /my-profile (auth) — current user profile.
  • GET /followers/:id — list followers.
  • GET /following/:id — list following.
  • GET /top-users — leaderboard of top users.
  • PUT /update-info (auth) — update profile (same schema as signup; extra fields allowed).
  • PUT /changeRole/:id (auth admin) — change user role.
  • POST /follow/:id (auth) — follow user.
  • POST /unfollow/:id (auth) — unfollow user.
  • POST /admin/add (auth admin) — create admin user.
  • PATCH /profile-picture (auth, multipart) — upload image.
  • GET / — list users.
  • GET /:id — get user by id.
  • PATCH /:id — update user by id (no auth enforced in router).
  • DELETE /:id (auth) — delete user.

AI Chatbot (/chatbot)

  • POST /ask (auth) — body: message (1–1000 chars). Returns { reply } from Gemini 1.5 Flash and stores chat history per user.
  • GET /user-chats/:userId — get stored chat history for a user (no auth enforced).

Workouts (/workout)

  • POST /create (multipart) — fields: name (3–100), description (≤300), optional exercises array, image file, video file.
  • GET / — list workouts.
  • GET /list/names — list workout names.
  • GET /:workoutId — get workout by id.
  • GET /workout-exercises/:workoutId — workout with exercises populated.
  • PUT /:workoutId (multipart) — update; same fields as create.
  • DELETE /:workoutId — delete workout.

Exercises (/exercise)

  • POST /create (multipart) — fields: name (≥2), description (10–500), targetMuscles, secondaryMuscles, equipment (bodyweight|dumbbell|barbell|machine|resistance band), difficulty (beginner|intermediate|advanced), optional videoUrl, image file(s), video file(s), workoutName (required).
  • GET /latest — latest exercises.
  • GET / — list exercises.
  • GET /:id — get exercise by id.
  • PUT /:id (multipart) — update exercise; file fields optional.
  • DELETE /:id — delete exercise.

Community (/community)

Posts:

  • GET /posts/getPosts — list posts.
  • POST /posts/createPost (auth, multipart) — body: content (5–1500), optional imageUrls[], videoUrls[] (or uploaded files).
  • GET /posts/getPostById/:id — get single post.
  • GET /posts/details/:id — post with extra details.
  • DELETE /posts/deletePostById/:id (auth) — delete post.
  • PUT /posts/edit/:id (auth, multipart) — update post content/media. Likes/Shares:
  • POST /like/:postId (auth) — like post.
  • POST /unlike/:postId (auth) — unlike.
  • POST /share/:postId (auth) — share.
  • DELETE /undoshare/:postId (auth) — undo share. Comments:
  • GET /posts/getComments/:id — list comments.
  • POST /comments/addComment/:postId (auth) — body: content (2–500).
  • POST /comments/replyToComment/:commentId (auth) — reply body same as comment.
  • PATCH /comments/editComment/:commentId (auth) — edit comment.
  • DELETE /comments/deleteComment/:commentId (auth) — delete. User feeds:
  • GET /following/posts (auth) — posts from following.
  • GET /user-posts/:id — posts by user.
  • GET /user-shares (auth) — posts current user shared.
  • GET /user-all-posts (auth) — current user posts + shares.

Trivia Questions (/trivia-questions)

  • POST /createTriviaQuestion — body: question (5–500), options (2–4 strings), correctAnswer, optional points (default 10).
  • GET /getTriviaQuestions — list all.
  • GET /:id — get one.
  • PUT /:id — update.
  • DELETE /:id — delete.

Challenges (/challenge)

  • POST /create — create challenge (no auth enforced). Body varies by type:
    • type: "exercise" + exerciseId (ObjectId), calcMethod (reps|time), optional target, points.
    • type: "trivia" + questionId (ObjectId), optional timeLimit, points.
  • GET / — list challenges.
  • GET /:id — get challenge.
  • PUT /:id — update challenge.
  • DELETE /:id — delete challenge.

Challenge Sessions (/challengeSession)

  • POST /createSession (auth) — create a session (body handled in controller).
  • POST /join/:sessionId (auth) — join session.
  • POST /start/:sessionId (auth) — start session.
  • POST /end/:sessionId (auth) — end session.
  • GET / — list sessions.

Challenge Progress & Leaderboards (/challenge-progress)

  • POST /update — update user progress for a session.
  • GET /leaderboard/last-session — leaderboard for most recent completed session.
  • GET /leaderboard/:sessionId — leaderboard by session.
  • GET /user-sessions/:id — progress for a user across sessions.

Exercise Progress (/progress)

  • POST /create — create exercise progress entry (fields in controller; supports optional detailed analysis).
  • GET /all — list all progress records.
  • GET /user/:userId — progress for a user.
  • GET /exercise/:exerciseId — progress for an exercise.

Stats (/stats)

  • GET / — aggregate counts (users, admins, exercises, sessions, etc.).
  • GET /ages — user age distribution.
  • GET /community — community engagement stats.
  • GET /exercise-time — global exercise time stats.
  • GET /user-growth — monthly user growth.

AI Notes

  • Gemini model: gemini-1.5-flash via @google/generative-ai.
  • Bot scope: fitness/nutrition; off-topic prompts return a guidance message.
  • Chat history stored per user in FitnessChat (userId, messages[{sender,text,time}]).

About

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages