From 1d920dc91ad1d2d7e00b697e613061fec189fe66 Mon Sep 17 00:00:00 2001 From: Ian <114031398+KingPhilip14@users.noreply.github.com> Date: Sat, 7 Oct 2023 00:36:04 -0500 Subject: [PATCH] Error api calls (#113) * Error api calls Made api calls that will return a list of errors based on the given submission. The submission is accessed by the id and uuid. * Error line Commented out error line * Submission apis Fixed code for getting a single submission or many submissions based on a given id. --- server/main.py | 29 +++++++++++++++++++++++++++-- server/models/submission.py | 2 +- server/schemas/submission_schema.py | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/server/main.py b/server/main.py index 4c101fb..eefb3fd 100644 --- a/server/main.py +++ b/server/main.py @@ -2,6 +2,7 @@ from sqlalchemy.orm import Session from models.base import Base from database import SessionLocal, engine +from crud import crud_errors, crud_submission from models.run import Run from models.errors import Errors from models.group_run import GroupRun @@ -10,6 +11,9 @@ from models.submission import Submission from models.turn_table import TurnTable from models.university import University +from schemas.university_schema import * +from schemas.submission_schema import * +from schemas.errors_schema import * Base.metadata.create_all(bind=engine) @@ -26,6 +30,27 @@ def get_db(): # API -@app.get("/") +@app.get('/') def root(): - return {"message": "Hello World"} \ No newline at end of file + return {"message": "Hello World"} + + +@app.get('/get_submission/', response_model=SubmissionSchema) +def get_submission(submission: SubmissionWTeam, db: Session = Depends(get_db)): + # Retrieves a list of submissions where the submission id and uuids match + submission_list: list[Submission] | None = crud_submission.read_all_W_filter( + db, submission_id=submission.submission_id, team_id_uuid=submission.team_id_uuid) + + if submission_list is None: + raise HTTPException(status_code=404, detail="Submission not found!") + + return submission_list[0] # returns a single SubmissionSchema to give the submission data to the user + + +@app.get('/get_submissions/{vid}', response_model=list[SubmissionSchema]) +def get_submissions(vid: int, db: Session = Depends(get_db)): + return crud_submission.read_all_by_team_id(db, vid) + + +# @app.get('/unis/', response_model=list[UniversityBase]) +# def get_unis(): diff --git a/server/models/submission.py b/server/models/submission.py index 4950701..3e32e75 100644 --- a/server/models/submission.py +++ b/server/models/submission.py @@ -14,4 +14,4 @@ class Submission(Base): file_txt: Mapped[str] = mapped_column(LargeBinary(), nullable=False) team: Mapped['Team'] = relationship(back_populates="submissions") - error: Mapped['Errors'] = relationship(back_populates='submission') + errors: Mapped[list['Errors']] = relationship(back_populates='submission') diff --git a/server/schemas/submission_schema.py b/server/schemas/submission_schema.py index 077815c..835c3c6 100644 --- a/server/schemas/submission_schema.py +++ b/server/schemas/submission_schema.py @@ -18,4 +18,4 @@ class SubmissionWTeam(SubmissionBase): class SubmissionSchema(SubmissionWTeam): team: team_schema.TeamBase - error: errors_schema.ErrorsWRun + errors: list[errors_schema.ErrorsWRun]