TopJava Graduation project - REST API
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, README.md with API documentation and couple curl commands to test it.
Used tools, libraries and frameworks: Maven, Spring MVC, Spring Security, Spring Data JPA, Spring Security Test, Hibernate ORM, Hibernate Validator, SLF4J, Json Jackson, Ehcache, HSQLDB, JUnit.
Endpoint | Base route | Consumer | Functions | Description |
---|---|---|---|---|
Dishes | /rest/admin/dishes | admin | CRUD | |
Restaurants | /rest/admin/restaurants | admin | CRUD | |
Dishes Of Day | /rest/admin/dishesofday | admin | CRUD | |
Votes | /rest/vote | user | create, delete | |
DishesofDay | /rest/dishesofday | user | get | get dishes of day |
RAD | /rest/rad | user | get | get full description of restaurants and today dishes |
Today | /rest/vote/today | user | get | get result of the today vote |
Currentuser | /rest/vote/currentuser | user | get | get vote of current user |
For windows use
Git Bash
For deployed version change "http://localhost:8080/bestlunch" to "http://bestlunch.herokuapp.com" in the curl tests
curl -s http://localhost:8080/bestlunch/rest/admin/restaurants --user [email protected]:admin
curl -s http://localhost:8080/bestlunch/rest/admin/restaurants/200001 --user [email protected]:admin
curl -s -X DELETE http://localhost:8080/bestlunch/rest/admin/restaurants/200001 --user [email protected]:admin
curl -s -X POST -d '{"title":"gell-mann'\''s restaurant","address":"Nizhny Novgorod, 13 Gagarina ave.","email":"[email protected]","site":"gell-mann.ru"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/bestlunch/rest/admin/restaurants --user [email protected]:admin
curl -s -X PUT -d '{"title":"gell","address":"Nizhny Novgorod, 13 Gagarina ave.","email":"[email protected]","site":"gell.ru"}' -H 'Content-Type: application/json' http://localhost:8080/bestlunch/rest/admin/restaurants/200003 --user [email protected]:admin
#### update Restaurant
curl -s http://localhost:8080/bestlunch/rest/admin/dishes --user [email protected]:admin
curl -s http://localhost:8080/bestlunch/rest/admin/dishes/300001 --user [email protected]:admin
curl -s -X DELETE http://localhost:8080/bestlunch/rest/admin/dishes/300001 --user [email protected]:admin
curl -s -X POST -d '{"name":"lobster2","price":12000,"restaurant_id":200001}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/bestlunch/rest/admin/dishes --user [email protected]:admin
curl -s -X PUT -d '{"id":300006,"name":"lobbbbf","price":13000,"registered":"2017-10-01T07:57:48.776+0000","restaurant_id":200001}' -H 'Content-Type: application/json' http://localhost:8080/bestlunch/rest/admin/dishes/300006 --user [email protected]:admin
#### update Dish
curl -s http://localhost:8080/bestlunch/rest/admin/dishesofday --user [email protected]:admin
curl -s http://localhost:8080/bestlunch/rest/admin/dishesofday/1 --user [email protected]:admin
curl -s -X DELETE http://localhost:8080/bestlunch/rest/admin/dishesofday/1 --user [email protected]:admin
curl -s -X POST -d '{"datelunch":"2017-10-01T06:00:00.000+0000","dish_id":300000}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/bestlunch/rest/admin/dishesofday --user [email protected]:admin
curl -s http://localhost:8080/bestlunch/rest/dishesofday --user [email protected]:password
curl -s http://localhost:8080/bestlunch/rest/rad --user [email protected]:password
curl -s http://localhost:8080/bestlunch/rest/vote/today --user [email protected]:password
curl -s http://localhost:8080/bestlunch/rest/vote/currentuser --user [email protected]:password
curl -s -X POST http://localhost:8080/bestlunch/rest/vote/200001 --user [email protected]:password
revote the Restaurant with id=200002 by [email protected]
curl -s -X POST http://localhost:8080/bestlunch/rest/vote/200002 --user [email protected]:password
curl -s -X DELETE http://localhost:8080/bestlunch/rest/vote/0 --user [email protected]:password