Skip to content

REST API with Hibernate/Spring/SpringMVC without frontend.

Notifications You must be signed in to change notification settings

RegisSDA/restaurantVoting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Restaurant Voting System

Описание
REST API
ТЗ

Описание

Система выбора ресторана для обеда. Пользователям с ролью 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)

REST API

Интерфейс ADMIN - rest/v1/admin

Все рестораны
Получить ресторан
Создать ресторан
Обновить ресторан
Удалить ресторан

Все пользователи
Получить пользователя
Создать пользователя
Обновть пользователя
Удалить пользователя

Интерфейс USER - rest/v1/user

История своих голосов
Посмотреть голос
Создать голос
Обновить голос
Удалить голос
Результаты голосования
Рестораны с меню
Лидирующий ресторан

Интерфейс ADMIN

Базовый URL - - 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 или себя

Интерфейс для USER

Базовый URL - rest/v1/user

История своих голосов

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.

About

REST API with Hibernate/Spring/SpringMVC without frontend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published