45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""
|
|
FastAPI Students Router (/api/v1/students)
|
|
Provides academic milestone and gradebook queries for students.
|
|
"""
|
|
from typing import Optional
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
|
|
|
|
from app.services.gradebook_service import GradebookService
|
|
from dependencies import get_current_user
|
|
from app.models.user import User
|
|
|
|
students_router = APIRouter(prefix="/api/v1/students", tags=["Students"])
|
|
|
|
|
|
@students_router.get("/my-grades")
|
|
def get_my_grades(
|
|
request: Request,
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Consulta individual de calificaciones y estado académico del alumno logueado."""
|
|
try:
|
|
grades = GradebookService.get_student_grades(current_user.id)
|
|
is_impersonating = bool(request.headers.get('X-Impersonate-User'))
|
|
return {
|
|
'status': 'success',
|
|
'student_id': current_user.id,
|
|
'is_impersonating': is_impersonating,
|
|
'data': grades
|
|
}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|
|
|
|
|
|
@students_router.get("/my-upcoming-milestones")
|
|
def get_my_upcoming_milestones(
|
|
limit: int = Query(5, ge=1, le=50),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""Próximas evaluaciones e hitos académicos con cuenta regresiva para el dashboard."""
|
|
try:
|
|
milestones = GradebookService.get_student_upcoming_milestones(current_user.id, limit=limit)
|
|
return {'status': 'success', 'data': milestones}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|