konianzero / RestaurantVotingSystem

A restaurant voting system REST API using Spring Boot 2.5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restaurant Voting System

Spring Boot 2.5.

A restaurant voting system (REST API) 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.


Project uses:

Application Properties


Requirements

  • JDK 17
  • maven 3
  • Docker 20

Launch

Local

mvn spring-boot:run

In container

mvn clean package
docker build -t restaurant/voting_system .
docker run --name votingSystem -d --rm -p 8080:8080 restaurant/voting_system:latest

URL: http://localhost:8080/voting


Users

Name Email Password Roles
Mike admin@gmail.com admin Admin, User
Nick user@gmail.com userpass User

API documentation

Swagger Api Documentation

API Method Description URL User
Admin POST Create user {URL}/rest/admin/users Admin
GET Get user {URL}/rest/admin/users/{userId} Admin
GET Get user by Email {URL}/rest/admin/users/by?email={email} Admin
GET Get all user {URL}/rest/admin/users Admin
UPDATE Update user {URL}/rest/admin/users/{userId} Admin
DELETE Delete user {URL}/rest/admin/users/{userId} Admin
Profile POST Create user {URL}/rest/profile/register Not Authorized
GET Get user {URL}/rest/profile Authorized
UPDATE Update user {URL}/rest/profile Authorized
DELETE Delete user {URL}/rest/profile Authorized
Restaurant POST Create restaurant {URL}/rest/restaurants Admin
GET Get restaurant {URL}/rest/restaurants/{restaurantId} Authorized
GET Get restaurant with today's dishes {URL}/rest/restaurants/{restaurantId}/today Authorized
GET Get all restaurants {URL}/rest/restaurants/ Authorized
GET Get all restaurants with today's dishes {URL}/rest/restaurants/today Authorized
PUT Update restaurant {URL}/rest/restaurants/{restaurantId} Admin
DELETE Delete restaurant {URL}/rest/restaurants/{restaurantId} Admin
Dish POST Create dish {URL}/rest/dishes Admin
GET Get dish {URL}/rest/dishes/{dishId} Authorized
GET Get all dishes by restaurant {URL}/rest/dishes?restaurantId={restaurantId} Authorized
GET Get all dishes by restaurant and date {URL}/rest/dishes?restaurantId={restaurantId}&date={date} Authorized
PUT Update dish {URL}/rest/dishes/{dishId} Admin
DELETE Delete dish {URL}/rest/dishes/{dishId} Admin
Vote PUT Create vote {URL}/rest/votes?restaurantId={restaurantId} Authorized
GET Get vote {URL}/rest/votes/{voteId} Authorized
GET Get last vote of user {URL}/rest/votes/last Authorized
PATCH Update vote {URL}/rest/votes?restaurantId={restaurantId} Authorized

CURL commands for the restaurant voting system REST API

You can use IntelliJ IDEA HTTP client with endpoints.http.

  1. Restaurant

    Create restaurant

    curl -X POST -d '{"name":"Restaurant3","address":"ул. Зеленая, д.20"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting/rest/restaurants --user admin@gmail.com:admin

    Get restaurant

    curl -X GET http://localhost:8080/voting/rest/restaurants/100002 --user user@gmail.com:userpass

    Get restaurant with today's dishes

    curl -X GET http://localhost:8080/voting/rest/restaurants/100002/today --user user@gmail.com:userpass

    Get all restaurants

    curl -X GET http://localhost:8080/voting/rest/restaurants/ --user user@gmail.com:userpass

    Get all restaurants with today's dishes

    curl -X GET http://localhost:8080/voting/rest/restaurants/today --user user@gmail.com:userpass

    Update restaurant

    curl -X PUT -d '{"id":100002,"name":"RestOne","address":"ул. Мира, 67"}' -H 'Content-Type: application/json' http://localhost:8080/voting/rest/restaurants/100002 --user admin@gmail.com:admin

    Delete restaurant

    curl -X DELETE http://localhost:8080/voting/rest/restaurants/100002 --user admin@gmail.com:admin
  2. Dish

    Create dish

    curl -X POST -d '{"restaurantId":100002,"name":"Sandwich","price":6}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting/rest/dishes --user admin@gmail.com:admin

    Get dish

    curl -X GET http://localhost:8080/voting/rest/dishes/100016 --user user@gmail.com:userpass

    Get all dishes by restaurant

    curl -X GET http://localhost:8080/voting/rest/dishes?restaurantId=100003 --user user@gmail.com:userpass

    Get all dishes by restaurant and date

    curl -X GET "http://localhost:8080/voting/rest/dishes?restaurantId=100003&date=2021-10-31" --user user@gmail.com:userpass

    Update dish

    curl -X PUT -d '{"id":100016,"restaurantId":100003,"name":"Sandwich with tune","price":8}' -H 'Content-Type: application/json' http://localhost:8080/voting/rest/dishes/100004 --user admin@gmail.com:admin

    Delete dish

    curl -X DELETE http://localhost:8080/voting/rest/dishes/100004 --user admin@gmail.com:admin
  3. User

    3.1 Admin

    Create user

    curl -X POST -d '{"name":"New","email":"new@gmail.com","password":"password","enabled":true,"roles":["USER"]}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting/rest/admin/users --user admin@gmail.com:admin

    Get user

    curl -X GET http://localhost:8080/voting/rest/admin/users/100001 --user admin@gmail.com:admin

    Get user by Email

    curl -X GET http://localhost:8080/voting/rest/admin/users/by?email=user@gmail.com --user admin@gmail.com:admin

    Get all users

    curl -X GET http://localhost:8080/voting/rest/admin/users --user admin@gmail.com:admin

    Update user

    curl -X PUT -d '{"id":100001,"name":"NewAdmin","email":"newadmin@gmail.com","password":"password","enabled":true,"roles":["USER","ADMIN"]}' -H 'Content-Type: application/json' http://localhost:8080/voting/rest/admin/users/100001 --user admin@gmail.com:admin

    Delete user

    curl -X DELETE http://localhost:8080/voting/rest/admin/users/100001 --user admin@gmail.com:admin

    3.2 User

    Register user

    curl -X POST -d '{"name":"Other","email":"other@gmail.com","password":"password"}' -H 'Content-Type:application/json;charset=UTF-8' http://localhost:8080/voting/rest/profile/register

    Get user

    curl -X GET http://localhost:8080/voting/rest/profile --user other@gmail.com:password

    Update user

    curl -X PUT -d '{"name":"UpdatedUser","email":"updated@gmail.com","password":"passupdate"}' -H 'Content-Type: application/json' http://localhost:8080/voting/rest/profile --user user@gmail.com:userpass

    Delete user

    curl -X DELETE http://localhost:8080/voting/rest/profile --user user@gmail.com:userpass
  4. Vote

    Create vote

    curl -X POST -H 'Content-Type: application/json' http://localhost:8080/voting/rest/votes?restaurantId=100002 --user new@gmail.com:password

    Get own votes

    curl -X GET http://localhost:8080/voting/rest/votes --user new@gmail.com:password

    Get last vote of user

    curl -X GET http://localhost:8080/voting/rest/votes/last --user new@gmail.com:password

    Update vote

    curl -X PUT -H 'Content-Type: application/json' http://localhost:8080/voting/rest/votes?restaurantId=100003 --user new@gmail.com:password

About

A restaurant voting system REST API using Spring Boot 2.5


Languages

Language:Java 99.9%Language:Dockerfile 0.1%