Skip to content

Java 14: Spring-Boot 2.3.3/ Spring Data JPA (Hibernate)/ H2Database/ Spring Data REST/ Spring Security/ Spring HATEOAS/ JUnit 5

Notifications You must be signed in to change notification settings

vladmeh/choose-restaurant

Repository files navigation

Codacy Badge Build Status StyleCI

Restaurant system of choice, something to eat lunch (REST only)

Implementation Stack:

  • Spring Boot 2.3.3
  • Spring Data JPA
  • Spring Data REST
  • Spring HATEOAS
  • Spring Security
  • H2 Database
  • JUnit 5
  • Lombok

Installation

$ git clone https://github.com/vladmeh/choose-restaurant.git

Introduction

Production environment

$ mvn spring-boot:run

or

$ mvn clean package
$ java -Dfile.encoding=UTF8 -jar target/choose-restaurant.jar
H2 database
  • JDBC URL: jdbc:h2:file:~/choosing
  • user name: sa
  • password: WdyHMa4G

Dev environment

$ mvn spring-boot:run -Dspring-boot.run.profiles=dev

or

$ mvn clean package
$ java -Dspring.profiles.active=dev -Dfile.encoding=UTF8 -jar target/choose-restaurant.jar
H2 database
  • console - http://localhost:8080/console
  • driver class: org.h2.Driver
  • JDBC URL: jdbc:h2:mem:choosing
  • user name: sa
  • password: no password

Authentication

  • Admin
    • login: "[email protected]"
    • Password: "admin"
    • Request Headers: "Authorization:Basic YWRtaW5AZ21haWwuY29tOmFkbWlu"
  • User
    • login: "[email protected]"
    • Password: "user"
    • Request Headers: "Authorization:Basic dXNlckB5YW5kZXgucnU6dXNlcg=="

Run

Admin

CURL Users
$ curl -si 'http://localhost:8080/api/users' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/users/0' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/users/search/[email protected]' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'

$ curl -si 'http://localhost:8080/api/users' -d '{"name":"New User","email":"[email protected]", "password":"12345", "roles" : ["ROLE_USER"]}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/users/0' -X PUT -d '{"name":"User update","email":"[email protected]", "password":"12345", "roles" : ["ROLE_USER"]}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/users/0' -X DELETE -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
CURL Restaurant
$ curl http://localhost:8080/api/restaurants -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl http://localhost:8080/api/restaurants/0 -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl http://localhost:8080/api/restaurants/search/by-name?name=McDonalds -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'

## get restaurant with lunch current date
$ curl http://localhost:8080/api/restaurants/0/lunch -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'

$ curl -si 'http://localhost:8080/api/restaurants' -d '{"name":"Mama Roma"}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/restaurants/0' -X PUT -d '{"name":"Teremok"}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/restaurants/0' -X DELETE -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
CURL Lunch
$ curl http://localhost:8080/api/lunch -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl http://localhost:8080/api/lunch/0 -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl http://localhost:8080/api/lunch/search/by-date?date=2018-05-23 -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl http://localhost:8080/api/lunch/search/by-restaurant?restaurant=http://localhost:8080/api/restaurant/0 -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl http://localhost:8080/api/lunch/search/by-restaurant-and-date?restaurant=http://localhost:8080/api/restaurant/0&date=2018-05-23 -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'

$ curl -si 'http://localhost:8080/api/lunch' -d '{"date": "2018-06-05", "restaurant":"http://localhost:8080/api/restaurant/0", "name": "New lunch", "price" : 200}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/lunch/0' -X PUT -d '{"date": "2018-06-04", "name": "Put lunch", "price" : 300}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
$ curl -si 'http://localhost:8080/api/lunch/0' -X DELETE -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'
WARNINIG! Restaurant change at lunch
$ curl -si 'http://localhost:8080/api/lunch/0' -X PATCH -d '{"restaurant": "http://localhost:8080/api/restaurant/1"}' -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization: Basic YWRtaW5AZ21haWwuY29tOmFkbWlu'

Choosing

Choice for restaurant 0:

$ curl -si 'http://localhost:8080/api/choice/0' -X POST -H 'Authorization:Basic dXNlckB5YW5kZXgucnU6dXNlcg=='

Choice for restaurant 2:

$ curl -si 'http://localhost:8080/api/choice/2' -X POST -H 'Authorization:Basic dXNlckB5YW5kZXgucnU6dXNlcg=='

Check current choice:

$ curl -si 'http://localhost:8080/api/choice' -H 'Authorization:Basic dXNlckB5YW5kZXgucnU6dXNlcg=='

Testing

  • Postman - ./choose-restaurant.postman_collection.json

About

Java 14: Spring-Boot 2.3.3/ Spring Data JPA (Hibernate)/ H2Database/ Spring Data REST/ Spring Security/ Spring HATEOAS/ JUnit 5

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published