File tree Expand file tree Collapse file tree 5 files changed +74
-1
lines changed
Expand file tree Collapse file tree 5 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 1010from src .students .missing_students .router import router as student_recover_attendance_router
1111from src .students .attendance_entry .router import router as student_attendance_entry_router
1212from src .students .withdrawal_processing .router import router as student_withdrawal_router
13+ from src .slack .student_info .router import router as student_info_router
1314
1415from src .gsheet .refresh .router import router as gsheet_refresh_router
1516from src .utils .authorization import verify_api_key
9192 gsheet_refresh_router ,
9293 prefix = "/gsheet/refresh" ,
9394 tags = ["GSheet" ],
94- )
95+ )
96+
97+ api_router .include_router (
98+ student_info_router ,
99+ prefix = "/slack/students/info" ,
100+ tags = ["Stack" ],
101+ )
Original file line number Diff line number Diff line change 1+ from typing import Any , Dict
2+
3+ from fastapi import APIRouter , Depends , status
4+ from sqlalchemy .orm import Session
5+
6+ from src .database .postgres .core import make_session
7+ from src .slack .student_info .service import fetch_student_info
8+ from src .utils .exceptions import handle_db_exceptions
9+
10+ router = APIRouter ()
11+
12+ @router .get ("" , status_code = status .HTTP_200_OK )
13+ def fetch_student_information (
14+ user_email : str ,
15+ db : Session = Depends (make_session ),
16+ ) -> Dict [str , Any ]:
17+ """
18+ Fetch student information from the database.
19+ """
20+ try :
21+ return fetch_student_info (db , user_email )
22+ except Exception as exc :
23+ handle_db_exceptions (db , exc )
Original file line number Diff line number Diff line change 1+ from sqlalchemy import select
2+ from sqlalchemy .orm import Session
3+
4+ from src .database .postgres .models import Student , StudentEmail
5+
6+ 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+ """
20+
21+ select_stmt = select (
22+ Student .cti_id ,
23+ Student .fname ,
24+ Student .lname ,
25+ Student .pname ,
26+ Student .institution ,
27+ Student .target_year ,
28+ Student .join_date ,
29+ Student .gender ,
30+ Student .ethnicities_agg ,
31+ Student .birthday ,
32+ Student .first_gen ,
33+ StudentEmail .email ).join (StudentEmail ).where (StudentEmail .email == user_email )
34+
35+ results = db .execute (select_stmt ).all ()
36+
37+ if len (results ) == 0 :
38+ raise ValueError ("No student records found" )
39+
40+ if len (results ) > 1 :
41+ raise ValueError ("Multiple student records found" )
42+
43+ return results [0 ]._asdict ()
You can’t perform that action at this time.
0 commit comments