From 8b1b4aef9520b16dcbfb32a39d00898d91054822 Mon Sep 17 00:00:00 2001 From: Anderson T Date: Sat, 22 Jun 2024 08:59:47 -0700 Subject: [PATCH] add transfer route to api --- api.py | 25 ++++++++++++++++++++++--- sdk/schema/Transfer.py | 4 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/api.py b/api.py index afc8703..79d7cb6 100644 --- a/api.py +++ b/api.py @@ -28,7 +28,7 @@ from sdk.schema.CourseSummary import CourseSummaryDB from sdk.schema.ScheduleEntry import ScheduleEntryDB from sdk.schema.Section import SectionDB, SectionAPI -from sdk.schema.Transfer import TransferDB +from sdk.schema.Transfer import TransferAPI, TransferDB from sdk.schema.BaseModels import Course, Semester @@ -303,7 +303,7 @@ async def semesterSectionsInfo( section = results.first() if section == None: - return 404 + raise HTTPException(status_code=404, detail="Course not found.") statement = select(ScheduleEntryDB).where(ScheduleEntryDB.year == year, ScheduleEntryDB.term == term, ScheduleEntryDB.crn == crn) results = session.exec(statement) @@ -316,7 +316,26 @@ async def semesterSectionsInfo( out["schedule"].append(s.model_dump()) return out - + +@app.get( + "/transfers/{institution_code}", + summary="Transfer information.", + description="Get all available transfers to a given institution.", + response_model=list[TransferAPI] +) +async def semesterSectionsInfo( + *, + session: Session = Depends(get_session), + institution_code: str, +): + statement = select(TransferDB).where(TransferDB.destination == institution_code).order_by(col(TransferDB.credit).asc()) + results = session.exec(statement) + transfers = results.all() + + if transfers == None: + raise HTTPException(status_code=404, detail="Institution not found.") + + return transfers # my wares are too powerful for you, traveller @app.get( diff --git a/sdk/schema/Transfer.py b/sdk/schema/Transfer.py index 28aee72..50ba0f3 100644 --- a/sdk/schema/Transfer.py +++ b/sdk/schema/Transfer.py @@ -13,10 +13,10 @@ class Transfer(SQLModel): source_credits: Optional[float] = Field(description="Credits at the source institution.") source_title : Optional[str] = Field(description="Course title at the source institution.") - destination: str = Field(description="Destination institution code e.g. ```SFU```.") + destination: str = Field(index=True, description="Destination institution code e.g. ```SFU```.") destination_name: str = Field(description="Destination institution full name e.g. ```Simon Fraser University```.") - credit: str = Field(description="How many credits is the course worth at the source institution.") + credit: str = Field(index=True, description="How many credits is the course worth at the source institution.") condition: Optional[str] = Field(description="Additional conditions that apply to the credit transfer.") effective_start: str = Field(description="When this transfer agreement began.")