Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ppichugin/restaurant-voting-system
Restaurant Voting System. REST API.
https://github.com/ppichugin/restaurant-voting-system
caffeine-cache h2-database hibernate-orm java lombok maven spring-boot swagger-ui
Last synced: about 2 months ago
JSON representation
Restaurant Voting System. REST API.
- Host: GitHub
- URL: https://github.com/ppichugin/restaurant-voting-system
- Owner: ppichugin
- Created: 2022-06-28T12:47:40.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-11-02T05:45:12.000Z (about 2 years ago)
- Last Synced: 2023-03-08T14:41:34.125Z (almost 2 years ago)
- Topics: caffeine-cache, h2-database, hibernate-orm, java, lombok, maven, spring-boot, swagger-ui
- Language: Java
- Homepage:
- Size: 246 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
REST API Project
==================[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f4d82a6c9735461c9486a4d76fbff683)](https://www.codacy.com/gh/ppichugin/restaurant-voting-system/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ppichugin/restaurant-voting-system&utm_campaign=Badge_Grade) [![Build Status](https://app.travis-ci.com/ppichugin/restaurant-voting-system.svg?branch=master)](https://app.travis-ci.com/ppichugin/restaurant-voting-system)
---
### Content
* [TopJava Graduation Project](#topjava-graduation-project)
* [Content](#content)
* [Restaurant Voting System](#restaurant-voting-system)
* [Technical requirement](#technical-requirement)
* [Stack](#stack)
* [Swagger UI link](#swagger-ui-link)
* [Credentials for testing purposes:](#credentials-for-testing-purposes)
* [Some testing cURLs](#some-testing-curls)
* [Admin API: Administration of restaurants](#admin-api-administration-of-restaurants)
* [Admin API: Administration of dishes](#admin-api-administration-of-dishes)
* [Admin API: Administration of users](#admin-api-administration-of-users)
* [User API: operations with restaurants](#user-api-operations-with-restaurants)
* [Profile operations](#profile-operations)
* [Voting operations](#voting-operations)---
## 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](#content)
---
### 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](#content)
---
### Swagger UI link
http://localhost:8080/swagger-ui/index.html
[ ⬆️Go Up](#content)
---
### 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](#content)
---
### Some testing cURLs
---
#### Admin API: Administration of restaurants
- Get all restaurants by Admin:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:admin http://localhost:8080/api/admin/restaurants
```- Create new restaurant by Admin:
```console
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:
```console
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:
```console
curl -X GET http://localhost:8080/api/admin/restaurants/100009 -v --user [email protected]:admin -H "accept: application/json"
```[ ⬆️Go Up](#content)
---
#### Admin API: Administration of dishes
- Get all dishes from restaurant {100005} by Admin:
```console
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:
```console
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:
```console
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:
```console
curl -X DELETE http://localhost:8080/api/admin/restaurants/100010/dishes/100033 -v --user [email protected]:admin
```[ ⬆️Go Up](#content)
---
#### Admin API: Administration of users
- Get all users by Admin:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:admin http://localhost:8080/api/admin/users
```- Get user {id=100000} by Admin:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:admin http://localhost:8080/api/admin/users/100000
```[ ⬆️Go Up](#content)
---
#### User API: operations with restaurants
- Get all restaurants with ID only:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/restaurants/
```- Get all restaurants with menu today:
```console
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:
```console
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:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/restaurants/100011/with-menu
```[ ⬆️Go Up](#content)
---
#### Profile operations
- Get profile of the logged-in user:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:admin -X GET http://localhost:8080/api/profile
```- Create new user:
```console
curl -X POST -d "{\"name\":\"newName\",\"email\":\"[email protected]\",\"password\":\"newPassword\"}" http://localhost:8080/api/profile -H "Content-Type: application/json"
```[ ⬆️Go Up](#content)
---
#### Voting operations
- Get all votes of authenticated user:
```console
curl -H "Content-Type: application/json" -v --user [email protected]:password http://localhost:8080/api/profile/votes
```- Get votes for today of authenticated user:
```console
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:
```console
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:
```console
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](#content)
---