Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/barcode8/VideoHub/llms.txt

Use this file to discover all available pages before exploring further.

Likes in VideoHub are toggle-based — calling a toggle endpoint when the authenticated user has already liked the target resource removes the like (unlike), and calling it when no like exists creates one. There is no separate “like” and “unlike” endpoint; one POST handles both transitions and returns the resulting state. All endpoints require a valid JWT in the Authorization header. Each toggle works by first searching for an existing Like document matching the resource ID and the authenticated user’s likedBy field. If a record is found it is deleted (unlike); if no record is found a new one is created (like). This findOne + delete-or-create pattern is used for all three toggle endpoints.

POST /api/v1/likes/toggle/v/:videoId

Toggles the like state of a video for the currently authenticated user. If the user has already liked the video the like record is deleted and isLiked: false is returned. If no like exists a new record is created and isLiked: true is returned.

Path parameters

videoId
string
required
The MongoDB ObjectId of the video to like or unlike. Returns 400 if missing or not a valid ObjectId.

Response

isLiked
boolean
true if the user has just liked the video; false if the like was removed.

Example

# Like (or unlike) a video
curl -X POST "https://api.videohub.com/api/v1/likes/toggle/v/64f1a2b3c4d5e6f7a8b9c0d1" \
  -H "Authorization: Bearer <your_token>"
Response — like added:
{
  "statusCode": 200,
  "data": { "isLiked": true },
  "message": "Video liked successfully"
}
Response — like removed:
{
  "statusCode": 200,
  "data": { "isLiked": false },
  "message": "Video unliked successfully"
}

POST /api/v1/likes/toggle/c/:commentId

Toggles the like state of a comment for the currently authenticated user. The behaviour is identical to video likes: one call either creates or deletes the like record and returns the current state.

Path parameters

commentId
string
required
The MongoDB ObjectId of the comment to like or unlike. Returns 400 if missing or not a valid ObjectId.

Response

isLiked
boolean
true if the user has just liked the comment; false if the like was removed.

Example

# Like (or unlike) a comment
curl -X POST "https://api.videohub.com/api/v1/likes/toggle/c/64f1a2b3c4d5e6f7a8b9c0d2" \
  -H "Authorization: Bearer <your_token>"
Response — like added:
{
  "statusCode": 200,
  "data": { "isLiked": true },
  "message": "Comment liked successfully"
}
Response — like removed:
{
  "statusCode": 200,
  "data": { "isLiked": false },
  "message": "Comment unliked successfully"
}

POST /api/v1/likes/toggle/t/:tweetId

Toggles the like state of a community post for the currently authenticated user. The URL path uses the parameter name tweetId, but internally the Like document stores the reference in the community field (not a tweet field) — the Like model uses community as the field name for all community post likes.

Path parameters

tweetId
string
required
The MongoDB ObjectId of the community post to like or unlike. Stored as the community field in the Like document. Returns 400 if missing or not a valid ObjectId.

Response

isLiked
boolean
true if the user has just liked the community post; false if the like was removed.

Example

# Like (or unlike) a community post
curl -X POST "https://api.videohub.com/api/v1/likes/toggle/t/64f1a2b3c4d5e6f7a8b9c0d3" \
  -H "Authorization: Bearer <your_token>"
Response — like added:
{
  "statusCode": 200,
  "data": { "isLiked": true },
  "message": "Tweet liked successfully"
}
Response — like removed:
{
  "statusCode": 200,
  "data": { "isLiked": false },
  "message": "Tweet unliked successfully"
}

GET /api/v1/likes/videos

Returns an array of all videos that the currently authenticated user has liked, sorted by most recently liked first. Each entry is a flattened video document that includes the video owner’s public profile. The aggregation pipeline matches Like documents where likedBy equals the current user and the video field exists and is non-null, then performs a $lookup on the videos collection with a nested $lookup on users for owner details.

Parameters

No path, query, or body parameters. The user identity is derived from the JWT.

Response

Returns an array of video objects. An empty array is returned if the user has not liked any videos.
[]._id
string
MongoDB ObjectId of the liked video.
[].title
string
Title of the video.
[].thumbnail
string
URL of the video’s thumbnail image.
[].duration
number
Duration of the video in seconds.
[].views
number
Total view count of the video.
[].ownerDetails
object
Public profile of the video’s uploader.
[].createdAt
string
ISO 8601 timestamp of when the like was created (i.e. when the user liked the video). Used for sort order.

Example

curl -X GET "https://api.videohub.com/api/v1/likes/videos" \
  -H "Authorization: Bearer <your_token>"
Response:
{
  "statusCode": 200,
  "data": [
    {
      "_id": "64f1a2b3c4d5e6f7a8b9c0d1",
      "title": "Introduction to Node.js",
      "thumbnail": "https://cdn.videohub.com/thumbnails/intro-nodejs.jpg",
      "duration": 3600,
      "views": 128450,
      "ownerDetails": {
        "fullName": "Jane Doe",
        "username": "janedoe",
        "avatar": "https://cdn.videohub.com/avatars/janedoe.jpg"
      },
      "createdAt": "2024-06-15T10:23:00.000Z"
    }
  ],
  "message": "Liked Videos fetched successfully"
}

Like object schema

The Like document stored in MongoDB is a sparse record — only the field corresponding to the liked resource type (video, comment, or community) is set; the others are left undefined. No fields carry a required constraint at the database level; all uniqueness and presence enforcement happens in the application layer.
_id
ObjectId
MongoDB-generated unique identifier for the like record.
video
ObjectId
Reference to the liked Video document. Present only for video likes.
comment
ObjectId
Reference to the liked Comment document. Present only for comment likes.
community
ObjectId
Reference to the liked Community post document. Present only for community post likes. Note: the toggle endpoint for community posts uses the URL parameter name tweetId, but this is the actual database field name.
likedBy
ObjectId
Reference to the User document who created the like.
createdAt
Date
Automatically set by Mongoose timestamps on document creation.
updatedAt
Date
Automatically updated by Mongoose timestamps on every save.

Build docs developers (and LLMs) love