Delete hexagonal directory

This commit is contained in:
JoannaaKL 2021-09-02 15:57:03 +02:00 committed by GitHub
parent a84a483214
commit 5afba3476d
13 changed files with 0 additions and 272 deletions

View File

@ -1,70 +0,0 @@
<?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>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</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>
</plugins>
</build>
</project>

View File

@ -1,12 +0,0 @@
package com.baeldung.hexagonal;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -1,10 +0,0 @@
package com.baeldung.hexagonal.adapter.in;
import lombok.Data;
@Data
class ItemTransportObject {
private String name;
private Integer quantity;
private String category;
}

View File

@ -1,24 +0,0 @@
package com.baeldung.hexagonal.adapter.in;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baeldung.hexagonal.domain.ShoppingCartService;
@RestController
@RequestMapping("/shopping-cart")
public class ShoppingCartController {
@Autowired
ShoppingCartService shoppingCartService;
@GetMapping
public Float getTotalCartValue() {
return shoppingCartService.getTotalCartValue();
}
@PostMapping()
public void addItem(@RequestBody ItemTransportObject item) {
shoppingCartService.addItem(item.getName(), item.getQuantity());
}
}

View File

@ -1,26 +0,0 @@
package com.baeldung.hexagonal.adapter.out;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import com.baeldung.hexagonal.domain.CartItem;
import lombok.Data;
@Entity
@Data
public class Product {
@Id
public final Integer id;
@Column
public final String name;
@Column
public final Float price;
public CartItem toItem() {
return new CartItem(name, price);
}
}

View File

@ -1,12 +0,0 @@
package com.baeldung.hexagonal.adapter.out;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.baeldung.hexagonal.domain.ports.ProductRepository;
@Repository
public interface ProductCrudRepository extends CrudRepository<Product, Integer>, ProductRepository {
Product findByName(String name);
}

View File

@ -1,13 +0,0 @@
package com.baeldung.hexagonal.domain;
import lombok.Data;
import lombok.NonNull;
@Data
public class CartItem {
@NonNull
private final String name;
private final Float price;
}

View File

@ -1,25 +0,0 @@
package com.baeldung.hexagonal.domain;
import java.util.Map;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
class ShoppingCart {
private final Map<CartItem, Integer> itemToQuantity;
Float getTotalCartValue() {
return itemToQuantity.entrySet()
.stream()
.map(item -> item.getKey()
.getPrice() * item.getValue())
.reduce(0f, Float::sum);
}
void addItem(CartItem cartItem, Integer quantity) {
if (quantity < 0)
throw new IllegalArgumentException("Quantity should not be negative.");
itemToQuantity.put(cartItem, itemToQuantity.getOrDefault(cartItem, 0) + quantity);
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.hexagonal.domain;
public interface ShoppingCartService {
Float getTotalCartValue();
void addItem(String name, Integer quantity);
}

View File

@ -1,31 +0,0 @@
package com.baeldung.hexagonal.domain;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baeldung.hexagonal.adapter.out.Product;
import com.baeldung.hexagonal.domain.ports.ProductRepository;
@Service
public class SimpleShoppingCartService implements ShoppingCartService {
private final ShoppingCart shoppingCart;
@Autowired
ProductRepository productRepository;
public SimpleShoppingCartService() {
this.shoppingCart = new ShoppingCart(new HashMap<>());
}
public Float getTotalCartValue() {
return shoppingCart.getTotalCartValue();
}
public void addItem(String name, Integer quantity) {
Product product = productRepository.findByName(name);
shoppingCart.addItem(product.toItem(), quantity);
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.hexagonal.domain.ports;
import com.baeldung.hexagonal.adapter.out.Product;
public interface ProductRepository {
Product findByName(String name);
}

View File

@ -1,5 +0,0 @@
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

View File

@ -1,28 +0,0 @@
package com.baeldung.hexagonal.domain;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
class ShoppingCartTest {
@Test
void givenNonemptyShoppingCart_whenGetTotalCartValueCalled_thenShouldCalculateCorrectly() {
// given
Map<CartItem, Integer> items = new HashMap<>();
items.put(new CartItem("Cheese", 1.5f), 2);
items.put(new CartItem("Lemon", 2f), 5);
ShoppingCart cart = new ShoppingCart(items);
// when
Float totalCartValue = cart.getTotalCartValue();
// then
assertEquals(totalCartValue, 13f, 0);
}
}