Hexagonal Architecture with Spring Boot

This commit is contained in:
Ramón Bailén Sánchez
2022-06-20 23:57:06 +02:00
parent c48d0c8223
commit 8188ccdad0

View File

@@ -27,13 +27,7 @@ public class ProductService implements CreateProductUseCase, GetProductUseCase {
@Override @Override
public Product getProductById(Long id) { public Product getProductById(Long id) {
Optional<Product> product = productOutputPort.getProductById(id); return productOutputPort.getProductById(id).orElseThrow(() -> new ProductNotFound("Product not found with id " + id));
if(product.isEmpty()) {
throw new ProductNotFound("Product not found with id " + id);
}
return product.get();
} }
} }