Giter Site home page Giter Site logo

lunch-voting's Introduction

Build Status codecov Codacy Badge

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 and README.md with API documentation and curl commands to get data for voting and vote.


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

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

Used technologies

  • Java 11
  • Maven
  • Spring Security
  • Spring 5
  • Spring Core (Beans, Context)
  • Spring Data Access (ORM, Spring Data JPA (Hibernate), Transactions)
  • DBs: H2
  • RESTful services
  • Spring Security Test / JUnit 5

Install

git clone https://github.com/a11exe/lunch-voting

Run

mvn clean package -DskipTests=true org.codehaus.cargo:cargo-maven2-plugin:1.7.5:run

Credentionals

DB connection

  • JDBC URL: jdbc:h2:file:~/voting
  • User: sa, password: zD5z6Wx

REST auth User(role, email, password)

CURL Commands

Users

Access allowed for Admin only

    curl -X GET 'http://localhost:8080/lunch-voting/rest/users' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/users/100001' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/users/find/[email protected]' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X POST 'http://localhost:8080/lunch-voting/rest/users' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu' -H 'Content-Type: application/json' -d '{"name": "new-user","email": "[email protected]","password": "newPassword"}'
    curl -X DELETE 'http://localhost:8080/lunch-voting/rest/users/100001' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X PUT 'http://localhost:8080/lunch-voting/rest/users/100002' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu' -H 'Content-Type: application/json' -d '{"id": 100002,"name": "userUpdate","email": "[email protected]","password": "password","roles": ["ROLE_USER"]}'

Restaurant

Access allowed for Admin and User

    curl -X GET 'http://localhost:8080/lunch-voting/rest/restaurants' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/restaurants/100004' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'

Access allowed for Admin only

    curl -X POST 'http://localhost:8080/lunch-voting/rest/restaurants' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu' -H 'Content-Type: application/json' -d '{"name": "New restaurant","description": "New restaurant desc"}'
    curl -X DELETE 'http://localhost:8080/lunch-voting/rest/restaurants/100004' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X PUT 'http://localhost:8080/lunch-voting/rest/restaurants/100005' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu' -H 'Content-Type: application/json' -d '{"name": "restaurant update","description": "New restaurant desc"}'

Menu

Access allowed for Admin and User

    curl -X GET 'http://localhost:8080/lunch-voting/rest/menus' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/menus/100004' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/menus/find/by-date?date=2015-05-30' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/menus/find/by-period?startDate=2015-05-30&endDate=2015-09-30' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/menus/find/by-restaurant-id?id=100005' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'

Access allowed for Admin only

    curl -X POST 'http://localhost:8080/lunch-voting/rest/menus' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu' -H 'Content-Type: application/json' -d '{"date":"2019-09-13","description":"new menu","restaurant":"http://localhost:8080/lunch-voting/rest/restaurants/100006"}'
    curl -X DELETE 'http://localhost:8080/lunch-voting/rest/menus/100004' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X PUT 'http://localhost:8080/lunch-voting/rest/menus/100005' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu' -H 'Content-Type: application/json' -d '{"date":"2019-09-13","updated description":"updated menu","restaurant":"http://localhost:8080/lunch-voting/rest/restaurants/100006"}'

Vote

Access allowed for Admin and User

id: menu id

    curl -X POST 'http://localhost:8080/lunch-voting/rest/votes' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk' -H 'Content-Type: application/json' -d '{"id":"100008"}'

voting results by restaurants

    curl -X GET 'http://localhost:8080/lunch-voting/rest/votes/results/by-date?date=2015-05-30' -H 'Authorization: Basic dXNlcl9vbmVAeWFuZGV4LnJ1OnBhc3N3b3Jk'

Access allowed for Admin only

    curl -X GET 'http://localhost:8080/lunch-voting/rest/votes' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/votes/100012' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/votes/find/by-date?date=2015-05-30' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
    curl -X GET 'http://localhost:8080/lunch-voting/rest/votes/find/by-period?startDate=2015-05-30&endDate=2015-09-30' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'        

lunch-voting's People

Contributors

a11exe avatar

Watchers

James Cloos avatar  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.