Skip to content

Commit 76d3a45

Browse files
Get student info prototyped
1 parent 67f43d9 commit 76d3a45

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

src/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from src.students.missing_students.router import router as student_recover_attendance_router
1111
from src.students.attendance_entry.router import router as student_attendance_entry_router
1212
from 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

1415
from src.gsheet.refresh.router import router as gsheet_refresh_router
1516
from src.utils.authorization import verify_api_key
@@ -91,4 +92,10 @@
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+
)

src/slack/__init__.py

Whitespace-only changes.

src/slack/student_info/__init__.py

Whitespace-only changes.

src/slack/student_info/router.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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)

src/slack/student_info/service.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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()

0 commit comments

Comments
 (0)