Skip to content

source-store/vote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codacy Badge

Topjava Graduation Project

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 a 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.

NOTE:

system for storing historical data is implemented by means of a DBMS.

Two roles are administrator (ADMIN) and user (USER).

administrator:

can create / edit users, menu items, restaurants

user:

can view / change himself profile, view menus and restaurants, perform voting (in accordance with the task), can view voting results

anonymous

registration of a new user, with USER rights POST /rest/profile/register body (json): UserTo

REST API

##for example JSON User {"name": "UserName", "email": "[email protected]", "password": "userPassword", "enabled": "true", "roles": ["USER", "ADMIN"]}
UserTo { "name": "UserName", "email": "[email protected]", "password": "userPassword"}
Restaurant { "name": "nameRestaurant", "address": "addressRestaurant"}
Menu { "restaurant": {"id": intId},"date": [YYYY, M, D],"description": "menuDescription", "price": intPrice }
VoteTo {"id":intId,"date":"YYYY-MM-DD","userId":intId,"restaurantId":intId}

AdminVoteRestController (Role ADMIN)

Method URL Body(JSON) Code response Body(JSON) Access
all user profiles GET /rest/admin/profiles 200 List(User) ADMIN
user profile by id GET /rest/admin/profiles/{userId} 200 User ADMIN
profile by email GET /rest/profiles/in?email={email} 200 User ADMIN
create new user POST /rest/admin/profiles User 201 User ADMIN
delete user DELETE /rest/admin/profiles/{userId} 204 ADMIN
update user PUT /rest/admin/profiles/{userId} 204 ADMIN

ProfileVoteRestController (Role USER)

Method URL Body(JSON) Code response Body(JSON) Access
current user profile GET /rest/profile 200 User USER
current user vote GET /rest/profile/vote 200 VoteTo USER
user vote by date (period) GET /rest/profile/votes/in?beginDate={beginDate}&endDate={endDate} 200 List(VoteTo) USER
update current user PUT /rest/profile UserTo 204 USER
vote POST /rest/profile/vote?id={restaurantId} 201 VoteTo USER
update current vote PUT /rest/profile/vote?id={restaurantId} 201 VoteTo USER
register new user POST /rest/profile/register UserTo 200 User

AdminRestaurantRestController (Role ADMIN)

Method URL Body(JSON) Code response Body(JSON) Access
all restaurants GET /rest/admin/restaurants 200 List(Restaurants) ADMIN
restaurant GET /rest/admin/restaurants/{id} 200 Restaurants ADMIN
create restaurant POST /rest/admin/restaurants Restaurants 201 Restaurants ADMIN
delete restaurant DELETE /rest/admin/restaurants/{id} 204 ADMIN
update restaurant PUT /rest/admin/restaurants Restaurants 204 ADMIN

RestaurantRestController (Role USER)

Method URL Body(JSON) Code response Body(JSON) Access
all restaurants GET /rest/restaurants 200 List(Restaurants) USER
restaurant GET /rest/restaurants/{id} 200 Restaurants USER

AdminMenuRestController (Role ADMIN)

Method URL Body(JSON) Code response Body(JSON) Access
get menu for all restaurants for the period GET /rest/admin/menus/in?beginDate={beginDate}&endDate={endDate} 200 List(Menu) ADMIN
get all menu items of restaurant from date GET /rest/admin/menus?{id}&beginDate={beginDate}&endDate={endDate} 200 List(Menu) ADMIN
menu item GET /rest/admin/menus/{id} 200 Menu ADMIN
create menu item POST /rest/admin/menus/ Menu 201 Menu ADMIN
delete menu item DELETE /rest/admin/menus/{id} 204 ADMIN
update menu item PUT /rest/admin/menus/{id} Menu 204 ADMIN

MenuRestController (Role USER)

Method URL Body(JSON) Code response Body(JSON) Access
menu for today GET /rest/menus/today 200 List USER
menu item GET /rest/menus/{id} 200 Menu USER
menu for all restaurants for the period GET /rest/menus/in?beginDate={beginDate}&endDate={endDate} 200 List USER
all menu items of restaurant from date GET /rest/menus?{id}&beginDate={beginDate}&endDate={endDate} 200 List USER

VoteRestController (Role USER)

Method URL Body(JSON) Code response Body(JSON) Access
result vote current date GET /rest/votes 200 List USER
result vote by period GET /rest/votes/in?beginDate=YYYY-MM-DD&endDate=YYYY-MM-DD 200 List USER
vote POST /rest/votes?id={restaurantId} 200 VoteTo USER
vote update PUT /rest/votes?id={restaurantId} 200 VoteTo USER

curl samples

AdminVoteRestController samples

get all users
curl -u [email protected]:password2 http://localhost:8080/vote/rest/admin/profiles

get user (user id = 50003)
curl -u [email protected]:password2 http://localhost:8080/vote/rest/admin/profiles/50003

