Skip to content

Commit

Permalink
a few more changes to index
Browse files Browse the repository at this point in the history
  • Loading branch information
Highfire1 committed Jun 4, 2024
1 parent fc6856c commit 9f42345
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 52 deletions.
43 changes: 15 additions & 28 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from sdk.schema.ScheduleEntry import ScheduleEntry, ScheduleEntryDB, ScheduleEntryAPI
from sdk.schema.Transfer import Transfer

from sdk.schema_built.ApiResponses import IndexCourse, IndexCourseList, IndexSemester, IndexSemesterList, IndexSubjectList
from sdk.schema_built.ApiResponses import IndexCourseList, IndexSemester, IndexSemesterList
from sdk.schema_built.Course import CourseDB, CourseAPI, CourseAPIExt, CourseBase, CourseAPIBuild
from sdk.schema_built.Semester import Semester, SemesterCourses, SemesterSections

Expand Down Expand Up @@ -125,7 +125,7 @@ async def semesters_all() -> dict[str, int]:
}

@app.get(
"/index/all_semesters",
"/index/semesters",
summary="All semesters.",
description="Returns all semesters from which data is available",
response_model=IndexSemesterList
Expand All @@ -141,43 +141,30 @@ async def semesters_all() -> list[str]:
semesters = result
)



@app.get(
"/index/all_subjects",
summary="All subjects.",
description="Returns all known subjects.",
response_model=IndexSubjectList
)
async def all_subjects():

with Session(controller.engine) as session:
statement = select(CourseSummaryDB.subject).distinct()
results = session.exec(statement)
result = results.all()

return IndexSubjectList(
count = len(result),
subjects = result
)


@app.get(
"/index/all_courses",
"/index/courses",
summary="All courses.",
description="Returns all known courses.",
description="Returns all known subjects and their courses.",
response_model=IndexCourseList
)
async def courses_all() -> IndexCourseList: #list[tuple[str, int]]:
async def courses() -> IndexCourseList:

with Session(controller.engine) as session:
statement = select(CourseSummaryDB.subject, CourseSummaryDB.course_code).distinct()
results = session.exec(statement)
result = results.all()


subjects = {}
for r in result:
if r[0] not in subjects:
subjects[r[0]] = []
subjects[r[0]].append(r[1])

return IndexCourseList(
count = len(result),
courses = result
subject_count = len(subjects),
course_code_count= len(result),
subjects = subjects
)


Expand Down
31 changes: 7 additions & 24 deletions sdk/schema_built/ApiResponses.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,20 @@ class IndexSubjectList(SQLModel):
]
}
}

class IndexCourse(SQLModel):
subject: str
course_code: int

model_config = {
"json_schema_extra": {
"examples": [
{
"subject": "ENGL",
"course_code": 1123
}
]
}
}


class IndexCourseList(SQLModel):
count: int
courses: list[IndexCourse]
subject_count: int
course_code_count: int
subjects: dict[str, list]

model_config = {
"json_schema_extra": {
"examples": [
{
"count": 1500,
"courses" : [
{
"subject": "ENGL",
"course_code": 1123
}
]
"subject_count" : 80,
"course_code_count" : 1500,
"subjects" : {"ENGL" : [1100, 1101]}
}
]
}
Expand Down

0 comments on commit 9f42345

Please sign in to comment.