File size: 1,207 Bytes
71a3948
93cf1dc
71a3948
ec5cc84
93cf1dc
 
2847bfd
93cf1dc
 
 
 
71a3948
 
 
 
93cf1dc
 
71a3948
 
3358b33
93cf1dc
 
 
71a3948
 
93cf1dc
 
71a3948
93cf1dc
71a3948
93cf1dc
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from fastapi import APIRouter, Depends, HTTPException, status
from sqlmodel import Session, SQLModel

from src.auth import get_current_active_user
from src.database import get_session
from src.models import StudentReadWithClearance
from src.crud import students as student_crud

# This is the new request body model for the POST request.
class StudentLookupRequest(SQLModel):
    matric_no: str

router = APIRouter(
    prefix="/students",
    tags=["Students"],
    # This endpoint still requires a user to be logged in.
    dependencies=[Depends(get_current_active_user)]
)

@router.get("/lookup", response_model=StudentReadWithClearance)
def lookup_student_by_matric_no(
    request: StudentLookupRequest,
    db: Session = Depends(get_session)
):
    """
    Endpoint for a logged-in user to retrieve a student's profile
    and clearance information by providing their matriculation number.
    """
    student = student_crud.get_student_by_matric_no(db=db, matric_no=request.matric_no)

    if not student:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND, 
            detail="Student with the provided matriculation number not found."
        )
    
    return student