get profile by email (email=[email protected])
curl -u [email protected]:password2 "http://localhost:8080/vote/rest/admin/profiles/[email protected]"

create new user from User
curl -s -X POST -d "{ \"name\": \"Us4er22\", \"email\": \"[email protected]\", \"password\": \"password\", \"enabled\": \"true\", \"roles\": [\"USER\", \"ADMIN\"]}" -H "Content-Type:application/json" "http://localhost:8080/vote/rest/admin/profiles" --user [email protected]:password2

delete user (user id = 50003)
curl -X DELETE http://localhost:8080/vote/rest/admin/profiles/50003 -u [email protected]:password2

update user (user id = 50003)
curl -X PUT -d "{ \"name\": \"User22\", \"email\": \"[email protected]\", \"password\": \"password\", \"enabled\": \"true\", \"roles\": [\"USER\", \"ADMIN\"]}" -H "Content-Type:application/json" http://localhost:8080/vote/rest/admin/profiles/50002 -u [email protected]:password2

ProfileVoteRestController samples

get current user profile
curl -u [email protected]:password4 http://localhost:8080/vote/rest/profile

get current user vote
curl -u [email protected]:password4 http://localhost:8080/vote/rest/profile/vote

get user vote by date (period)
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/profile/votes/in?beginDate=2021-03-08&endDate=2021-03-10"

update current user
curl -X PUT -d "{ \"name\": \"User22\", \"email\": \"[email protected]\", \"password\": \"password4\"}" -H "Content-Type:application/json" http://localhost:8080/vote/rest/profile -u [email protected]:password4

register new user
curl -X POST -d "{ \"name\": \"User22\", \"email\": \"[email protected]\", \"password\": \"password4\"}" -H "Content-Type:application/json" "http://localhost:8080/vote/rest/profile/register"

AdminRestaurantRestController samples

get all restaurants
curl -u [email protected]:password2 http://localhost:8080/vote/rest/admin/restaurants

get restaurant
curl -u [email protected]:password2 http://localhost:8080/vote/rest/admin/restaurants/50006

create restaurant
curl -s -X POST -d "{ \"name\": \"NAME test\", \"address\": \"ADDRESS test\"}" -H "Content-Type:application/json" "http://localhost:8080/vote/rest/admin/restaurants" --user [email protected]:password2

delete restaurant
curl -s -X DELETE "http://localhost:8080/vote/rest/admin/restaurants/100000" --user [email protected]:password2

update restaurant
curl -s -X PUT -d "{ \"name\": \"NAME test\", \"address\": \"ADDRESS222 test\"}" -H "Content-Type:application/json" "http://localhost:8080/vote/rest/admin/restaurants/50006" --user [email protected]:password2

RestaurantRestController samples

get all restaurants
curl -u [email protected]:password4 http://localhost:8080/vote/rest/restaurants

get restaurant
curl -u [email protected]:password4 http://localhost:8080/vote/rest/restaurants/50007

AdminMenuRestController samples

get menu for all restaurants for the period
curl -u [email protected]:password2 "http://localhost:8080/vote/rest/admin/menus/in?beginDate=2021-03-08&endDate=2021-03-10"

get all menu items of restaurant from date
curl -u [email protected]:password2 "http://localhost:8080/vote/rest/admin/menus?id=50006&beginDate=2021-03-08&endDate=2021-03-10"

get menu item
curl -u [email protected]:password2 "http://localhost:8080/vote/rest/admin/menus/50012"

create menu item
curl -s -X POST -d "{ \"restaurant\": {\"id\": 50005},\"date\": [2021, 3, 18],\"description\": \"m446re7u11\", \"price\": 5000 }" -H "Content-Type:application/json" "http://localhost:8080/vote/rest/admin/menus/" --user [email protected]:password2

delete menu item
curl -s -X DELETE "http://localhost:8080/vote/rest/admin/menus/50012" --user [email protected]:password2

update menu item
curl -s -X PUT -d "{ \"restaurant\": {\"id\": 50005},\"date\": [2021, 3, 18],\"description\": \"m4re7u11\", \"price\": 5000 }" -H "Content-Type:application/json" "http://localhost:8080/vote/rest/admin/menus/50011" --user [email protected]:password2

MenuRestController samples

get menu for today
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/menus/today"

get menu item
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/menus/50014"

get menu for all restaurants for the period
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/menus/in?beginDate=2021-03-08&endDate=2021-03-10"

get menu for all restaurants for the period
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/menus?id=50006&beginDate=2021-03-08&endDate=2021-03-10"

VoteRestController samples

get result vote current date
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/votes"

get result vote by period
curl -u [email protected]:password4 "http://localhost:8080/vote/rest/votes/in?beginDate=2021-03-08&endDate=2021-03-10"

create vote
curl -X POST -u [email protected]:password4 "http://localhost:8080/vote/rest/votes?restaurantid=50007"

update current vote
curl -X PUT -u [email protected]:password4 "http://localhost:8080/vote/rest/votes?restaurantid=50007"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages