Giter VIP home page Giter VIP logo

restaurant-voting-system's Introduction

REST API Project

Codacy Badge Build Status


Content


Restaurant Voting System

The voting system for deciding where to have lunch.


Technical requirement

Design and implement a REST API using Hibernate/Spring/SpringMVC (Spring-Boot preferred!) 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.

⬆️Go Up


Stack

Technology Version
Spring Framework v.5.3.21
Spring Boot v.2.6.9
Java JDK 17.0.3
Database H2 v2.1.214
Lombok v.1.18.24
Cache Caffeine Cache
REST Open API v.3 / SwaggerUI

⬆️Go Up


Swagger UI link

http://localhost:8080/swagger-ui/index.html

⬆️Go Up


Credentials for testing purposes:

Login Password
User1: [email protected] password
Admin: [email protected] admin
User2: [email protected] password
User3: [email protected] password
User4: [email protected] password

⬆️Go Up


Some testing cURLs


Admin API: Administration of restaurants

  • Get all restaurants by Admin:
curl -H "Content-Type: application/json" -v --user [email protected]:admin http://localhost:8080/api/admin/restaurants
  • Create new restaurant by Admin:
curl -H "Content-Type: application/json" -X POST http://localhost:8080/api/admin/restaurants -v --user [email protected]:admin -d "{\"name\": \"New restaurant1\"}"
  • Update existing restaurant by Admin:
curl -H "Content-Type: application/json" -X PUT http://localhost:8080/api/admin/restaurants/100009 -v --user [email protected]:admin -d "{\"name\": \"Updated Roof to Heaven\"}"
  • Get existing restaurant by Admin:
curl -X GET http://localhost:8080/api/admin/restaurants/100009 -v --user [email protected]:admin -H "accept: application/json"

⬆️Go Up


Admin API: Administration of dishes

  • Get all dishes from restaurant {100005} by Admin:
curl -X GET http://localhost:8080/api/admin/restaurants/100010/dishes -v --user [email protected]:admin -H "accept: application/json"
  • Create new dish for restaurant {100005} by Admin:
curl -X POST http://localhost:8080/api/admin/restaurants/100010/dishes -H "accept: application/json" -H "Content-Type: application/json" -d "{\"name\": \"Coffee Pastry\",\"price\": 12}" -v --user [email protected]:admin
  • Update dish {100038} for restaurant {100005} by Admin:
curl -X PUT http://localhost:8080/api/admin/restaurants/100010/dishes/100038 -H "accept: application/json" -H "Content-Type: application/json" -d "{\"name\": \"Waffles with cream\",\"price\": 200}" -v --user [email protected]:admin
  • Delete dish {100033} for restaurant {100005} by Admin:
curl -X DELETE http://localhost:8080/api/admin/restaurants/100010/dishes/100033 -v --user [email protected]:admin

⬆️Go Up


Admin API: Administration of users

  • Get all users by Admin:
curl -H "Content-Type: application/json" -v --user [email protected]:admin http://localhost:8080/api/admin/users
  • Get user {id=100000} by Admin:
curl -H "Content-Type: application/json" -v --user [email protected]:admin http://localhost:8080/api/admin/users/100000

⬆️Go Up


User API: operations with restaurants

  • Get all restaurants with ID only:
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/restaurants/
  • Get all restaurants with menu today:
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/restaurants/with-menu
  • Get restaurant {id=100005} with menu today:
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/restaurants/100005/with-menu
  • Get restaurant {id=100011} without menu for today:
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/restaurants/100011/with-menu

⬆️Go Up


Profile operations

  • Get profile of the logged-in user:
curl -H "Content-Type: application/json" -v --user [email protected]:admin -X GET http://localhost:8080/api/profile
  • Create new user:
curl -X POST -d "{\"name\":\"newName\",\"email\":\"[email protected]\",\"password\":\"newPassword\"}" http://localhost:8080/api/profile -H "Content-Type: application/json"

⬆️Go Up


Voting operations

  • Get all votes of authenticated user:
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/profile/votes
  • Get votes for today of authenticated user:
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/profile/votes/by-date

'/by-date' without provided parameter will filter votes for today by default

  • Get votes for yesterday of authenticated user:
curl -H "Content-Type: application/json" -v --user [email protected]:password "http://localhost:8080/api/profile/votes/by-date?date=2022-08-03"

change parameter 'date=' to the yesterday value while testing

  • Make new vote for restaurant {100006} by user who didn't vote today:
curl -X POST -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/profile/votes?restaurantId=100006

'[email protected]' didn't vote for restaurant {100006} by today yet

⬆️Go Up


restaurant-voting-system's People

Contributors

ppichugin avatar

Watchers

 avatar

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.