Code Monkey home page Code Monkey logo

restaurant-voting's Introduction

Restaurant voting REST API

TopJava #20 Graduation Project

Codacy Badge Build Status Known Vulnerabilities

Task

Link

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.

P.S.: Make sure everything works with latest version that is on github :)

P.P.S.: Assume that your API will be used by a frontend developer to build frontend on top of that.

API

Application is deployed at application context voting_system. Curl commands were tested using Git Bash

Unauthorized visitors

Register

curl -s -X POST -d '{"name":"newName","email":"[email protected]","password":"newPassword"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/profile/register

Produces: {"id":100043,"name":"newName","email":"[email protected]","enabled":true,"registered":"2020-10-26T16:54:23.802+00:00","roles":["USER"]}

Get actual list of restaurants (list consists of transfer objects and is sorted by daily rating)

curl -s 'http://localhost:8080/voting_system/restaurants'

Produces [{"id":100002,"name":"Corner Grill","rating":1},{"id":100003,"name":"Bluefin","rating":0},{"id":100005,"name":"Caesars Palace","rating":0},{"id":100004,"name":"McDonalds","rating":0}]

Authorized user

Get user profile

curl -s 'http://localhost:8080/voting_system/profile' --user [email protected]:admin

Produces {"id":100001,"name":"Admin","email":"[email protected]","enabled":true,"registered":"2020-10-26T16:35:35.037+00:00","roles":["ADMIN"],"votes":null}

Get user profile with votes

curl -s 'http://localhost:8080/voting_system/profile/with-votes' --user [email protected]:admin

Get votes

curl -s 'http://localhost:8080/voting_system/profile/votes/' --user [email protected]:admin

Produces [{"id":100012,"localDate":"2020-11-16"},{"id":100011,"localDate":"2020-08-12"},{"id":100010,"localDate":"2020-08-11"},{"id":100009,"localDate":"2020-08-10"}]

Get today's vote

curl -s 'http://localhost:8080/voting_system/profile/votes/today' --user [email protected]:admin

Produces {"id":100012,"localDate":"2020-11-16"}

Get vote by date

curl -s 'http://localhost:8080/voting_system/profile/votes/by?date=2020-08-11' --user [email protected]:admin

Produces {"id":100010,"localDate":"2020-08-11"}

Get today's vote

curl -s 'http://localhost:8080/voting_system/profile/votes' --user [email protected]:admin

Produces {"id":100001,"name":"Admin","email":"[email protected]","enabled":true,"registered":"2020-10-26T16:35:35.037+00:00","roles":["ADMIN"],"votes":[{"id":100011,"date":"2020-08-12"},{"id":100010,"date":"2020-08-11"},{"id":100009,"date":"2020-08-10"}]}

Update user (user updates himself)

curl -s -X PUT -d '{"name":"newName","email":"[email protected]","password":"newPassword"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/profile/ --user [email protected]:admin

Produces {"id":100001,"name":"newName","email":"[email protected]","enabled":true,"registered":"2020-10-26T16:58:31.488+00:00","roles":["ADMIN"],"votes":null}

Delete user (user deletes himself)

curl -s -X DELETE 'http://localhost:8080/voting_system/profile' --user [email protected]:admin

Get list of restaurants by date

curl -s 'http://localhost:8080/voting_system/restaurants/by?date=2020-08-10' --user [email protected]:admin

Produces [{"id":100003,"name":"Bluefin","rating":1},{"id":100002,"name":"Corner Grill","rating":1},{"id":100005,"name":"Caesars Palace","rating":0},{"id":100004,"name":"McDonalds","rating":0}]

Get list of dishes in restaurant by date

curl -s 'http://localhost:8080/voting_system/restaurants/100002/dishes/by?date=2020-08-10' --user [email protected]:admin

Produces [{"id":100015,"name":"New York Cheesecake","price":350,"localDate":"2020-08-10"},{"id":100013,"name":"Caprese Burger","price":500,"localDate":"2020-08-10"},{"id":100014,"name":"Borsch","price":300,"localDate":"2020-08-10"}]

Get certain dish

curl -s 'http://localhost:8080/voting_system/restaurants/100002/dishes/100015' --user [email protected]:admin

Produces {"id":100015,"name":"New York Cheesecake","price":350,"localDate":"2020-08-10"}

Vote for restaurant

curl -s -X POST http://localhost:8080/voting_system/votes?restaurantId=100002 --user [email protected]:password

Produces {"id":100043,"date":"2020-10-26"}

Admin

Get all users

curl -s 'http://localhost:8080/voting_system/admin/users' --user [email protected]:admin

Produces [{"id":100001,"name":"Admin","email":"[email protected]","enabled":true,"registered":"2020-10-26T17:00:30.303+00:00","roles":["ADMIN"],"votes":null},{"id":100000,"name":"User","email":"[email protected]","enabled":true,"registered":"2020-10-26T17:00:30.303+00:00","roles":["USER"],"votes":null}]

Get one user

curl -s 'http://localhost:8080/voting_system/admin/users/100000' --user [email protected]:admin

Produces {"id":100000,"name":"User","email":"[email protected]","enabled":true,"registered":"2020-10-26T17:00:30.303+00:00","roles":["USER"],"votes":null}

Get user by e-mail

