This document provides instructions and usage examples for the Cloudflare Wrangler API Program.
This API allows users to submit votes for different submissions. It ensures that users and submissions exist in the database and handles vote counting.
-
Install Dependencies:
pnpm install
-
Build the Project:
pnpm run build
-
Start the Development Server:
pnpm run dev
- Endpoint:
/vote
- Method:
POST
- Description: Submits a vote for a specific submission and category.
{
"submissionId": "string",
"slackID": "string",
"hashedSlackID": "string",
"category": "string"
}
- Success:
- Status:
200 OK
- Body:
{ "success": "Vote submitted successfully" }
- Status:
- Errors:
- Status:
409 Conflict
{ "error": "User {slackID} has reached the maximum vote count of 3" }
- Status:
409 Conflict
{ "error": "User {slackID} has already voted for submission {submissionId} in category {category}" }
- Status:
500 Internal Server Error
{ "error": "Failed to submit vote" }
- Status:
Column | Type | Description |
---|---|---|
slack_id | TEXT | Unique identifier for the user |
hashed_slackid | TEXT | Hashed Slack ID |
username | TEXT | Username of the user |
vote_count | INTEGER | Number of votes cast by the user |
Column | Type | Description |
---|---|---|
submission_id | TEXT | Unique identifier for the submission |
category | TEXT | Category of the submission |
votes | INTEGER | Number of votes for the submission |
Column | Type | Description |
---|---|---|
submission_id | INTEGER | ID of the submission |
slack_id | TEXT | ID of the user |
category | TEXT | Category of the vote |
Errors are returned with appropriate HTTP status codes and a JSON body containing the error message.
{
"error": "User {slackID} has reached the maximum vote count of 3"
}
Ensure to handle errors gracefully in your client application by checking the status codes and displaying relevant messages to the user.