1. About
2. Architecture
2.1 Ports
2.2 Database Schema
2.3 Endpoints
2.3.1 Health Check
2.3.2 Vote on Poll
2.3.3 Remove Vote from Poll
2.3.4 Get Vote Count
The Vote Service is responsible for handling user votes.
-
The user votes on a specific answer option in the poll via the browser.
-
The browser sends a request to the Vote Service API.
-
The Vote Service handles that request by interacting with the Poll Service and the database to record and retrieve vote data.
-
Service port: 8084
-
Database port: 5434
votes Table:**
CREATE TABLE votes
(
vote_id UUID PRIMARY KEY,
user_id UUID NOT NULL,
voting_item_id INT NOT NULL,
vote_datetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);BASE URL: /api/vote
For each endpoint, use the base URL along with the URL extension if provided.
-
Method: POST
-
Endpoint:
/health -
Description: Standard service health check.
Response:
-
Status Code: 200
-
Response body:
{
"status" : "running"
}-
Method: POST
-
Description: Creates a vote in the Vote Service's database.
-
Request body:
{
"userId": "user-id", // UUID
"votingItemId": "voting-item-id" // int
}Response:
-
Status Code: 201
-
Response body:
{
"voteId": "vote-id", // UUID
"userId": "user-id", // UUID
"votingItemId": "voting-item-id", // int
"voteDateTime": "vote-date-time" // LocalDateTime
}A call to this endpoint also triggers a PUT request from the Vote Service to the Poll Service (/api/poll/vote).
Request body:
{
"votingItemId": "voting-item-id", // int
"action": "add"
}Poll Service Response:
-
Status Code: 200
-
Response body:
{
"votingItemDescription": "voting-item-description", // String
"voteCount": vote-count // int
}-
Method: DELETE
-
Description: Deletes a vote from the Vote Service's database.
-
Request body:
{
"userId": "user-id", // UUID
"votingItemId": "voting-item-id" // int
}Response:
-
Status Code: 200
-
Response body:
{
"voteId": "vote-id", // UUID
"userId": "user-id", // UUID
"votingItemId": "voting-item-id", // int
"voteDateTime": "vote-date-time" // LocalDateTime
}A call to this endpoint also triggers a PUT request from the Vote Service to the Poll Service (/api/poll/vote).
Request body:
{
"votingItemId": "voting-item-id", // int
"action": "remove" // String
}Poll Service Response:
-
Status Code: 200
-
Response body:
{
"votingItemDescription": "voting-item-description", // String
"voteCount": vote-count // int
}-
Method: POST
-
Endpoint:
/count -
Description: Returns the number of votes for each specified voting item ID. The request body should include a list of voting item IDs, and the response will provide the vote count for each item in a key-value format.Request body:
{
"votingItemIds": [1, 2, 3] // Array of voting item IDs (int)
}Response:
-
Status Code: 200
-
Response body:
{
"voteCounts": {
"1": 10, // Voting item ID and its vote count
"2": 5,
"3": 8
}
}Note: The voteCounts field is an object where each key is a voting item ID (as an integer) and the value is the corresponding vote count.