Skip to main content

Overview

The Colors API provides endpoints to manage color catalog entries in the furniture store system. All color operations support CRUD functionality with logical deletion. Base URL: /colors

Endpoints

List Colors

Retrieve all active colors from the catalog.
GET /colors/

Response

Returns an HTML page with the list of colors. For API consumption, colors are represented as:
id_color
integer
Unique identifier for the color
name
string
Name of the color (max 50 characters)
active
boolean
Whether the color is active
created_at
string
ISO 8601 timestamp of creation
updated_at
string
ISO 8601 timestamp of last update

Example Request

curl -X GET http://localhost:5000/colors/ \
  -H "Accept: text/html"

Example Response

[
  {
    "id_color": 1,
    "name": "Mahogany",
    "active": true,
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:30:00Z"
  },
  {
    "id_color": 2,
    "name": "Walnut",
    "active": true,
    "created_at": "2024-01-16T14:20:00Z",
    "updated_at": "2024-01-16T14:20:00Z"
  }
]

Create Color

Create a new color entry in the catalog.
GET  /colors/create
POST /colors/create
GET - Displays the creation form POST - Processes form submission and creates the color

Request Parameters

name
string
required
Name of the colorValidation:
  • Required field
  • Maximum 50 characters
  • Must be unique

Response

Success:
  • Flash message: “Color creado exitosamente”
  • Redirects to /colors/create
Error Cases:
ConflictError
error
Returned when a color with the same name already exists

Example Request

curl -X POST http://localhost:5000/colors/create \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "name=Cherry" \
  -d "csrf_token=your_csrf_token"

Error Response

<!-- Flash message displayed -->
<div class="alert alert-error">
  Ya existe un color con ese nombre
</div>

Edit Color

Update an existing color in the catalog.
GET  /colors/<id_color>/edit
POST /colors/<id_color>/edit
GET - Displays the edit form pre-populated with current data POST - Processes form submission and updates the color

Path Parameters

id_color
integer
required
Unique identifier of the color to edit

Request Parameters

name
string
required
Updated name for the colorValidation:
  • Required field
  • Maximum 50 characters
  • Must be unique

Response

Success:
  • Flash message: “Color actualizado exitosamente”
  • Redirects to /colors/
Error Cases:
NotFoundError
error
Returned when the color ID does not existRedirects to /colors/ with error message
ConflictError
error
Returned when the updated name conflicts with an existing color
ValidationError
error
Returned when validation rules are violated

Example Request

curl -X POST http://localhost:5000/colors/1/edit \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "name=Dark Mahogany" \
  -d "csrf_token=your_csrf_token"

Delete Color

Perform logical deletion of a color (marks as inactive).
POST /colors/<id_color>/delete

Path Parameters

id_color
integer
required
Unique identifier of the color to delete

Response

Success:
  • Flash message: “Color eliminado exitosamente”
  • Redirects to /colors/
Error Cases:
NotFoundError
error
Returned when the color ID does not existRedirects to /colors/ with error message

Example Request

curl -X POST http://localhost:5000/colors/1/delete \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "csrf_token=your_csrf_token"

Data Model

Color Object

{
  "id_color": 1,
  "name": "Mahogany",
  "active": true,
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}

Validation Rules

  • name: Required, unique, max 50 characters
  • active: Boolean, defaults to true
  • All endpoints require CSRF token for POST requests

Error Messages

ErrorMessage
Missing name”El nombre del color es requerido”
Name too long”El nombre no puede exceder 50 caracteres”
Duplicate name”Ya existe un color con ese nombre”
Not foundColor-specific error message from service

Implementation Details

  • Source: app/catalogs/colors/routes.py:13-106
  • Form: app/catalogs/colors/forms.py:10-19
  • Model: app/models/color.py:6-61
  • Pattern: Post-Redirect-Get (PRG) for all form submissions
  • Deletion: Logical (soft delete) - sets active=false and deleted_at timestamp

Build docs developers (and LLMs) love