Skip to main content

Reserve a Classroom

curl -X POST http://localhost:8000/api/v1/reservar-aula \
  -H "Content-Type: application/json" \
  -d '{
    "asignatura_id": "A001",
    "aula_id": "AU001",
    "fecha": "22/07/2024",
    "dia": "Lunes",
    "hora_inicio": "07:00",
    "hora_fin": "09:00",
    "cantidad_estudiantes": 30,
    "semestre": 1,
    "docente_id": "D001",
    "id_usuario": "USR001"
  }'
{
  "success": true,
  "message": "Reserva realizada para 24 sesiones.",
  "reservas": [
    {
      "id": "PROG001",
      "aula_id": "AU001",
      "docente_id": "D001",
      "asignatura_id": "A001",
      "fecha": "22/07/2024",
      "hora_inicio": "07:00",
      "hora_fin": "09:00",
      "id_usuario": "USR001",
      "fecha_creacion": "2024-07-15",
      "hora_creacion": "14:30",
      "estado": "reservado",
      "dia": "Lunes",
      "semestre": 1,
      "estudiantes": 30
    }
  ]
}

POST /reservar-aula

Creates a classroom reservation for a course. Automatically generates recurring sessions based on course duration.

How It Works

  1. Validates availability - Checks if the classroom is available using the same constraints as /aulas-disponibles
  2. Retrieves course duration - Gets the course duration (e.g., “6 meses”) from course data
  3. Generates recurring dates - Creates weekly sessions for the entire course duration
  4. Checks for conflicts - Ensures no existing reservations conflict with any generated session
  5. Creates all sessions - Saves all reservations with status reservado
This endpoint creates recurring weekly reservations. A 6-month course will generate approximately 24 sessions.

Request Body

asignatura_id
string
required
Course ID. System will retrieve course duration to generate recurring sessions.Example: "A001"
aula_id
string
required
Classroom ID to reserve. Must be available for the requested time.Example: "AU001"
fecha
string
required
Start date in format DD/MM/YYYY. This is the date of the first session.Example: "22/07/2024"
dia
string
required
Day of the week for recurring sessions. Must match the day of fecha.Example: "Lunes"
hora_inicio
string
required
Start time in format HH:MM.Example: "07:00"
hora_fin
string
required
End time in format HH:MM.Example: "09:00"
cantidad_estudiantes
integer
required
Number of students. Used for availability validation.Example: 30
semestre
integer
required
Semester number (1-10).Example: 1
docente_id
string
Professor/instructor ID assigned to teach the course.Example: "D001"
id_usuario
string
required
User ID making the reservation. Used for audit trail.Example: "USR001"

Response Fields

success
boolean
Indicates if the reservation was created successfully
message
string
Human-readable message, e.g., “Reserva realizada para 24 sesiones.”
reservas
array
List of all created reservation sessions

Get All Reservations

curl http://localhost:8000/api/v1/programaciones
{
  "programaciones": [
    {
      "id": "PROG001",
      "aula_id": "AU001",
      "docente_id": "D001",
      "asignatura_id": "A001",
      "fecha": "2024-07-22",
      "hora_inicio": "07:00",
      "hora_fin": "09:00",
      "dia": "Lunes",
      "id_usuario": "USR001",
      "fecha_creacion": "2025-06-16",
      "hora_creacion": "21:18",
      "estado": "ocupado",
      "semestre": 1,
      "horario_id": "H_PROG001_20250617_151314",
      "fecha_confirmacion": "2025-06-17T15:13:14.191244"
    }
  ],
  "total": 1
}

GET /programaciones

Retrieves all reservations/schedules in the system.

Response Fields

programaciones
array
List of all programaciones (reservations)
total
integer
Total count of programaciones

Get Single Reservation

curl http://localhost:8000/api/v1/programaciones/PROG001
{
  "id": "PROG001",
  "aula_id": "AU001",
  "docente_id": "D001",
  "asignatura_id": "A001",
  "fecha": "2024-07-22",
  "hora_inicio": "07:00",
  "hora_fin": "09:00",
  "dia": "Lunes",
  "estado": "reservado",
  "semestre": 1
}

GET /programaciones/

Retrieves a specific reservation by ID.

Path Parameters

programacion_id
string
required
The unique ID of the programacion to retrieveExample: "PROG001"

Update Reservation Status

curl -X PUT 'http://localhost:8000/api/v1/programaciones/PROG001/estado?nuevo_estado=ocupado'
{
  "success": true,
  "message": "Estado cambiado a ocupado",
  "programacion": {
    "id": "PROG001",
    "estado": "ocupado",
    "aula_id": "AU001",
    "asignatura_id": "A001"
  }
}

PUT /programaciones//estado

Changes the status of a reservation.

Path Parameters

programacion_id
string
required
ID of the programacion to updateExample: "PROG001"

Query Parameters

nuevo_estado
string
required
New status. Valid values: reservado, ocupado, canceladoExample: "ocupado"

Status Workflow

  • reservado: Initial state when reservation is created
  • ocupado: Confirmed and in use (typically set when schedule is finalized)
  • cancelado: Reservation cancelled

Cancel Reservation

curl -X DELETE http://localhost:8000/api/v1/programaciones/PROG001
{
  "success": true,
  "message": "Estado cambiado a cancelado",
  "programacion": {
    "id": "PROG001",
    "estado": "cancelado"
  }
}

DELETE /programaciones/

Cancels a reservation by setting its status to cancelado.
This is a soft delete. The programacion record is not removed, just marked as cancelled.

Path Parameters

programacion_id
string
required
ID of the programacion to cancelExample: "PROG001"

Reservation Workflow

Complete Workflow Example

import requests

BASE_URL = "http://localhost:8000/api/v1"

# Step 1: Check availability
availability = requests.post(f"{BASE_URL}/aulas-disponibles", json={
    "asignatura_id": "A001",
    "hora_inicio": "07:00",
    "hora_fin": "09:00",
    "dia": "Lunes",
    "cantidad_estudiantes": 30,
    "semestre": 1
}).json()

if availability['total_disponibles'] == 0:
    print("No classrooms available")
    exit()

# Step 2: Select first available classroom and reserve
selected_aula = availability['aulas_disponibles'][0]
reservation = requests.post(f"{BASE_URL}/reservar-aula", json={
    "asignatura_id": "A001",
    "aula_id": selected_aula['id'],
    "fecha": "22/07/2024",
    "dia": "Lunes",
    "hora_inicio": "07:00",
    "hora_fin": "09:00",
    "cantidad_estudiantes": 30,
    "semestre": 1,
    "docente_id": "D001",
    "id_usuario": "USR001"
}).json()

if reservation['success']:
    prog_id = reservation['reservas'][0]['id']
    print(f"Reserved! Programacion ID: {prog_id}")
    
    # Step 3: Later, confirm the reservation
    confirm = requests.put(
        f"{BASE_URL}/programaciones/{prog_id}/estado",
        params={'nuevo_estado': 'ocupado'}
    ).json()
    
    print(f"Confirmed: {confirm['success']}")

Build docs developers (and LLMs) love