feat(ux): separate physical and virtual classroom KPIs, fix month sessions filter, improve admin contrast, persist sidebar submenus, and relocate theme toggle (v3.8.14)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
FastAPI Reservations Router (/api/v1/reservations)
|
||||
Handles creation, listing, updating, cancelling, confirmation and full conflict matrix validation.
|
||||
"""
|
||||
import calendar
|
||||
from typing import Optional, Any, Dict
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status, Request
|
||||
@@ -21,11 +22,17 @@ reservation_service = ReservationService()
|
||||
|
||||
|
||||
@reservations_router.get("")
|
||||
@reservations_router.get("/")
|
||||
def list_reservations(
|
||||
start_date: Optional[str] = Query(None),
|
||||
end_date: Optional[str] = Query(None),
|
||||
date_from: Optional[str] = Query(None),
|
||||
date_to: Optional[str] = Query(None),
|
||||
scope: Optional[str] = Query(None),
|
||||
classroom_id: Optional[str] = Query(None),
|
||||
hide_virtual: Optional[str] = Query(None),
|
||||
only_virtual: Optional[str] = Query(None),
|
||||
status_filter: Optional[str] = Query(None, alias="status"),
|
||||
floor: Optional[str] = Query(None),
|
||||
shift: Optional[str] = Query(None),
|
||||
search: Optional[str] = Query(None),
|
||||
@@ -33,24 +40,47 @@ def list_reservations(
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Consulta de reservas por rango de fechas y/o aula con filtros en SQL."""
|
||||
effective_start = (date_from or start_date or "").strip()
|
||||
effective_end = (date_to or end_date or "").strip()
|
||||
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
try:
|
||||
start_dt = datetime.strptime(start_date, '%Y-%m-%d') if start_date else now.replace(hour=0, minute=0, second=0)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Formato inválido de start_date (debe ser YYYY-MM-DD).")
|
||||
|
||||
try:
|
||||
end_dt = datetime.strptime(end_date, '%Y-%m-%d').replace(hour=23, minute=59, second=59) if end_date else start_dt + timedelta(days=7)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Formato inválido de end_date (debe ser YYYY-MM-DD).")
|
||||
# Resolución inteligente de rangos según scope o filtros
|
||||
if scope == 'month' and not effective_start and not effective_end:
|
||||
start_dt = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
||||
_, last_day = calendar.monthrange(now.year, now.month)
|
||||
end_dt = now.replace(day=last_day, hour=23, minute=59, second=59, microsecond=999999)
|
||||
elif scope == 'today' and not effective_start and not effective_end:
|
||||
start_dt = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end_dt = now.replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
elif scope == 'week' and not effective_start and not effective_end:
|
||||
start_of_week = now - timedelta(days=now.weekday())
|
||||
start_dt = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end_of_week = start_of_week + timedelta(days=6)
|
||||
end_dt = end_of_week.replace(hour=23, minute=59, second=59, microsecond=999999)
|
||||
elif not effective_start and not effective_end:
|
||||
# Si no se especificó rango, abarcar desde inicio del mes actual hasta 90 días adelante para no dejar el listado vacío
|
||||
start_dt = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
||||
end_dt = (start_dt + timedelta(days=90)).replace(hour=23, minute=59, second=59)
|
||||
else:
|
||||
try:
|
||||
start_dt = datetime.strptime(effective_start, '%Y-%m-%d') if effective_start else now.replace(day=1, hour=0, minute=0, second=0)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Formato inválido de fecha inicial (debe ser YYYY-MM-DD).")
|
||||
try:
|
||||
end_dt = datetime.strptime(effective_end, '%Y-%m-%d').replace(hour=23, minute=59, second=59) if effective_end else (start_dt + timedelta(days=60)).replace(hour=23, minute=59, second=59)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Formato inválido de fecha final (debe ser YYYY-MM-DD).")
|
||||
|
||||
is_hide_virtual = str(hide_virtual).lower() in ['1', 'true']
|
||||
is_only_virtual = str(only_virtual).lower() in ['1', 'true']
|
||||
parsed_classroom_id = int(classroom_id.strip()) if classroom_id and classroom_id.strip().isdigit() else None
|
||||
|
||||
reservations = reservation_service.list_reservations(
|
||||
start_dt, end_dt,
|
||||
classroom_id=parsed_classroom_id,
|
||||
is_hide_virtual=is_hide_virtual,
|
||||
only_virtual=is_only_virtual,
|
||||
status=status_filter,
|
||||
floor=floor,
|
||||
shift=shift,
|
||||
search=search,
|
||||
|
||||
Reference in New Issue
Block a user