Category Management
Relevant source files
The following files were used as context for generating this wiki page:
- Back/Alumnos/Api/Controllers/CategoriaController.cs
- Back/Alumnos/Api/Entidades/Categoria.cs
- Back/Alumnos/Api/Comun/Modelos/Categorias/CrearCategoriaDto.cs
- Back/Alumnos/Api/Comun/Modelos/Categorias/ModificarCategoriaDto.cs
- Back/Alumnos/Api/Comun/Modelos/Categorias/BuscarCategoriaDto.cs
- Back/Alumnos/Api/Comun/Utilidades/MapeoDtos.cs
- Back/Alumnos/Api/Persistencia/Configuraciones/CategoriaConfiguracion.cs
- Front/src/pages/home.jsx
- Front/src/pages/publishProduct.jsx
Category Management is a core module responsible for organizing and classifying products within the application. It provides a structured way to group items, facilitating efficient searching, filtering, and navigation for both buyers and sellers. The system encompasses backend data persistence and API endpoints, as well as frontend user interfaces for filtering products and selecting categories during the publication process.
Sources: Back/Alumnos/Api/Entidades/Categoria.cs, Front/src/pages/home.jsx:13-22
Data Architecture and Models
The backend utilizes an Entity-Relationship model where Categoria acts as a classification entity for Producto. Each category is uniquely identified and includes descriptive attributes used for both display and SEO-friendly routing (Slugs).
Database Entity
The Categoria entity defines the structure of category records in the database.
| Field | Type | Description |
|---|---|---|
| CategoriaID | int | Primary Key |
| Nombre | string | The display name of the category |
| Descripcion | string | A detailed description of the category |
| Slug | string | URL-friendly identifier |
| Productos | List<Producto> | Virtual collection of related products |
Sources: Back/Alumnos/Api/Entidades/Categoria.cs:5-24, Back/Alumnos/Api/Persistencia/Configuraciones/CategoriaConfiguracion.cs:9-12
Entity Relationships
The following diagram illustrates the relationship between Categories and Products.
The system maintains a one-to-many relationship where a single Category can be associated with multiple Products.
Sources: Back/Alumnos/Api/Entidades/Categoria.cs:12, Back/Alumnos/Api/Entidades/Producto.cs:15-18
Backend API Implementation
The CategoriasController manages the lifecycle of category data through RESTful endpoints. It interacts with the IAplicacionBdContexto to perform CRUD operations.
API Endpoints
| Method | Route | Description |
|---|---|---|
| GET | /categorias | Retrieves a list of categories, optionally filtered by name or description. |
| GET | /categorias/{slug} | Retrieves a specific category by its slug identifier. |
| POST | /categorias | Creates a new category record. |
| PUT | /categorias/{slug} | Updates an existing category based on its slug. |
| DELETE | /categorias/{id} | Removes a category by its ID. |
Sources: Back/Alumnos/Api/Controllers/CategoriaController.cs:13-100
Data Transfer Objects (DTOs)
The system uses specialized DTOs to separate internal entities from the external API interface.
- CrearCategoriaDto: Used for creating new categories, requiring Name, Description, and Slug.
- ModificarCategoriaDto: Includes
CategoriaIDfor identification during updates. - BuscarCategoriaDto: Used for returning category data to the client.
Sources: Back/Alumnos/Api/Comun/Modelos/Categorias/CrearCategoriaDto.cs, Back/Alumnos/Api/Comun/Modelos/Categorias/ModificarCategoriaDto.cs, Back/Alumnos/Api/Comun/Modelos/Categorias/BuscarCategoriaDto.cs
Mapping Logic
A static utility class handles the conversion from the Categoria entity to BuscarCategoriaDto.
public static BuscarCategoriaDto ConvertirDto(this Categoria categoria)
{
return new BuscarCategoriaDto
{
CategoriaID = categoria.CategoriaID,
Nombre = categoria.Nombre,
Descripcion = categoria.Descripcion,
Slug = categoria.Slug,
};
}
Sources: Back/Alumnos/Api/Comun/Utilidades/MapeoDtos.cs:38-46
Frontend Integration
The frontend uses categories primarily for product filtering on the home page and for classification during product creation.
Product Filtering Flow
In the Home component, categories are used to filter the displayed product list. The UI dynamically generates filter buttons based on a predefined list and the categories actually present in the products.
Sources: Front/src/pages/home.jsx:25-39
Category Selection in Publishing
When a user publishes a new product, they must select a category from a predefined set of options. This ensures that new items are correctly classified within the system.
const CATEGORIES = [
'Electrónica',
'Libros',
'Ropa',
'Deportes',
'Hogar',
'Videojuegos',
'Otros'
];
Sources: Front/src/pages/publishProduct.jsx:7-15, Front/src/pages/publishProduct.jsx:128-144
Summary
Category Management provides the organizational backbone for the project, enabling a structured marketplace. Through a combination of robust backend API controllers, clear data modeling via DTOs, and intuitive frontend filtering mechanisms, the system ensures that products are easily discoverable and consistently categorized across the platform.