fix: corregir layout de dashboard, resiliencia en filtros de asignaturas y paginacion de bd (v3.8.12)
This commit is contained in:
@@ -24,14 +24,15 @@ reservation_service = ReservationService()
|
||||
def list_reservations(
|
||||
start_date: Optional[str] = Query(None),
|
||||
end_date: Optional[str] = Query(None),
|
||||
classroom_id: Optional[int] = Query(None),
|
||||
classroom_id: Optional[str] = Query(None),
|
||||
hide_virtual: Optional[str] = Query(None),
|
||||
floor: Optional[str] = Query(None),
|
||||
shift: Optional[str] = Query(None),
|
||||
search: Optional[str] = Query(None),
|
||||
limit: int = Query(1000, le=5000),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Consulta de reservas por rango de fechas y/o aula."""
|
||||
"""Consulta de reservas por rango de fechas y/o aula con filtros en SQL."""
|
||||
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)
|
||||
@@ -44,27 +45,22 @@ def list_reservations(
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Formato inválido de end_date (debe ser YYYY-MM-DD).")
|
||||
|
||||
is_hide_virtual = str(hide_virtual).lower() in ['1', 'true']
|
||||
parsed_classroom_id = int(classroom_id.strip()) if classroom_id and str(classroom_id).strip().isdigit() else None
|
||||
|
||||
reservations = reservation_service.list_reservations(start_dt, end_dt, classroom_id=classroom_id)
|
||||
reservations = reservation_service.list_reservations(
|
||||
start_dt, end_dt,
|
||||
classroom_id=parsed_classroom_id,
|
||||
is_hide_virtual=is_hide_virtual,
|
||||
floor=floor,
|
||||
shift=shift,
|
||||
search=search,
|
||||
limit=limit
|
||||
)
|
||||
result = []
|
||||
for r in reservations:
|
||||
is_virt = bool(r.is_virtual or (r.classroom and r.classroom.is_virtual))
|
||||
if is_hide_virtual and is_virt:
|
||||
continue
|
||||
if floor and r.classroom and str(r.classroom.floor).strip().lower() != floor.strip().lower():
|
||||
continue
|
||||
if shift and r.shift and shift.lower() not in r.shift.lower():
|
||||
continue
|
||||
r_user: Any = getattr(r, 'user', None)
|
||||
u_name = (getattr(r_user, 'name', '') or '').lower() if r_user else ''
|
||||
if search:
|
||||
s_lower = search.lower()
|
||||
subj_n = (r.subject_name or '').lower()
|
||||
subj_c = (r.subject_code or '').lower()
|
||||
c_name = (r.classroom.code if r.classroom else '').lower()
|
||||
if s_lower not in subj_n and s_lower not in subj_c and s_lower not in c_name and s_lower not in u_name:
|
||||
continue
|
||||
|
||||
is_virt = bool(r.is_virtual or (r.classroom and getattr(r.classroom, 'is_virtual', False)))
|
||||
user_dict = {
|
||||
'id': getattr(r_user, 'id', None),
|
||||
'name': getattr(r_user, 'name', None),
|
||||
|
||||
Reference in New Issue
Block a user