Skip to content

Commit 39dd00d

Browse files
Changed sql result and exception to HTTP
1 parent 76d3a45 commit 39dd00d

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/slack/student_info/service.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1+
from fastapi import HTTPException
12
from sqlalchemy import select
23
from sqlalchemy.orm import Session
34

45
from src.database.postgres.models import Student, StudentEmail
56

67
def 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

Comments
 (0)