The base URL for all endpoints is https://election-managment-system.onrender.com.
- Endpoint:
GET /api/voters - Description: Retrieve a list of all voters.
- Request:
- No request parameters required.
- Response:
- Success Status Code:
200 OK - Success Response:
[ { "id": 1, "name": "John Doe", "email": "john@example.com", "password": "hashed_password" }, // ... other voters ] - Error Status Codes:
404 Not Found: If no voters are found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
GET /api/voters/:id - Description: Retrieve a specific voter by ID.
- Request:
- Parameters:
id(integer): The ID of the voter.
- Parameters:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "id": 1, "name": "John Doe", "email": "john@example.com", "password": "hashed_password" } - Error Status Codes:
404 Not Found: If the voter with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
POST /api/voters/signup - Description: Create a new voter account.
- Request:
- Body:
name(string): The name of the voter.email(string): The email of the voter.password(string): The password of the voter.
- Body:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Voter created successfully!", "voter": { "id": 1, "name": "John Doe", "email": "john@example.com", "password": "hashed_password" } } - Error Status Codes:
409 Conflict: If the email already exists.404 Not Found: If the voter cannot be created.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
POST /api/voters/signin - Description: Authenticate and log in a voter.
- Request:
- Body:
email(string): The email of the voter.password(string): The password of the voter.
- Body:
- Response:
- Success Status Code:
201 Created - Success Response:
{ "message": "Voter logged in successfully!", "token": "jwt_token" } - Error Status Codes:
409 Conflict: If the email does not exist.404 Not Found: If the password is incorrect.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
PUT /api/voters/:id - Description: Update a voter's information by ID.
- Request:
- Parameters:
id(integer): The ID of the voter.
- Body:
name(string): The new name of the voter.email(string): The new email of the voter.password(string): The new password of the voter.
- Parameters:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Voter updated successfully!", "voter": { "id": 1, "name": "Updated Name", "email": "updated@example.com", "password": "updated_hashed_password" } } - Error Status Codes:
404 Not Found: If the voter with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
DELETE /api/voter/:id - Description: Delete a voter by ID.
- Request:
- Parameters:
id(integer): The ID of the voter.
- Parameters:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Voter deleted successfully!", "voter": { "id": 1, "name": "Deleted Voter", "email": "deleted@example.com", "password": "deleted_hashed_password" } } - Error Status Codes:
404 Not Found: If the voter with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
##Candidate
- Endpoint:
GET /api/candidates - Description: Retrieve a list of all candidates.
- Request:
- No request parameters required.
- Response:
- Success Status Code:
200 OK - Success Response:
[ { "id": 1, "name": "John Doe", "cand_type": "president", "email": "john@example.com" }, // ... other candidates ] - Error Status Codes:
404 Not Found: If no candidates are found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
GET /api/candidates/:id - Description: Retrieve a specific candidate by ID.
- Request:
- Parameters:
id(integer): The ID of the candidate.
- Parameters:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "id": 1, "name": "John Doe", "cand_type": "president", "email": "john@example.com" } - Error Status Codes:
404 Not Found: If the candidate with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
POST /api/candidates - Description: Create a new candidate.
- Request:
- Authorization Header:
Authorization: Bearer token for admin authentication.
- Body:
name(string): The name of the candidate.cand_type(string): The type of the candidate.email(string): The email of the candidate.
- Authorization Header:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Candidate created successfully!", "candidate": { "id": 1, "name": "John Doe", "cand_type": "President", "email": "john@example.com" } } - Error Status Codes:
409 Conflict: If the candidate with the specified email already exists.404 Not Found: If the candidate cannot be created.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
PUT /api/candidates/:id - Description: Update a candidate's information by ID.
- Request:
- Authorization Header:
Authorization: Bearer token for admin authentication.
- Parameters:
id(integer): The ID of the candidate.
- Body:
name(string): The new name of the candidate.cand_type(string): The new type of the candidate.email(string): The new email of the candidate.
- Authorization Header:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Candidate updated successfully!", "candidate": { "id": 1, "name": "Updated Name", "cand_type": "Updated Type", "email": "updated@example.com" } } - Error Status Codes:
404 Not Found: If the candidate with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
DELETE /api/candidates/:id - Description: Delete a candidate by ID.
- Request:
- Authorization Header:
Authorization: Bearer token for admin authentication.
- Parameters:
id(integer): The ID of the candidate.
- Authorization Header:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Candidate deleted successfully!" } - Error Status Codes:
404 Not Found: If the candidate with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
Certainly! Below is the API documentation for the provided code:
##Votes
- Endpoint:
GET /api/votes - Description: Retrieve a list of all votes.
- Request:
- No request parameters required.
- Response:
- Success Status Code:
200 OK - Success Response:
[ { "id": 1, "voterId": 1, "candidateId": 1 }, // ... other votes ] - Error Status Codes:
404 Not Found: If no votes are found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
GET /api/votes/:id - Description: Retrieve a specific vote by ID.
- Request:
- Parameters:
id(integer): The ID of the vote.
- Parameters:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "id": 1, "voterId": 1, "candidateId": 1 } - Error Status Codes:
404 Not Found: If the vote with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
POST /api/votes - Description: Create a new vote.
- Request:
- Authorization Header:
Authorization: Bearer token for voter authentication.
- Body:
voterId(integer): The ID of the voter.candidateId(integer): The ID of the candidate.
- Authorization Header:
- Response:
- Success Status Code:
200 OK - Success Response:
Certainly! Below is the API documentation for the provided code:
{ "id": 1, "voterId": 1, "candidateId": 1 }
- Success Status Code:
- Endpoint:
PUT api/votes/:id - Description: Update a vote by ID.
- Request:
- Authorization Header:
Authorization: Bearer token for voter authentication.
- Parameters:
id(integer): The ID of the vote.
- Body:
candidateId(integer): The ID of the new candidate.
- Authorization Header:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Vote updated successfully!", "vote": { "id": 1, "voterId": 1, "candidateId": 2 } } - Error Status Codes:
404 Not Found: If the vote with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code:
- Endpoint:
DELETE api/votes/:id - Description: Delete a vote by ID.
- Request:
- Authorization Header:
Authorization: Bearer token for voter authentication.
- Parameters:
id(integer): The ID of the vote.
- Authorization Header:
- Response:
- Success Status Code:
200 OK - Success Response:
{ "message": "Vote deleted successfully!" } - Error Status Codes:
404 Not Found: If the vote with the specified ID is not found.500 Internal Server Error: If an internal server error occurs.
- Success Status Code: