Overview
The Unit of Measures API provides endpoints to manage measurement unit catalog entries in the furniture store system. Each unit includes a name, abbreviation, and active status. Base URL:/unit-of-measures
Endpoints
List Unit of Measures
Retrieve all unit of measures from the catalog.Response
Returns an HTML page with the list of unit of measures. For API consumption, units are represented as:Unique identifier for the unit of measure
Name of the unit of measure (max 50 characters)
Abbreviation for the unit (max 10 characters)
Whether the unit is active
ISO 8601 timestamp of creation
ISO 8601 timestamp of last update
Example Request
Example Response
Create Unit of Measure
Create a new unit of measure entry in the catalog.Request Parameters
Name of the unit of measureValidation:
- Required field
- Maximum 50 characters
- Must be unique
Abbreviation for the unit of measureValidation:
- Required field
- Maximum 10 characters
- Must be unique
Whether the unit is activeDefault:
trueResponse
Success:- Flash message: “Unidad de medida creada exitosamente”
- Redirects to
/unit-of-measures/
Returned when a unit with the same name or abbreviation already exists
Returned when validation rules are violated
Example Request
Error Response
Edit Unit of Measure
Update an existing unit of measure in the catalog.Path Parameters
Unique identifier of the unit of measure to edit
Request Parameters
Updated name for the unit of measureValidation:
- Required field
- Maximum 50 characters
- Must be unique
Updated abbreviation for the unit of measureValidation:
- Required field
- Maximum 10 characters
- Must be unique
The
active field is displayed in the GET form (line 97) but not included in the POST update data (lines 83-86). This may be intentional to prevent accidental deactivation.Response
Success:- Flash message: “Unidad de medida actualizada exitosamente”
- Redirects to
/unit-of-measures/
Returned when the unit ID does not existFlash message: “Unidad de medida no encontrada”Redirects to
/unit-of-measures/Returned when the updated name or abbreviation conflicts with an existing unit
Returned when validation rules are violated
Example Request
Delete Unit of Measure
Perform logical deletion of a unit of measure (marks as inactive).Path Parameters
Unique identifier of the unit of measure to delete
Response
Success:- Flash message: “Unidad de medida eliminada exitosamente”
- Redirects to
/unit-of-measures/
Returned when the unit ID does not existFlash message: “Unidad de medida no encontrada”Redirects to
/unit-of-measures/Example Request
Data Model
Unit of Measure Object
Validation Rules
- name: Required, unique, max 50 characters
- abbreviation: Required, unique, max 10 characters
- active: Boolean, defaults to
true - All endpoints require CSRF token for POST requests
Error Messages
| Error | Message |
|---|---|
| Missing name | ”El nombre de la unidad de medida es requerido” |
| Name too long | ”El nombre no puede exceder 50 caracteres” |
| Missing abbreviation | ”La abreviatura de la unidad de medida es requerida” |
| Abbreviation too long | ”La abreviatura no puede exceder 10 caracteres” |
| Duplicate name/abbr | Service-specific conflict error |
| Not found | ”Unidad de medida no encontrada” |
Implementation Details
- Source:
app/catalogs/unit_of_measures/routes.py:18-118 - Form:
app/catalogs/unit_of_measures/forms.py:10-27 - Model:
app/models/unit_of_measure.py:6-64 - Pattern: Post-Redirect-Get (PRG) for all form submissions
- Deletion: Logical (soft delete) - sets
active=falseanddeleted_attimestamp - Note: Flash messages use “danger” class instead of “error” for consistency with Bootstrap