Skip to main content

Overview

The Product module provides application-level use cases for querying and retrieving product information from the e-commerce catalog. These use cases implement the business logic for product operations.
REST Controller Not Implemented: The product use cases are implemented but not yet exposed through REST endpoints. To use these features, you’ll need to create a ProductoRestController in the infrastructure layer.

Available Use Cases

ConsultarProductoDetalladoUC

Retrieves detailed information for a specific product by its name. Location: src/main/java/com/example/demo/producto/application/usecases/ConsultarProductoDetalladoUC.java Method Signature:
ConsultarProductoDetalladoUC.java
@Service
public class ConsultarProductoDetalladoUC {
    private final ProductoRepository productoRepository;
    
    public ConsultarProductoDetalladoUC(ProductoRepository productoRepository) {
        this.productoRepository = productoRepository;
    }
    
    public ProductoPOJO execute(String nombre) {
        return productoRepository.getProductByNombre(nombre);
    }
}
Parameters:
  • nombre (String): The exact name of the product to retrieve. Product names are case-sensitive.
Returns:
  • ProductoPOJO object with product details (id, nombre, precio)
Example Usage:
@Autowired
private ConsultarProductoDetalladoUC consultarProductoDetalladoUC;

public void getProduct() {
    ProductoPOJO producto = consultarProductoDetalladoUC.execute("Laptop Dell XPS 15");
    System.out.println("Product ID: " + producto.getId());
    System.out.println("Name: " + producto.getNombre());
    System.out.println("Price: " + producto.getPrecio().getValue());
}

RecuperarTodosLosProductosUC

Retrieves the complete list of all products in the catalog. Location: src/main/java/com/example/demo/producto/application/usecases/RecuperarTodosLosProductosUC.java Method Signature:
RecuperarTodosLosProductosUC.java
@Service
public class RecuperarTodosLosProductosUC {
    private final ProductoRepository productoRepository;
    
    public RecuperarTodosLosProductosUC(ProductoRepository productoRepository) {
        this.productoRepository = productoRepository;
    }
    
    public List<ProductoPOJO> execute() {
        return productoRepository.findAll();
    }
}
Parameters: None Returns:
  • List<ProductoPOJO> containing all products in the catalog
Example Usage:
@Autowired
private RecuperarTodosLosProductosUC recuperarTodosLosProductosUC;

public void getAllProducts() {
    List<ProductoPOJO> productos = recuperarTodosLosProductosUC.execute();
    for (ProductoPOJO producto : productos) {
        System.out.println(producto.getNombre() + ": $" + producto.getPrecio().getValue());
    }
}

Repository Interface

The use cases depend on the ProductoRepository interface: Location: src/main/java/com/example/demo/producto/domain/repositories/ProductoRepository.java
ProductoRepository.java
public interface ProductoRepository {
    List<ProductoPOJO> findAll();
    ProductoPOJO getProductByNombre(String nombre);
}

Data Models

ProductoPOJO

The product domain model used across all product use cases.
FieldTypeDescription
idLongUnique identifier
nombreStringProduct name
precioPrecioVOPrice value object
See Product Model for complete documentation.

PrecioVO

Value object for price handling with built-in validation. Validation Rules:
  • Cannot be null
  • Must be non-negative (>= 0)
  • Stored as Float type for decimal precision
See Product Model for complete documentation.

Implementation Guide

Creating a REST Controller

To expose these use cases through REST endpoints, create a controller:
ProductoRestController.java
package com.example.demo.producto.infrastructure.controllers;

import org.springframework.web.bind.annotation.*;
import com.example.demo.producto.application.usecases.*;
import com.example.demo.producto.domain.models.ProductoPOJO;
import java.util.List;

@RestController
@RequestMapping("/productos")
public class ProductoRestController {
    
    private final ConsultarProductoDetalladoUC consultarProductoDetalladoUC;
    private final RecuperarTodosLosProductosUC recuperarTodosLosProductosUC;
    
    public ProductoRestController(
            ConsultarProductoDetalladoUC consultarProductoDetalladoUC,
            RecuperarTodosLosProductosUC recuperarTodosLosProductosUC) {
        this.consultarProductoDetalladoUC = consultarProductoDetalladoUC;
        this.recuperarTodosLosProductosUC = recuperarTodosLosProductosUC;
    }
    
    @GetMapping("/nombre/{nombre}")
    public ProductoPOJO getProductByName(@PathVariable String nombre) {
        return consultarProductoDetalladoUC.execute(nombre);
    }
    
    @GetMapping
    public List<ProductoPOJO> getAllProducts() {
        return recuperarTodosLosProductosUC.execute();
    }
}

Suggested REST Endpoints

Once the controller is implemented, the following endpoints would be available:
cURL
curl -X GET http://localhost:8080/productos/nombre/Laptop%20Dell%20XPS%2015
Response:
{
  "id": 101,
  "nombre": "Laptop Dell XPS 15",
  "precio": {
    "value": 1299.99
  }
}
cURL
curl -X GET http://localhost:8080/productos
Response:
[
  {
    "id": 101,
    "nombre": "Laptop Dell XPS 15",
    "precio": {
      "value": 1299.99
    }
  },
  {
    "id": 102,
    "nombre": "Mouse Logitech MX Master 3",
    "precio": {
      "value": 99.99
    }
  }
]

Architecture

The Product module follows Clean Architecture and Domain-Driven Design principles:

Application Layer

Use cases implementing business logic
  • ConsultarProductoDetalladoUC
  • RecuperarTodosLosProductosUC

Domain Layer

Core business models and interfaces
  • ProductoPOJO
  • PrecioVO
  • ProductoRepository (interface)

Infrastructure Layer

Technical implementations
  • ProductoAdapterRepository
  • ProductoEntity (JPA)
  • ProductoJPARepository
  • REST Controller (to be implemented)

Product Model

Complete ProductoPOJO and PrecioVO documentation

Clean Architecture

Understanding the architecture pattern

Build docs developers (and LLMs) love