Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ricpalomino/spring-boot/llms.txt

Use this file to discover all available pages before exploring further.

The Product model is the central domain object in this API. It represents a single item in the product catalog and appears in three distinct shapes depending on context: the internal Product entity used by the service and repository layers, the ProductRequestDTO accepted in POST and PUT request bodies, and the ProductResponseDTO returned in every API response. Understanding the difference between these shapes helps you construct valid requests and correctly parse the responses you receive.
The Product entity is an internal class never exposed directly over the wire. You send ProductRequestDTO when creating or updating a product, and you always receive ProductResponseDTO inside an ApiResponse<T> envelope. See the ApiResponse envelope page for details on the wrapper.

Product entity (internal)

Product is the internal domain object used by the service and repository layers. It is never serialized directly into an HTTP response.
id
Long
Auto-assigned unique identifier for the product. Set by the repository when a product is persisted.
name
String
Human-readable name of the product.
price
Double
Price of the product as a floating-point number.

ProductRequestDTO

Use ProductRequestDTO as the JSON body when calling POST /api/v1/products to create a product or PUT /api/v1/products/{id} to update one. Both fields are required and validated on arrival.
name
string
required
Product name. Must be between 3 and 100 characters and must not be blank. Validation error: "El nombre del producto debe tener entre 3 y 100 caracteres".
price
number
required
Product price. Must be at least 1. Validation error: "El precio del producto debe ser mayor a 0".

Validation constraints

FieldConstraintRuleError message
name@NotBlankMust not be null or empty"Nombre del proudcto es requerido"
name@Size(min=3, max=100)Between 3 and 100 characters"El nombre del producto debe tener entre 3 y 100 caracteres"
price@Min(1)Numeric value ≥ 1"El precio del producto debe ser mayor a 0"
When validation fails, the API returns a 400 response. The data field of the envelope contains a map of field names to their corresponding error messages. See the ApiResponse envelope page for an example.

ProductResponseDTO

ProductResponseDTO is the shape you receive in the data field of every successful product response. It mirrors the Product entity but is decoupled from it so that internal implementation details are never leaked to consumers.
id
Long
Auto-assigned unique identifier for the product.
name
String
Name of the product.
price
Double
Price of the product.

Source code

package com.zegel.springboot.dto;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class ProductRequestDTO {

    @NotBlank(message = "Nombre del proudcto es requerido")
    @Size(min = 3, max = 100, message = "El nombre del producto debe tener entre 3 y 100 caracteres")
    private String name;

    @Min(value = 1, message = "El precio del producto debe ser mayor a 0")
    private Double price;

    public ProductRequestDTO() {
    }

    public ProductRequestDTO(String name, Double price) {
        this.name = name;
        this.price = price;
    }

}

JSON examples

Request body

Send this JSON when creating or updating a product.
Request body
{
  "name": "Laptop Pro 15",
  "price": 1299.99
}

Response object

The data field of a successful response contains a ProductResponseDTO.
Response object
{
  "responseCode": "200",
  "responseMessage": "Producto obtenido correctamente",
  "data": {
    "id": 42,
    "name": "Laptop Pro 15",
    "price": 1299.99
  }
}

Build docs developers (and LLMs) love