##The best restaurant voting system.
Design and implement a REST API using Hibernate/Spring/SpringMVC (or Spring-Boot) without frontend.
The task is:
####Build a voting system for deciding where to have lunch.
- 2 types of users: admin and regular users
- Admin can input a restaurant and it's lunch menu of the day (2-5 items usually, just a dish name and price)
- Menu changes each day (admins do the updates)
- Users can vote on which restaurant they want to have lunch at
- Only one vote counted per user
- If user votes again the same day:
- If it is before 11:00 we asume that he changed his mind.
- If it is after 11:00 then it is too late, vote can't be changed
Each restaurant provides new menu each day.
As a result, provide a link to github repository.
It should contain the code and README.md with API documentation and curl commands to get data for voting and vote.
P.S.: Make sure everything works with latest version that is on github :)
P.P.S.: Asume that your API will be used by a frontend developer to build frontend on top of that.
SERVER_PATH for app http://localhost:8080/votingballot
##Profiles
curl -s -X POST -d '{"name":"UserName","email":"[email protected]","password":"password"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/users/register
#####Response example:
{ "id":100022,
"name":"UserName",
"email":"[email protected]",
"password":"{bcrypt}$2a$10$nPBfsT9y9S1/VkcUqfeVm.n963.SdCg7pp7FpNpI13eWCdWn2Rj0q",
"enabled":true,"registered":"2020-01-17T11:00:55.238+0000",
"roles":["ROLE_USER"]
}
curl -s http://localhost:8080/votingballot/admin/users --user [email protected]:admin
#####Response example:
[ { "id":100000,
"name":"Admin",
"email":"[email protected]",
"password":"{noop}admin",
"enabled":true,
"registered":"2020-01-16T18:01:38.738+0000",
"roles":["ROLE_ADMIN","ROLE_USER"]
},
{ "id":100001,
"name":"User",
"email":"[email protected]",
"password":"{noop}password",
"enabled":true,
"registered":"2020-01-16T18:01:38.738+0000",
"roles":["ROLE_USER"]
}
]
curl -s http://localhost:8080/votingballot/admin/users/100001 --user [email protected]:admin
#####Response example:
{ "id":100001,
"name":"User",
"email":"[email protected]",
"password":"{noop}password",
"enabled":true,"registered":"2020-01-16T18:01:38.738+0000",
"roles":["ROLE_USER"]
}
curl -s -X POST -d '{"name":"SomeUsers","email":"[email protected]","password":"somepassword","roles":["ROLE_USER"]}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/users --user [email protected]:admin
#####Response example:
{ "id":100022,
"name":"SomeUsers",
"email":"[email protected]",
"password":"{bcrypt}$2a$10$2wBBA02jxYFqM86n18AN9eH1uRd8jP8PXtT5IK2NfHNURbweFT536",
"enabled":true,
"registered":"2020-01-17T09:29:17.307+0000",
"roles":["ROLE_USER"]
}
curl -s -X PUT -d '{"id":100022, "name":"SomeUsers Update Name","email":"[email protected]","password":"newsomepassword"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/users --user [email protected]:admin
#####Response example:
{ "id":100022,
"name":"SomeUsers Update Name",
"email":"[email protected]",
"password":"{bcrypt}$2a$10$4ldMjpj80Liz/UgoyjPcfOMY4rZ3eP9dUTYdr6zvY4V9TnFqhTVwS",
"enabled":true,
"registered":"2020-01-17T11:18:36.456+0000",
"roles":["ROLE_USER"]
}
curl -s -X DELETE http://localhost:8080/votingballot/admin/users/100022 --user [email protected]:admin
curl -s http://localhost:8080/votingballot/users --user [email protected]:password
#####Response example:
{ "id":100001,
"name":"User",
"email":"[email protected]",
"password":"{noop}password"
}
curl -s -X PUT -d '{"id":100001,"name":"NewName","email":"[email protected]","password":"password"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/users --user [email protected]:password
curl -s -X DELETE http://localhost:8080/votingballot/users --user [email protected]:password
##Restaurants
curl -s http://localhost:8080/votingballot/restaurants/today --user [email protected]:password
#####Response example:
[ { "id":100002,
"name":"Шарманка",
"dishes":[ { "id":100007,
"name":"Шашлык из Каре Ягненка",
"price":450,
"date":"2020-01-17"
}
]
},
{ "id":100003,
"name":"Тарас Бульба",
"dishes":[ { "id":100011,
"name":"Вареники Староукраинские",
"price":310,
"date":"2020-01-17"
}
]
},
{ "id":100006,
"name":"Ёлки Палки",
"dishes":[ { "id":100017,
"name":"Суп из белых грибов",
"price":175,
"date":"2020-01-17"
}
]
}
]
curl -s http://localhost:8080/votingballot/admin/restaurants --user [email protected]:admin
curl -s http://localhost:8080/votingballot/restaurants/100002 --user [email protected]:password
curl -s -X POST -d '{"name":"New Restaurant"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/restaurants --user [email protected]:admin
curl -s -X PUT -d '{"name":"Update Restaurant"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/restaurants/100022 --user [email protected]:admin
curl -s -X DELETE '{"name":"Update Restaurant"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/restaurants/100022 --user [email protected]:admin
##Dishes
curl -s http://localhost:8080/votingballot/admin/restaurants/100002/dishes --user [email protected]:admin
curl -s -X POST -d '{"name":"New dish","price":199,"date":"2020-01-17"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/restaurants/100002/dishes --user [email protected]:admin
#####Response example:
{ "id":100023,
"name":"New dish",
"price":199,
"date":"2020-01-17"}
curl -s -X PUT -d '{"name":"Update dish","price":199,"date":"2020-01-17"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/admin/restaurants/100002/dishes/100023 --user [email protected]:admin
curl -s -X DELETE http://localhost:8080/votingballot/admin/restaurants/100002/dishes/100023 --user [email protected]:admin
##Votes
curl -s http://localhost:8080/votingballot/admin/votes --user [email protected]:admin
#####Response example:
[ { "id":100019,
"date":"2020-01-15",
"userId":100000,
"userName":"Admin",
"restaurantId":100002,
"restaurantName":"Шарманка"
},
{ "id":100020,
"date":"2020-01-16",
"userId":100000,
"userName":"Admin",
"restaurantId":100005,
"restaurantName":"8 SECONDS PUB"
},
{ "id":100021,
"date":"2020-01-16",
"userId":100001,
"userName":"User",
"restaurantId":100004,
"restaurantName":"Караван"
}
]
curl -s http://localhost:8080/votingballot/admin/votes/today --user [email protected]:admin
curl -s http://localhost:8080/votingballot/admin/votes/100019 --user [email protected]:admin
curl -s http://localhost:8080/votingballot/votes --user [email protected]:password
#####Response example:
{ "id":100021,
"date":"2020-01-17",
"userId":100001,
"userName":"User",
"restaurantId":100004,
"restaurantName":"Караван"
}
curl -s -X POST -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/votingballot/votes/100005 --user [email protected]:password
curl -s -X DELETE http://localhost:8080/votingballot/admin/votes/100019 --user [email protected]:admin