by Alminas Plunge
Design and implement a simplified President Election application back-end
- The code must be written in Java language.
- You may use any frameworks you need, but try to add as little dependencies as
- There are no specific requirements for data storage. You can keep data in memory. Be prepared to discuss alternatives.
- All interaction with an application must be implemented via REST endpoints.
- REST API Requests/Responses have to be simple and easy to read/understand.
- Be mindful about naming and comments. Your code must be readable and clean.
- Your final delivery must be a Maven project.
I used spring boot framework to power API. It is easy to use and reasonable fast: https://spring.io/projects/spring-boot
- Create data models of Candidate, Voter and Vote;
- Implement java entities for Candidate, Voter and Vote data models;
- Implement repositories for a java entities;
- Implement service Candidate and Vote services;
- Implement Region, Candidates and votes data transfer objects;
- Implement Elections controller;
/api/elections/
Definition
GET /candidates
Response
200 OK
on success
[
{
"fullName": "Uzumaki Naruto",
"number": 1,
"agenda": "An “ultra-millionaire tax” on people worth more than 50 million and a major overhaul of housing policies."
},
{
"fullName": "Uchiha Itachi",
"number": 2,
"agenda": "Spend 1.7 trillion to set the Konoha on track to eliminate net greenhouse gas emissions by 2050."
}
]
Definition
POST /votes
Arguments
"candidateNumber":integer
a candidate's number on the list of the voted candidate"voterSsn":integer
a voter's social security number
Response
201 Created
on success
If a vote has already been cast by the voter, then error message will be returned.
401 Unauthorised
on trying to vote again
{
"errorMessage": "A vote has already been cast by the voter 122211"
}
404 Not Found
if the candidate does not exist
{
"errorMessage": "Candidate does not exist 122"
}
404 Not Found
if the voter is not registered
{
"errorMessage": "Voter does not exist 234234"
}
Definition
GET /votes
Response
200 OK
on success
[
{
"candidate": {
"fullName": "Uzumaki Naruto",
"number": 1,
"agenda": "An “ultra-millionaire tax” on people worth more than 50 million and a major overhaul of housing policies."
},
"numberOfVotes": 3
},
{
"candidate": {
"fullName": "Uchiha Itachi",
"number": 2,
"agenda": "Spend 1.7 trillion to set the Konoha on track to eliminate net greenhouse gas emissions by 2050."
},
"numberOfVotes": 0
}
]
Definition
GET /regions
Response
200 OK
on success
[
{
"region": "Mid-Atlantic",
"votes": [
{
"candidate": {
"fullName": "Shikadai Nara",
"number": 6,
"agenda": "Sand will be free!"
},
"numberOfVotes": 1
}
]
},
{
"region": "New England",
"votes": [
{
"candidate": {
"fullName": "Uzumaki Naruto",
"number": 1,
"agenda": "An “ultra-millionaire tax” on people worth more than 50 million and a major overhaul of housing policies."
},
"numberOfVotes": 1
}
]
}
]
Definition
GET /winner
Response
200 OK
on success when candidates been voted for by more than 50%
[
{
"fullName": "Uzumaki Naruto",
"number": 1,
"agenda": "An “ultra-millionaire tax” on people worth more than 50 million and a major overhaul of housing policies."
}
]
200 OK
on success when there is no one winner candidate
[
{
"fullName": "Uzumaki Naruto",
"number": 1,
"agenda": "An “ultra-millionaire tax” on people worth more than 50 million and a major overhaul of housing policies."
},
{
"fullName": "Uchiha Itachi",
"number": 2,
"agenda": "Spend 1.7 trillion to set the Konoha on track to eliminate net greenhouse gas emissions by 2050."
}
]
404 Not Found
when there are more than two candidates with the same votes
{
"errorMessage": "To many participants (3) have the same amount of votes. No clear winner."
}