Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@
</excludes>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
114 changes: 114 additions & 0 deletions pom.xml~
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>dev.example</groupId>
<artifactId>restaurantManager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>restaurantManager</name>
<description>Demo project for Spring Boot with API rest</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!--<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>-->

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.3.232</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>7</source><target>7</target></configuration></plugin>
</plugins>
</build>

</project>
13 changes: 13 additions & 0 deletions src/main/java/dev/example/restaurantManager/model/Dessert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.example.restaurantManager.model;

import jakarta.persistence.Entity;

@Entity
public class Dessert extends MenuItem {
private String dessertSpecificProperty;

public Dessert(String id, String name, String description, double price, String dessertSpecificProperty) {
super(id, name, description, price);
this.dessertSpecificProperty = dessertSpecificProperty;
}
}
20 changes: 20 additions & 0 deletions src/main/java/dev/example/restaurantManager/model/IMenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.example.restaurantManager.model;

public interface IMenuItem {

String getId();

String getName();

String getDescription();

double getPrice();

void setId(String id);

void setName(String name);

void setDescription(String description);

void setPrice(double price);
}
14 changes: 14 additions & 0 deletions src/main/java/dev/example/restaurantManager/model/MainCourse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.example.restaurantManager.model;

import jakarta.persistence.Entity;

@Entity
public class MainCourse extends MenuItem {

private String mainCourseSpecificProperty;

public MainCourse(String id, String name, String description, double price, String mainCourseSpecificProperty) {
super(id, name, description, price);
this.mainCourseSpecificProperty = mainCourseSpecificProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class MenuItem {
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class MenuItem implements IMenuItem {

@Id
private String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,40 @@ private void createTables() {

// we are going to create 25 menu items
// and save them in the H2 local database
// private void createMenuItemsOld() {
// for (int i = 0; i < 25; i++) {
// MenuItem menuItem = new MenuItem(
// UUID.randomUUID().toString(),
// faker.food().dish(),
// faker.food().ingredient() + " " + faker.food().ingredient() ,
// faker.number().randomDouble(2, 5, 30)
// );
// menuItemRepository.save(menuItem);
// }
// }

private void createMenuItems() {
for (int i = 0; i < 25; i++) {
MenuItem menuItem = new MenuItem(
UUID.randomUUID().toString(),
faker.food().dish(),
faker.food().ingredient() + " " + faker.food().ingredient() ,
faker.number().randomDouble(2, 5, 30)
);
MenuItem menuItem;
if (faker.random().nextBoolean()) {
// Create a MainCourse
menuItem = new MainCourse(
UUID.randomUUID().toString(),
faker.food().dish(),
faker.food().ingredient() + " " + faker.food().ingredient() ,
faker.number().randomDouble(2, 5, 30),
"Some main course specific property"
);
} else {
// Create a Dessert
menuItem = new Dessert(
UUID.randomUUID().toString(),
faker.food().dish(),
faker.food().ingredient() + " " + faker.food().ingredient() ,
faker.number().randomDouble(2, 5, 30),
"Some dessert specific property"
);
}
menuItemRepository.save(menuItem);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package dev.example.restaurantManager.menuItem;

import dev.example.restaurantManager.model.Dessert;
import dev.example.restaurantManager.model.IMenuItem;
import dev.example.restaurantManager.model.MainCourse;
import org.junit.jupiter.api.Test;

import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MenuItemTest {
@Test
public void testIMenuItemInterface() {
IMenuItem mainCourse = new MainCourse(
UUID.randomUUID().toString(),
"Grilled Chicken",
"Grilled chicken breast with roasted vegetables",
15.99,
"Some main course specific property"
);
IMenuItem dessert = new Dessert(
UUID.randomUUID().toString(),
"Chocolate Cake",
"Moist chocolate cake with vanilla ice cream",
6.99,
"Some dessert specific property"
);
assertEquals(mainCourse.getName(), "Grilled Chicken");
assertEquals(mainCourse.getDescription(), "Grilled chicken breast with roasted vegetables");
assertEquals(mainCourse.getPrice(), 15.99, 0.01);
assertEquals(dessert.getName(), "Chocolate Cake");
assertEquals(dessert.getDescription(), "Moist chocolate cake with vanilla ice cream");
assertEquals(dessert.getPrice(), 6.99, 0.01);
mainCourse.setName("Grilled Steak");
mainCourse.setDescription("Grilled steak with roasted potatoes");
mainCourse.setPrice(19.99);
dessert.setName("Cheesecake");
dessert.setDescription("Creamy cheesecake with strawberry sauce");
dessert.setPrice(7.99);
assertEquals(mainCourse.getName(), "Grilled Steak");
assertEquals(mainCourse.getDescription(), "Grilled steak with roasted potatoes");
assertEquals(mainCourse.getPrice(), 19.99, 0.01);
assertEquals(dessert.getName(), "Cheesecake");
assertEquals(dessert.getDescription(), "Creamy cheesecake with strawberry sauce");
assertEquals(dessert.getPrice(), 7.99, 0.01);
}
}