├── .gitignore
├── Dockerfile
├── Makefile
├── README.md
├── day1
└── README.md
├── day2
├── README.md
└── tests.http
├── day3
└── README.md
├── day6
└── README.md
├── docker-compose.yml
├── pom.xml
└── src
├── main
├── java
│ └── pizzalab
│ │ ├── Main.java
│ │ ├── config
│ │ └── PizzaLabConfig.java
│ │ ├── controller
│ │ ├── CustomerController.java
│ │ └── MenuController.java
│ │ ├── domain
│ │ ├── Deliverer.java
│ │ ├── Order.java
│ │ ├── PizzaType.java
│ │ └── exchange
│ │ │ ├── ExchangeApiResponse.java
│ │ │ ├── ExchangeResponse.java
│ │ │ └── Rates.java
│ │ ├── dto
│ │ └── CustomerOutputDTO.java
│ │ ├── entity
│ │ ├── Address.java
│ │ ├── Customer.java
│ │ ├── Menu.java
│ │ ├── MenuItem.java
│ │ ├── Pizza.java
│ │ ├── Product.java
│ │ └── Soda.java
│ │ ├── exception
│ │ └── CustomerNotFoundException.java
│ │ ├── repository
│ │ ├── CustomerRepository.java
│ │ └── ProductRepository.java
│ │ └── services
│ │ ├── CustomerService.java
│ │ ├── PantryService.java
│ │ └── exchange
│ │ ├── ApiExchangeService.java
│ │ ├── CachedExchangeService.java
│ │ ├── DockerExclusiveService.java
│ │ ├── ExchangeConnectorProperties.java
│ │ ├── ExchangeService.java
│ │ └── LocalExchangeService.java
└── resources
│ ├── application-docker.properties
│ ├── application-prod.properties
│ ├── application.properties
│ ├── db
│ └── migration
│ │ └── V1.0.1__Init.sql
│ └── product-data.json
└── test
└── java
└── pizzalab
├── integration
└── CustomerIT.java
└── services
├── CustomerServiceTest.java
└── exchange
└── ApiExchangeServiceTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # IntelliJ IDEA
26 | *.iml
27 | .idea
28 | target/*
29 | .DS_Store
30 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jdk-alpine
2 |
3 | ARG JAR_FILE=target/*.jar
4 | COPY ${JAR_FILE} app.jar
5 |
6 | ENTRYPOINT ["java","-jar","/app.jar"]
7 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | build:
2 | mvn clean package spring-boot:repackage
3 |
4 | image:
5 | docker build -t pizza-lab:latest .
6 |
7 | push:
8 | docker push pizza-lab:latest
9 |
10 | start:
11 | docker run -p 8080:8080 pizza-lab:latest
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # pizza-lab
2 |
3 | ## Schedule
4 | ### Day 1
5 | - Welcome + Intro
6 | - Initial Setup
7 | - Java Recap
8 |
9 | ### Day 2
10 | - Intro to Spring Boot and Web Services
11 | - Building REST APIs using Spring
12 |
13 | ### Day 3
14 | - Adding a database to the Spring Boot application
15 | - Hibernate, JPA, HQL/JPQL
16 |
17 | ### Day 4
18 | - Building the Service Layer
19 | - Design patterns
20 | - Http client
21 |
22 | ### Day 5
23 | - Testing your application
24 | - Unit tests, Mockito, integration/e2e tests
25 |
26 | ### Day 6
27 | - Deploying in containers
28 | - Docker, Logs
29 |
30 | ### Day 7
31 |
32 | - Deep dive into Web Services Suggestions
33 | - Best practices/ Spring Security
34 | - Cloud
35 |
36 | ### Day 8
37 | **DEMO DAY**
38 |
39 |
--------------------------------------------------------------------------------
/day1/README.md:
--------------------------------------------------------------------------------
1 | ## Day 1
2 | ### Initial setup
3 |
4 | - Download and install [IntelliJ IDEA](https://www.jetbrains.com/idea/download/#section=windows)
5 | - Create a new GitHub repository using the following [tutorial](https://docs.github.com/en/get-started/quickstart/create-a-repo). If you don't have a github account yet, please create one using your
6 | personal email address.
7 | - Generate a new SSH key and add it to GITHUB [tutorial](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
8 | - Configure Java 1.8 [tutorial](https://www.jetbrains.com/help/idea/sdk.html#change-module-sdk)
9 | - Create new Maven project in your repository: use https://github.com/javacamp2022/pizza-lab as reference
10 | - Add lombok plugin [tutorial](https://projectlombok.org/setup/intellij)
11 | - [shortcuts intellij](https://cheatography.com/dmop/cheat-sheets/intellij-idea/)
12 | - Short tutorial Streams (map, filter) [more...](https://www.baeldung.com/java-8-streams)
13 | - Short tutorial design pattern (Builder, Singleton)[more...](https://sourcemaking.com/design_patterns/creational_patterns)
14 |
15 | - Create at least 8 domain objects
16 | - Create a dummy repository(storage) that stores in memory a few collections of your objects. The storage should be initialized at startup.
17 | - Create at least 5 operations to retrieve and add new objects to the dummy storage
18 | - Create a main class that will call the 5 operations
19 |
20 | Sugestii proiecte:
21 |
22 | - structura unei organizații (angajați, relații ierarhice, salarii)
23 | - o agendă personală (categorii, întâlniri, sarcini)
24 | - activitatea unei companii de transport (orașe, legături, mașini, rute)
25 | - credite (client, credit, rate)
26 | - cabinet medical (pacienți, medici, rețete)
27 | - admitere (candidat, facultate, examen)
28 | - vanzare de bilete online(client, eveniment, locatie)
29 | - software casa de marcat(metoda de plata, client, produs)
30 | - rezervare loc în sala de spectacol (spectacol, loc, client)
31 |
--------------------------------------------------------------------------------
/day2/README.md:
--------------------------------------------------------------------------------
1 | ## Intro Web Services
2 | https://youtu.be/mKjvKPlb1rA
3 |
4 | ## Intro HTTP
5 | https://www.freecodecamp.org/news/http-and-everything-you-need-to-know-about-it/
6 |
7 | ## REST
8 |
9 | https://restfulapi.net/
10 |
11 | ```
12 | # REST samples
13 | GET /customers - Retrieves a list of customers
14 | GET /customers/12 - Retrieves a specific customer
15 | POST /customers - Creates a new customer
16 | PUT /customers/12 - Updates customer #12
17 | PATCH /customers/12 - Partially updates customer #12
18 | DELETE /customers/12 - Deletes customer #12
19 | ```
20 |
21 | ## Intellij Debug
22 | https://www.jetbrains.com/help/idea/debugging-your-first-java-application.html#examining-code
23 |
24 | ## Spring
25 | * [Using the "default" Package](https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.structuring-your-code)
26 |
27 | ### Spring application.properties
28 | * https://www.javatpoint.com/spring-boot-properties
29 |
30 | ### Spring Exception handling
31 | * https://reflectoring.io/spring-boot-exception-handling/
32 |
33 | * https://www.toptal.com/java/spring-boot-rest-api-error-handling
34 |
35 | ## Model Mapper
36 | https://www.baeldung.com/java-modelmapper
37 |
38 | http://modelmapper.org/getting-started/
39 |
40 | ## Swagger UI
41 | ```
42 |
43 |
44 | org.springdoc
45 | springdoc-openapi-ui
46 | 1.6.8
47 |
48 | ```
49 | ## Chrome Extensions
50 | Live Reload
51 | [LiveReload](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en)
52 |
53 | Json Formatter
54 | [Json Formatter](https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa/related?hl=en)
55 |
--------------------------------------------------------------------------------
/day2/tests.http:
--------------------------------------------------------------------------------
1 | POST http://127.0.0.1:8080/customers
2 | Content-Type: application/json
3 |
4 | {
5 | "name": "Alice",
6 | "phone": "071234567",
7 | "hashedPassword": "PRIVATE",
8 | "addresses": [
9 | {
10 | "street": "string"
11 | }
12 | ]
13 | }
14 |
15 | ### GET customers
16 | GET http://127.0.0.1:8080/customers
17 |
18 | ### GET customers by name
19 | GET http://127.0.0.1:8080/customers/John
20 |
21 | ### GET customers by not existing name
22 | GET http://127.0.0.1:8080/customers/Beta
23 |
--------------------------------------------------------------------------------
/day3/README.md:
--------------------------------------------------------------------------------
1 | ## Day 3
2 |
3 | ### Key takeaways
4 | 1. Decide on a database to use (RDBMS, NoSQL? In Memory? Cloud? etc.)
5 | 2. Decide on a testing infrastructure ([Docker](#docker)? In Memory? Locally installed)
6 | 3. Hibernate Annotations
7 | 1. Add [@Entity](https://docs.oracle.com/javaee/7/api/javax/persistence/Entity.html) annotations to the relevant domain objects.
8 | 2. Add [relationship annotations](https://www.objectdb.com/api/java/jpa/annotations/relationship)
9 | 3. Further notes below in [Hibernate section](#hibernate)
10 | 4. JPA Data
11 | 1. Create repositories for classes that will be processed https://www.baeldung.com/spring-data-repositories
12 | 2. Define any custom queries that you might need https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa
13 | 5. Once you are satisfied, add versioning via [flyway](#flyway) or liquibase
14 | 1. Decide on a solution based on:
15 | * flexibility needed (+1 for liquibase)
16 | * ease of use (+1 for flyway)
17 | * other criteria
18 | 2. Dump existing DB
19 | 3. Migrate it to one of the formats
20 | 4. Add dependencies to the project POM
21 | 5. Change ```spring.jpa.hibernate.ddl-auto=validate```
22 | 6. Further notes below in [Flyway section](#flyway)
23 |
24 | ### Docker
25 | #### Docker Installation
26 | https://docs.docker.com/desktop/windows/install/
27 | #### Docker compose tutorial
28 | https://docs.docker.com/compose/gettingstarted/
29 |
30 | To start the database from the docker file:
31 | ```docker compose down; docker compose up```
32 |
33 | ### How to choose the right database for your service?
34 | https://medium.com/wix-engineering/how-to-choose-the-right-database-for-your-service-97b1670c5632
35 |
36 | ## Hibernate
37 | ### Most important annotations
38 | https://thorben-janssen.com/key-jpa-hibernate-annotations/
39 |
40 | ### Ways of mapping inheritance
41 | The specific solution used is the one on paragraph 3, single table
42 | https://www.baeldung.com/hibernate-inheritance
43 |
44 | ### Many to Many Relationships
45 | https://www.baeldung.com/jpa-many-to-many
46 |
47 | ## Flyway
48 | ### Dumping the DB
49 | Run the following command:
50 | ```
51 | mkdir -P /path/to/project/src/resources/db/migration
52 | docker exec -i pizzalab-postgres /bin/bash -c "PGPASSWORD=example pg_dump --username user pizzalab" > /path/to/project/src/resources/db/migration/V1.0.1__Init.sql
53 | ```
54 | ### Add POM dependencies
55 | ```
56 |
57 | org.flywaydb
58 | flyway-core
59 | 8.5.10
60 |
61 | ```
62 | ### Check GIT
63 | Check commit `25fd49f22` for further info.
64 | You may use github, command line or any other GUI.
65 | #### Command line
66 | `git diff 25fd49f22~ 25fd49f22`
67 | ### Github
68 | Check it [here](https://github.com/javacamp2022/pizza-lab/commit/25fd49f22bde5eff31d8f120a6141513399ea1f7)
69 |
70 |
--------------------------------------------------------------------------------
/day6/README.md:
--------------------------------------------------------------------------------
1 | ## Day 6
2 |
3 | ### Building the code
4 | We are using Maven as our build tool. Our goal is to run the tests and other plugins whenever building the project; more than this we want the application jar that is generated to be fully executable (have included the tomcat spring-boot runnables).
5 |
6 | There are a couple of options to configure maven to build the uber-jar (shaded, fat) and include all of the dependencies.
7 | https://www.baeldung.com/deployable-fat-jar-spring-boot
8 | https://www.baeldung.com/spring-boot-run-maven-vs-executable-jar
9 |
10 | The option we chose was to add a plugin in the pom.xml that will configure a spring-boot plugin that is used via the repackage goal to generate the jar.
11 | ```xml
12 |
13 |
14 | org.springframework.boot
15 | spring-boot-maven-plugin
16 |
17 |
18 |
19 | pizzalab.Main
20 |
21 |
22 |
23 |
24 | ```
25 |
26 |
27 | ```bash
28 | $ mvn clean package spring-boot:repackage
29 | ```
30 |
31 | If we now have the database running - we can simply start the jar;
32 | ```bash
33 | $ java -jar target/pizza-lab-0.0.1-SNAPSHOT.jar
34 | ```
35 |
36 | ### Building the image
37 | Given our executable jar, we want to containerize the app and prepare a Docker Image that can be executed and have all the needed Java and OS prerequisites:
38 |
39 | The Dockerfile is build based on a openjdk-8 image; and our customization is only copying the previously build fat jar.
40 | ```dockerfile
41 | FROM openjdk:8-jdk-alpine
42 |
43 | ARG JAR_FILE=target/*.jar
44 | COPY ${JAR_FILE} app.jar
45 |
46 | ENTRYPOINT ["java","-jar","/app.jar"]
47 | ```
48 |
49 | https://spring.io/guides/gs/spring-boot-docker/
50 |
51 | ```bash
52 | $ docker build -t pizza-lab:latest .
53 | ```
54 |
55 | ### Running docker
56 | We have a few options to run the Docker Image. One is to run the image directly; but we will need to override and config the app to use an H2 database.
57 | Another option is to repurpose the docker-compose.yaml file to start the database and web service together.
58 |
59 | https://stackoverflow.com/questions/64135291/how-to-connect-java-app-in-docker-container-with-database-in-another-container
60 |
61 | ```yaml
62 | version: '3.1'
63 |
64 | services:
65 |
66 | pizzalab:
67 | image: pizza-lab:v2
68 | environment:
69 | SPRING_PROFILES_ACTIVE: docker
70 | depends_on:
71 | - db
72 | ports:
73 | - "8080:8080"
74 |
75 | db:
76 | image: postgres
77 | container_name: pizzalab-postgres
78 | restart: always
79 | ports:
80 | - "8432:5432"
81 | expose:
82 | - 5432
83 | environment:
84 | POSTGRES_USER: user
85 | POSTGRES_PASSWORD: example
86 | POSTGRES_DB: pizzalab
87 | healthcheck:
88 | test: [ "CMD-SHELL", "pg_isready -d pizzalab -U user" ]
89 | interval: 30s
90 | timeout: 30s
91 | retries: 3
92 |
93 | adminer:
94 | image: adminer
95 | restart: always
96 | ports:
97 | - 9080:8080
98 | ```
99 |
100 | Simply triggering the docker-compose commant we will startup the database, externally exposed on port 8432, along the application that will use spring-boot profile "docker".
101 | ```bash
102 | docker-compose up
103 | ```
104 |
105 | The spring-boot profile is linked with a tweaked properties file that knows to connect to the dockerized database as well;
106 | ```properties
107 | spring.datasource.url=jdbc:postgresql://db:5432/pizzalab
108 | ```
109 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | # Use postgres/example user/password credentials
2 | version: '3.1'
3 |
4 | services:
5 |
6 | pizzalab:
7 | image: pizza-lab:v2
8 | environment:
9 | SPRING_PROFILES_ACTIVE: docker
10 | depends_on:
11 | - db
12 | ports:
13 | - "8080:8080"
14 |
15 | db:
16 | image: postgres
17 | container_name: pizzalab-postgres
18 | restart: always
19 | ports:
20 | - "8432:5432"
21 | expose:
22 | - 5432
23 | environment:
24 | POSTGRES_USER: user
25 | POSTGRES_PASSWORD: example
26 | POSTGRES_DB: pizzalab
27 | healthcheck:
28 | test: [ "CMD-SHELL", "pg_isready -d pizzalab -U user" ]
29 | interval: 30s
30 | timeout: 30s
31 | retries: 3
32 |
33 | adminer:
34 | image: adminer
35 | restart: always
36 | ports:
37 | - 9080:8080
38 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | javabootcamp2022ro
6 | pizza-lab
7 | 0.0.1-SNAPSHOT
8 | pizza-lab
9 |
10 | jar
11 |
12 |
13 |
14 | 1.8
15 | 1.8
16 | 1.18.24
17 | 2.6.7
18 | 42.3.2
19 |
20 |
21 |
22 |
23 | org.projectlombok
24 | lombok
25 | ${lombok.version}
26 | provided
27 |
28 |
29 |
30 | com.github.ben-manes.caffeine
31 | caffeine
32 | 2.8.0
33 |
34 |
35 |
36 |
37 | com.konghq
38 | unirest-java
39 | 3.13.8
40 |
41 |
42 |
43 |
44 | com.github.peichhorn
45 | lombok-pg
46 | 0.11.0
47 |
48 |
49 | com.fasterxml.jackson.core
50 | jackson-databind
51 | 2.13.2
52 |
53 |
54 |
55 | org.springframework.boot
56 | spring-boot-starter-web
57 | ${spring.boot.version}
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-starter-data-jpa
62 | ${spring.boot.version}
63 |
64 |
65 | org.springframework.data
66 | spring-data-jpa
67 | 2.6.4
68 |
69 |
70 |
71 | org.flywaydb
72 | flyway-core
73 | 8.5.10
74 |
75 |
76 |
77 |
78 | org.modelmapper
79 | modelmapper
80 | 3.1.0
81 |
82 |
83 | javax.persistence
84 | javax.persistence-api
85 | 2.2
86 |
87 |
88 | org.hibernate
89 | hibernate-core
90 | 5.6.8.Final
91 |
92 |
93 | org.postgresql
94 | postgresql
95 | ${postgresql.version}
96 |
97 |
98 |
99 |
100 | junit
101 | junit
102 | 4.13.2
103 | test
104 |
105 |
106 | org.mockito
107 | mockito-core
108 | 4.5.1
109 | test
110 |
111 |
112 | com.github.tomakehurst
113 | wiremock-jre8
114 | 2.32.0
115 | test
116 |
117 |
118 | org.springframework.boot
119 | spring-boot-starter-test
120 | 2.5.12
121 | test
122 |
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-dependency-plugin
129 |
130 |
131 |
132 | copy-dependencies
133 |
134 |
135 |
136 |
137 | lombok
138 |
139 |
140 |
141 | org.springframework.boot
142 | spring-boot-maven-plugin
143 |
144 |
145 |
146 | pizzalab.Main
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/Main.java:
--------------------------------------------------------------------------------
1 | package pizzalab;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Main {
8 | public static void main(String[] args) {
9 | SpringApplication.run(Main.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/config/PizzaLabConfig.java:
--------------------------------------------------------------------------------
1 | package pizzalab.config;
2 |
3 | import com.github.benmanes.caffeine.cache.Cache;
4 | import com.github.benmanes.caffeine.cache.Caffeine;
5 | import org.modelmapper.ModelMapper;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.core.io.ClassPathResource;
9 | import org.springframework.core.io.Resource;
10 | import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFactoryBean;
11 |
12 | import java.util.concurrent.TimeUnit;
13 |
14 | @Configuration
15 | public class PizzaLabConfig {
16 |
17 | @Bean
18 | public ModelMapper modelMapper() {
19 | return new ModelMapper();
20 | }
21 |
22 | @Bean
23 | public Jackson2RepositoryPopulatorFactoryBean getRespositoryPopulator() {
24 | Jackson2RepositoryPopulatorFactoryBean factory = new Jackson2RepositoryPopulatorFactoryBean();
25 | factory.setResources(new Resource[]{new ClassPathResource("product-data.json")});
26 | return factory;
27 | }
28 |
29 | @Bean
30 | public Cache provideCache() {
31 | return Caffeine.newBuilder()
32 | .expireAfterWrite(1, TimeUnit.MINUTES)
33 | .maximumSize(100)
34 | .build();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/controller/CustomerController.java:
--------------------------------------------------------------------------------
1 | package pizzalab.controller;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 |
5 | import org.modelmapper.ModelMapper;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | import pizzalab.services.CustomerService;
10 | import pizzalab.entity.Customer;
11 | import pizzalab.dto.CustomerOutputDTO;
12 |
13 | import java.util.List;
14 | import java.util.stream.Collectors;
15 |
16 | @Slf4j
17 | @RestController
18 | public class CustomerController {
19 |
20 | private final CustomerService customerService;
21 | private final ModelMapper modelMapper;
22 |
23 | public CustomerController(CustomerService deliveryService, ModelMapper modelMapper) {
24 | this.customerService = deliveryService;
25 | this.modelMapper = modelMapper;
26 | }
27 |
28 | @GetMapping("customers")
29 | public ResponseEntity> getCustomers() {
30 | List customersWithPrivateStuff = customerService.findAll();
31 | List customersDto = customersWithPrivateStuff.stream()
32 | .map(customer -> modelMapper.map(customer, CustomerOutputDTO.class))
33 | .collect(Collectors.toList());
34 | return ResponseEntity.ok(customersDto);
35 | }
36 |
37 | @PostMapping("customers")
38 | public ResponseEntity> createCustomer(@RequestBody Customer customer) {
39 | // TODO validation
40 | Customer added = customerService.addCustomer(customer);
41 | return added != null ? ResponseEntity.ok(added) : ResponseEntity.badRequest().body("Customer already exists!");
42 | }
43 |
44 | @GetMapping("customers/{customerId}")
45 | public ResponseEntity> getCustomer(@PathVariable Long customerId) {
46 | return ResponseEntity.ok(modelMapper.map(customerService.findById(customerId), CustomerOutputDTO.class));
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/controller/MenuController.java:
--------------------------------------------------------------------------------
1 | package pizzalab.controller;
2 |
3 |
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import pizzalab.services.PantryService;
9 | import pizzalab.entity.Menu;
10 |
11 | @RestController
12 | class MenuController {
13 |
14 | @Autowired
15 | PantryService pantryService;
16 |
17 | @GetMapping("/menu")
18 | public Menu getMenu() {
19 | return pantryService.listMenu();
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/domain/Deliverer.java:
--------------------------------------------------------------------------------
1 | package pizzalab.domain;
2 |
3 | public class Deliverer {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/domain/Order.java:
--------------------------------------------------------------------------------
1 | package pizzalab.domain;
2 |
3 | import lombok.Data;
4 | import pizzalab.entity.Address;
5 | import pizzalab.entity.Customer;
6 | import pizzalab.entity.Product;
7 |
8 | import java.util.Date;
9 | import java.util.List;
10 |
11 | @Data
12 | public class Order {
13 |
14 | private Customer customer;
15 | private Address address;
16 | private Date createdAt;
17 | private Date expectedTime;
18 | private Date actualDeliveryTime;
19 |
20 | private Long total;
21 | private List items;
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/domain/PizzaType.java:
--------------------------------------------------------------------------------
1 | package pizzalab.domain;
2 |
3 | public enum PizzaType {
4 | QUATTRO_STAGIONI,
5 | CAPRICCIOSA,
6 | QUATTRO_FORMAGGI
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/domain/exchange/ExchangeApiResponse.java:
--------------------------------------------------------------------------------
1 | package pizzalab.domain.exchange;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class ExchangeApiResponse {
7 | private Rates rates;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/domain/exchange/ExchangeResponse.java:
--------------------------------------------------------------------------------
1 | package pizzalab.domain.exchange;
2 |
3 | import lombok.Data;
4 | import lombok.RequiredArgsConstructor;
5 |
6 | @Data
7 | @RequiredArgsConstructor
8 | public class ExchangeResponse {
9 | private final Double amount;
10 | private final Double curs;
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/domain/exchange/Rates.java:
--------------------------------------------------------------------------------
1 | package pizzalab.domain.exchange;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class Rates {
7 | private Double EUR;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/dto/CustomerOutputDTO.java:
--------------------------------------------------------------------------------
1 | package pizzalab.dto;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | import lombok.Data;
6 |
7 | @Data
8 | public class CustomerOutputDTO {
9 | @JsonProperty
10 | private String name;
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/entity/Address.java:
--------------------------------------------------------------------------------
1 | package pizzalab.entity;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.List;
9 |
10 | import javax.persistence.Entity;
11 | import javax.persistence.GeneratedValue;
12 | import javax.persistence.GenerationType;
13 | import javax.persistence.Id;
14 | import javax.persistence.ManyToMany;
15 | import javax.persistence.SequenceGenerator;
16 |
17 | @Data
18 | @Builder
19 | @NoArgsConstructor
20 | @AllArgsConstructor
21 | @Entity
22 | public class Address {
23 |
24 | @Id
25 | @GeneratedValue(strategy = GenerationType.AUTO, generator = "address_key_sequence_generator")
26 | @SequenceGenerator(name = "address_key_sequence_generator", sequenceName = "address_sequence", allocationSize = 1)
27 | private Long id;
28 |
29 | @ManyToMany(mappedBy = "addresses")
30 | private List customer;
31 |
32 | String street;
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/entity/Customer.java:
--------------------------------------------------------------------------------
1 | package pizzalab.entity;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.List;
9 |
10 | import javax.persistence.CascadeType;
11 | import javax.persistence.Entity;
12 | import javax.persistence.GeneratedValue;
13 | import javax.persistence.GenerationType;
14 | import javax.persistence.Id;
15 | import javax.persistence.JoinColumn;
16 | import javax.persistence.JoinTable;
17 | import javax.persistence.ManyToMany;
18 | import javax.persistence.SequenceGenerator;
19 |
20 | @Builder
21 | @Data
22 | @NoArgsConstructor
23 | @AllArgsConstructor
24 | @Entity
25 | public class Customer {
26 |
27 | @Id
28 | @GeneratedValue(strategy = GenerationType.AUTO, generator = "customer_key_sequence_generator")
29 | @SequenceGenerator(name = "customer_key_sequence_generator", sequenceName = "customer_sequence", allocationSize = 1)
30 | private Long id;
31 |
32 | private String name;
33 | private String phone;
34 | private String hashedPassword;
35 | private String creditCard;
36 |
37 | @ManyToMany(cascade = CascadeType.ALL)
38 | @JoinTable(
39 | name = "customer_to_address",
40 | joinColumns = @JoinColumn(name = "customer_id"),
41 | inverseJoinColumns = @JoinColumn(name = "address_id"))
42 | private List addresses;
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/pizzalab/entity/Menu.java:
--------------------------------------------------------------------------------
1 | package pizzalab.entity;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.Date;
9 | import java.util.List;
10 |
11 | import javax.persistence.Entity;
12 | import javax.persistence.Id;
13 | import javax.persistence.JoinColumn;
14 | import javax.persistence.JoinTable;
15 | import javax.persistence.ManyToMany;
16 |
17 | @Builder
18 | @Data
19 | @Entity
20 | @NoArgsConstructor
21 | @AllArgsConstructor
22 | public class Menu {
23 |
24 | @Id
25 | private Long id;
26 |
27 | @ManyToMany
28 | @JoinTable(
29 | name = "menu_to_menu_items",
30 | joinColumns = @JoinColumn(name = "menu_item_id"),
31 | inverseJoinColumns = @JoinColumn(name = "menu_id"))
32 | private List