The vote endpoint lets authenticated users upvote or remove their vote from a post. Each user can vote on a post at most once — submitting a second upvote on the same post returns aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pvnm4/Social-Media-Backend/llms.txt
Use this file to discover all available pages before exploring further.
409 Conflict. To undo a vote, send the same request with dir: 0. Both actions are handled by a single POST /vote/ endpoint.
Endpoint
POST /vote/ — authentication required.
How voting works
Voting is controlled by thedir field in the request body:
dir: 1— Adds your vote to the post. If you have already voted on this post, the server returns409 Conflict.dir: 0— Removes your existing vote from the post. If you have not yet voted on this post, the server returns404 Not Found.
votes table with a composite primary key of (user_id, post_id). This constraint is enforced at the database level, guaranteeing that each user can hold at most one vote per post at any given time.
Request body
The ID of the post to vote on. The post must exist — if it does not, a
404 Not Found is returned.Direction of the vote action. Use
1 to add a vote, or 0 to remove your existing vote. The maximum accepted value is 1.Response
HTTP 201 Created Returns a plain JSON message confirming the action. When voting (dir: 1):
dir: 0):
A human-readable confirmation of the action taken — either
"Successfully added vote" or "successfully deleted vote".Error responses
| Status | Condition | Detail Message |
|---|---|---|
401 Unauthorized | Missing or invalid JWT token. | (FastAPI/OAuth2 default) |
404 Not Found | The target post does not exist. | "Post with id: {post_id} doss not exist." |
404 Not Found | dir: 0 — the authenticated user has not voted on this post. | "vode does not exist" |
409 Conflict | dir: 1 — the authenticated user has already voted on this post. | "User {user_id} has already voted on the post {post_id}" |