Система выбора ресторана для обеда. Пользователям с ролью ADMIN доступно управлять ресторанами и пользователями. Пользователям с ролью USER доступно управлять своими голосами и получать информацию по результатам голосования. Голосование доступно до 11.00 по времени сервера. Пользователь может иметь обе роли.
Использованные технологии:
- Работа с БД: H2, Spring Data-JPA(Hibernate)
- Web: Spring MVC, Spring Security (basic auth), реализован REST API, JSON(Jackson)
- Разное: JAVA 8, Spring (IoC, Test, Cache(ehcache)) , Maven, JUnit, SLF4J(logback)
Интерфейс ADMIN - rest/v1/admin
Все рестораны
Получить ресторан
Создать ресторан
Обновить ресторан
Удалить ресторан
Все пользователи
Получить пользователя
Создать пользователя
Обновть пользователя
Удалить пользователя
История своих голосов
Посмотреть голос
Создать голос
Обновить голос
Удалить голос
Результаты голосования
Рестораны с меню
Лидирующий ресторан
URL: /restaurants
Method: GET
URL Params: no
Data Params: no
Success Response:
Code: 200
Content: [{"name":"testrest1"},{"name":"testrest2"},{"name":"testrest3"}]
Error Response:
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants
Notes: Рестораны содержат только название
URL: /restaurants/:name
Method: GET
URL Params: no
Data Params: no
Success Response:
Code: 200
Content: {"name":"testrest1","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]}
Error Response:
Code 404
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants/testrest1
Notes:
URL: /restaurants
Method: POST
URL Params: no
Data Params: JSON
{name : "restaurant", dishes : [{name : "dish1", price : 1000},{name : "dish2", price : 900}]}
Success Response:
Code: 201
Error Response:
400
409
Sample Call:
for windows: curl -u testuser1:testuser1 -X POST -H "Content-Type: application/json" -d "{"name":"testrest4","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]}" http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants
for linux: curl -u testuser1:testuser1 -X POST -H "Content-Type: application/json" -d '{"name":"testrest4","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]}" http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants
Notes:
URL: /restaurants/:name
Method: PUT
URL Params: no
Data Params: JSON
{name : "restaurant", dishes : [{name : "dish1", price : 1000},{name : "dish2", price : 900}]}
Success Response:
Code: 200
Error Response:
400
Sample Call:
for windows: curl -u testuser1:testuser1 -X PUT -H "Content-Type: application/json" -d "{"name":"testrest2","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]}" http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants/testrest2
for linux: curl -u testuser1:testuser1 -X PUT -H "Content-Type: application/json" -d '{"name":"testrest2","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]}" http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants/testrest2
Notes:
URL: /restaurants/:name
Method: DELETE
URL Params: no
Data Params: no
Success Response:
Code: 204
Error Response:
Sample Call: curl -u testuser1:testuser1 -X DELETE http://localhost:8080/restaurantVoting/rest/v1/admin/restaurants/testrest4
Notes:
URL: /users
Method: GET
URL Params: no
Data Params: no
Success Response:
[{"login":"testuser1","password":"testuser1","roles":["ROLE_USER","ROLE_ADMIN"]},{"login":"testuser2","password":"testuser2","roles":["ROLE_ADMIN"]},{"login":"testuser3","password":"testuser3","roles":["ROLE_USER"]}]
Code: 200
Error Response:
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/admin/users
Notes:
URL: /users/:login
Method: GET
URL Params: no
Data Params: no
Success Response:
{"login":"testuser1","password":"testuser1","roles":["ROLE_USER","ROLE_ADMIN"]}
Code: 200
Error Response:
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/admin/users/testuser1
Notes:
URL: /users
Method: POST
URL Params: no
Data Params: JSON
{login:"testuser1",password:"testuser1",roles:["ROLE_USER","ROLE_ADMIN"]}
Success Response:
Code: 201
Error Response:
409
Sample Call:
for windows: curl -u testuser1:testuser1 -X POST -H "Content-Type: application/json" -d "{"login":"testuserCreated","password":"testuser1","roles":["ROLE_USER","ROLE_ADMIN"]}" http://localhost:8080/restaurantVoting/rest/v1/admin/users
for linux: curl -u testuser1:testuser1 -X POST -H "Content-Type: application/json" -d "{"login""testuserCreated","password":"testuser1","roles":["ROLE_USER","ROLE_ADMIN"]}" http://localhost:8080/restaurantVoting/rest/v1/admin/users
Notes:
URL: /users/:login
Method: PUT
URL Params: no
Data Params: JSON
{login:"testuser1",password:"testuser1",roles:["ROLE_USER","ROLE_ADMIN"]}
Success Response:
Code: 200
Error Response:
404, 403
Sample Call:
for windows: curl -u testuser1:testuser1 -X PUT -H "Content-Type: application/json" -d "{"login":"testuser3","password":"updatedPass","roles":["ROLE_USER","ROLE_ADMIN"]}" http://localhost:8080/restaurantVoting/rest/v1/admin/users/testuser3
for linux: curl -u testuser1:testuser1 -X PUT -H "Content-Type: application/json" -d "{"login""testuser3","password":"updatedPass","roles":["ROLE_USER","ROLE_ADMIN"]}" http://localhost:8080/restaurantVoting/rest/v1/admin/users/testuser3
Notes: Можно обновить только пользователей не имеющих роли ADMIN или себя
URL: /users/:login
Method: DELETE
URL Params: no
Data Params: no
Success Response:
Code: 204
Error Response:
404, 403
Sample Call:
for windows: curl -u testuser1:testuser1 -X DELETE http://localhost:8080/restaurantVoting/rest/v1/admin/users/testuser1
for linux: curl -u testuser1:testuser1 -X DELETE http://localhost:8080/restaurantVoting/rest/v1/admin/users/testuser1
Notes: Можно удалить только пользователей не имеющих роли ADMIN или себя
URL: /votes
Method: GET
URL Params: no
Data Params: no
Success Response:
Code: 200
[{"id":3,"restaurant":"testrest2","date":"2017-09-10"},{"id":6,"restaurant":"testrest2","date":"2017-09-11"}]
Error Response:
Sample Call: curl -u testuser3:testuser3 http://localhost:8080/restaurantVoting/rest/v1/user/votes
Notes:
URL: /votes/:data
Method: GET
URL Params: no
Data Params: no
Success Response:
Code: 200
{"id":3,"restaurant":"testrest2","date":"2017-09-10"}
Error Response:
Code: 404
Sample Call: curl -u testuser3:testuser3 http://localhost:8080/restaurantVoting/rest/v1/user/votes/2017-09-10
Notes:
URL: /votes
Method: POST
URL Params: no
Data Params: JSON
{"id":"null","restaurant":"testrest2","date":"2017-09-10"}
Success Response:
Code: 201
Error Response:
Code: 403, 409
Sample Call:
for windows: curl -u testuser1:testuser1 -X POST -H "Content-Type: application/json" -d "{"id":"null","restaurant":"testrest2","date":"2017-09-25"}" http://localhost:8080/restaurantVoting/rest/v1/user/votes
for linux: curl -u testuser1:testuser1 -X POST -H "Content-Type: application/json" -d "{"id":"null","restaurant":"testrest2","date":"2017-09-25"}' http://localhost:8080/restaurantVoting/rest/v1/user/votes
Notes: Полосование доступно до 11:00 по времени сервера, до этого срока возможно свободно менять голос, после 11 голоса не принимаются. Голоса принимаются только за текущий день.
URL: /votes/:id
Method: PUT
URL Params: no
Data Params: JSON
{"id":"1","restaurant":"testrest2","date":"2017-09-10"}
Success Response:
Code: 200
Sample Call:
for windows: curl -u testuser1:testuser1 -X PUT -H "Content-Type: application/json" -d "{"id":1,"restaurant":"testrest2","date":"2017-09-25"}" http://localhost:8080/restaurantVoting/rest/v1/user/votes/1
for linux: curl -u testuser1:testuser1 -X PUT -H "Content-Type: application/json" -d "{"id":1,"restaurant":"testrest2","date":"2017-09-25"}' http://localhost:8080/restaurantVoting/rest/v1/user/votes/1
Error Response:
Code: 403, 409
Sample Call:
Notes: Голосование доступно до 11:00 по времени сервера, до этого срока возможно свободно менять голос, после 11 голоса не принимаются. Голоса принимаются только за текущий день.
URL: /votes
Method: DELETE
URL Params: no
Data Params: no
Success Response:
Code: 204
Error Response:
Code: 403
Sample Call: curl -u testuser1:testuser1 -X DELETE http://localhost:8080/restaurantVoting/rest/v1/user/votes/7
Notes: Отказаться можно только от голоса за текщую дату до 11:00 по времени сервера (Для тестирования предварительно создайте голос за сегодняшнюю дату)
URL: /restaurants/votes
Method: GET
URL Params:
optional: date=[ISO DATE]
Data Params: no
Success Response:
Code: 200
[{"name":"testrest3","votes":1}]
Error Response:
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/user/restaurants/votes?date=2017-09-11
Notes: При отсутствии даты - возвращает за сегодняшний день. Возвращаются только рестораны хотя бы с 1 голосом. Получить все имеющиеся рестораны с меню
URL: /restaurants
Method: GET
URL Params: no
Data Params: no
Success Response:
Code: 200
[{"name":"testrest2","votes":1},{"name":"testrest3","votes":2}]
[{"name":"testrest1","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]},{"name":"testrest2","dishes":[{"name":"dish1","price":1000},{"name":"dish2","price":900},{"name":"dish3","price":800}]},{"name":"testrest3","dishes":[{"name":"dish3","price":500},{"name":"dish4","price":600},{"name":"dish5","price":400}]}]
Error Response:
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/user/restaurants
Notes: Получить ресторан с наибольшим числом голосов
URL: /restaurants/top1
Method: GET
URL Params:
optional: date=[ISO DATE]
Data Params: no
Success Response:
Code: 200
{"name":"testrest3","dishes":[{"name":"dish3","price":500},{"name":"dish4","price":600},{"name":"dish5","price":400}]}
Error Response:
Sample Call: curl -u testuser1:testuser1 http://localhost:8080/restaurantVoting/rest/v1/user/restaurants/top1?date=2017-09-11
Notes:
-При отсутствии даты - используется текущая дата
-При одинаковом числе голосов возвращается первый по алфавиту
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 assume 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.