curl -s 'http://localhost:8080/voting_system/admin/users/[email protected]' --user [email protected]:admin

Produces {"id":100000,"name":"User","email":"[email protected]","enabled":true,"registered":"2020-10-26T17:00:30.303+00:00","roles":["USER"],"votes":null}

Get user with votes

curl -s 'http://localhost:8080/voting_system/admin/users/100000/with-votes' --user [email protected]:admin

Produces {"id":100000,"name":"User","email":"[email protected]","enabled":true,"registered":"2020-10-26T17:19:10.174+00:00","roles":["USER"],"votes":[{"id":100008,"date":"2020-08-12"},{"id":100007,"date":"2020-08-11"},{"id":100006,"date":"2020-08-10"}]}

Get user votes

curl -s 'http://localhost:8080/voting_system/admin/users/100000/votes/' --user [email protected]:admin

Produces [{"id":100008,"localDate":"2020-08-12"},{"id":100007,"localDate":"2020-08-11"},{"id":100006,"localDate":"2020-08-10"}]

Get user's vote today

curl -s 'http://localhost:8080/voting_system/admin/users/100001/votes/today' --user [email protected]:admin

Produces {"id":100012,"localDate":"2020-11-16"}

Get vote by date

curl -s 'http://localhost:8080/voting_system/admin/users/100001/votes/by?date=2020-08-11' --user [email protected]:admin

Produces {"id":100010,"localDate":"2020-08-11"}

Enable/disable user

curl -s -X PATCH 'http://localhost:8080/voting_system/admin/users/100000?enabled=false' --user [email protected]:admin

Create new user

curl -s -X POST -d '{"name":"newName","email":"[email protected]","password":"newPassword"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/admin/users --user [email protected]:admin

Produces {"id":100044,"name":"newName","email":"[email protected]","enabled":true,"registered":"2020-10-26T17:14:38.220+00:00"}

Update user

curl -s -X PUT -d '{"name":"newName","email":"[email protected]","password":"newPassword"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/admin/users/100000 --user [email protected]:admin

Delete user

curl -s -X DELETE 'http://localhost:8080/voting_system/admin/users/100000' --user [email protected]:admin

Get restaurant

curl -s 'http://localhost:8080/voting_system/admin/restaurants/100002' --user [email protected]:admin

Produces {"id":100002,"name":"Corner Grill","enabled":true,"registered":"2020-10-26T17:19:10.176+00:00","dishes":null,"votes":null}

Create new restaurant

curl -s -X POST -d '{"name":"New","enabled":true,"registered":"2020-10-26T17:28:39.214+00:00"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/admin/restaurants/ --user [email protected]:admin

Produces {"id":100043,"name":"New","enabled":true,"registered":"2020-10-26T17:28:39.214+00:00"}

Update restaurant

curl -s -X PUT -d '{"id":100002,"name":"UpdatedName","enabled":true,"registered":"2020-10-26T17:30:01.415+00:00"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/admin/restaurants/100002 --user [email protected]:admin

Enable/disable restaurant

curl -s -X PATCH 'http://localhost:8080/voting_system/admin/restaurants/100002?enabled=false' --user [email protected]:admin

Delete restaurant

curl -s -X DELETE 'http://localhost:8080/voting_system/admin/restaurants/100002' --user [email protected]:admin

Get all dishes for restaurant

curl -s 'http://localhost:8080/voting_system/admin/restaurants/100002/dishes/' --user [email protected]:admin

Produces [{"id":100022,"name":"Combo box","price":999,"localDate":"2020-11-16"},{"id":100021,"name":"Belgian Waffles","price":375,"localDate":"2020-08-12"},{"id":100019,"name":"Corsican Burger","price":500,"localDate":"2020-08-12"},{"id":100020,"name":"Tom Yum","price":400,"localDate":"2020-08-12"},{"id":100016,"name":"Bolognese Pasta","price":250,"localDate":"2020-08-11"},{"id":100017,"name":"Chicken Noodles","price":150,"localDate":"2020-08-11"},{"id":100018,"name":"Chiefs special","price":500,"localDate":"2020-08-11"},{"id":100014,"name":"Borsch","price":300,"localDate":"2020-08-10"},{"id":100013,"name":"Caprese Burger","price":500,"localDate":"2020-08-10"},{"id":100015,"name":"New York Cheesecake","price":350,"localDate":"2020-08-10"}]

Get restaurant's dish

curl -s 'http://localhost:8080/voting_system/admin/restaurants/100002/dishes/100013' --user [email protected]:admin

Produces {"id":100013,"name":"Caprese Burger","price":500,"date":"2020-08-10"}

Create new dish

curl -s -X POST -d '{"name":"New","price":1000,"date":"2020-10-26"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/admin/restaurants/100002/dishes --user [email protected]:admin

Produces {"id":100044,"name":"New","price":1000,"date":"2020-10-26"}

Update dish

curl -s -X PUT -d '{"id":100013,"name":"UpdatedName","price":500,"date":"2020-08-10"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting_system/admin/restaurants/100002/dishes/100013 --user [email protected]:admin

Delete dish

curl -s -X DELETE 'http://localhost:8080/voting_system/admin/restaurants/100002/dishes/100013' --user [email protected]:admin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.