1+ from fastapi import HTTPException
12from sqlalchemy import select
23from sqlalchemy .orm import Session
34
45from src .database .postgres .models import Student , StudentEmail
56
67def fetch_student_info (db : Session , user_email : str ):
7- """
8- first_name Student.fname
9- last_name Student.lname
10- preferred_name Student.pname
11- primary_email StudentEmail !!
12- institution Student.institution
13- target_year Student.target_year
14- join_date Student.join_date
15- gender Student.gender
16- ethnicity Student.ethnicities_agg ??
17- birthday Student.birthday
18- first_generation Student.first_gen
19- """
208
219 select_stmt = select (
2210 Student .cti_id ,
@@ -32,12 +20,9 @@ def fetch_student_info(db: Session, user_email: str):
3220 Student .first_gen ,
3321 StudentEmail .email ).join (StudentEmail ).where (StudentEmail .email == user_email )
3422
35- results = db .execute (select_stmt ).all ()
23+ result = db .execute (select_stmt ).first ()
3624
37- if len ( results ) == 0 :
38- raise ValueError ( "No student records found" )
25+ if result is None :
26+ raise HTTPException ( status_code = 404 , detail = f "No student records found for email { user_email } " )
3927
40- if len (results ) > 1 :
41- raise ValueError ("Multiple student records found" )
42-
43- return results [0 ]._asdict ()
28+ return result ._asdict ()
0 commit comments