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
- Validates availability - Checks if the classroom is available using the same constraints as
/aulas-disponibles
- Retrieves course duration - Gets the course duration (e.g., “6 meses”) from course data
- Generates recurring dates - Creates weekly sessions for the entire course duration
- Checks for conflicts - Ensures no existing reservations conflict with any generated session
- 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
Course ID. System will retrieve course duration to generate recurring sessions.Example: "A001"
Classroom ID to reserve. Must be available for the requested time.Example: "AU001"
Start date in format DD/MM/YYYY. This is the date of the first session.Example: "22/07/2024"
Day of the week for recurring sessions. Must match the day of fecha.Example: "Lunes"
Start time in format HH:MM.Example: "07:00"
End time in format HH:MM.Example: "09:00"
Number of students. Used for availability validation.Example: 30
Semester number (1-10).Example: 1
Professor/instructor ID assigned to teach the course.Example: "D001"
User ID making the reservation. Used for audit trail.Example: "USR001"
Response Fields
Indicates if the reservation was created successfully
Human-readable message, e.g., “Reserva realizada para 24 sesiones.”
List of all created reservation sessions
Unique programacion ID (auto-generated: PROG001, PROG002, etc.)
Session date in DD/MM/YYYY format
User who created the reservation
Date when reservation was created (YYYY-MM-DD)
Time when reservation was created (HH:MM)
Reservation status: reservado, ocupado, or cancelado
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
List of all programaciones (reservations)
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
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
ID of the programacion to updateExample: "PROG001"
Query Parameters
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
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']}")