From 4448220e872fb3bd44f30d876e973a79bb99f31d Mon Sep 17 00:00:00 2001 From: JuliaCaesar Date: Fri, 6 Oct 2023 22:01:29 -0500 Subject: [PATCH 1/4] fixed crud error stuff --- server/crud/crud_group_run.py | 50 +++++++++++++++++++++++++++++ server/schemas/errors_schema.py | 8 +++++ server/schemas/run_schema.py | 2 +- server/schemas/submission_schema.py | 2 +- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/server/crud/crud_group_run.py b/server/crud/crud_group_run.py index e69de29..d73be04 100644 --- a/server/crud/crud_group_run.py +++ b/server/crud/crud_group_run.py @@ -0,0 +1,50 @@ +# import uuid +# from typing import Type +# +# from sqlalchemy.orm import Session +# from sqlalchemy import and_ +# +# from server.models.group_run import GroupRun +# from server.schemas.group_run_schema import GroupRunSchema, GroupRunBase +# +# +# def create(db: Session, group_run: GroupRunBase) -> GroupRun: +# db_group_run: GroupRun = GroupRun(**group_run.model_dump(exclude={'group_run_id'})) +# db.add(db_group_run) +# db.commit() +# db.refresh(db_group_run) +# return db_group_run +# +# +# def read(db: Session, id: int) -> GroupRun | None: +# return (db.query(GroupRun) +# .filter(GroupRun.group_run_id == id) +# .first()) +# +# +# def update(db: Session, id: int, group_run: GroupRunBase) -> GroupRun | None: +# db_group_run: GroupRun | None = (db.query(GroupRun) +# .filter(and_(GroupRun.group_run_id == id, +# GroupRun.is_finished == group_run.is_finished)) +# .one_or_none()) +# if db_group_run is None: +# return +# +# for group_run.is_finished, value in group_run.model_dump().items(): +# setattr(db_group_run, group_run.is_finished, True) if value is else False +# +# db.commit() +# db.refresh(db_submission) +# return db_submission +# +# +# def delete(db: Session, id: int, submission: SubmissionWTeam) -> None: +# db_submission: Submission | None = (db.query(Submission) +# .filter(and_(Submission.submission_id == id, +# Submission.team_id_uuid == submission.team_id_uuid)) +# .one_or_none()) +# if db_submission is None: +# return +# +# db.delete(db_submission) +# db.commit() diff --git a/server/schemas/errors_schema.py b/server/schemas/errors_schema.py index 6522a9e..f0a3848 100644 --- a/server/schemas/errors_schema.py +++ b/server/schemas/errors_schema.py @@ -13,6 +13,14 @@ class Config: from_attributes = True +class ErrorsWRun(ErrorsBase): + run: run_schema.RunBase + + +class ErrorsWSubmission(ErrorsBase): + submission: submission_schema.SubmissionBase + + class ErrorsSchema(ErrorsBase): run: run_schema.RunBase submission: submission_schema.SubmissionBase diff --git a/server/schemas/run_schema.py b/server/schemas/run_schema.py index cfecd24..e0de6bb 100644 --- a/server/schemas/run_schema.py +++ b/server/schemas/run_schema.py @@ -18,5 +18,5 @@ class Config: class RunSchema(RunBase): group_run: group_run_schema.GroupRunBase - errors: errors_schema.ErrorsBase + errors: errors_schema.ErrorsWSubmission turn_tables: list[turn_table_schema.TurnTableBase] = [] diff --git a/server/schemas/submission_schema.py b/server/schemas/submission_schema.py index f2dbffa..077815c 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.ErrorsBase + error: errors_schema.ErrorsWRun From b3bd85e4b1eb785225417820a113b179725fbd2a Mon Sep 17 00:00:00 2001 From: JuliaCaesar Date: Fri, 6 Oct 2023 22:26:14 -0500 Subject: [PATCH 2/4] group run --- server/crud/crud_group_run.py | 97 +++++++++++++++++------------------ 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/server/crud/crud_group_run.py b/server/crud/crud_group_run.py index d73be04..df7288b 100644 --- a/server/crud/crud_group_run.py +++ b/server/crud/crud_group_run.py @@ -1,50 +1,47 @@ -# import uuid -# from typing import Type -# -# from sqlalchemy.orm import Session -# from sqlalchemy import and_ -# -# from server.models.group_run import GroupRun -# from server.schemas.group_run_schema import GroupRunSchema, GroupRunBase -# -# -# def create(db: Session, group_run: GroupRunBase) -> GroupRun: -# db_group_run: GroupRun = GroupRun(**group_run.model_dump(exclude={'group_run_id'})) -# db.add(db_group_run) -# db.commit() -# db.refresh(db_group_run) -# return db_group_run -# -# -# def read(db: Session, id: int) -> GroupRun | None: -# return (db.query(GroupRun) -# .filter(GroupRun.group_run_id == id) -# .first()) -# -# -# def update(db: Session, id: int, group_run: GroupRunBase) -> GroupRun | None: -# db_group_run: GroupRun | None = (db.query(GroupRun) -# .filter(and_(GroupRun.group_run_id == id, -# GroupRun.is_finished == group_run.is_finished)) -# .one_or_none()) -# if db_group_run is None: -# return -# -# for group_run.is_finished, value in group_run.model_dump().items(): -# setattr(db_group_run, group_run.is_finished, True) if value is else False -# -# db.commit() -# db.refresh(db_submission) -# return db_submission -# -# -# def delete(db: Session, id: int, submission: SubmissionWTeam) -> None: -# db_submission: Submission | None = (db.query(Submission) -# .filter(and_(Submission.submission_id == id, -# Submission.team_id_uuid == submission.team_id_uuid)) -# .one_or_none()) -# if db_submission is None: -# return -# -# db.delete(db_submission) -# db.commit() + +from sqlalchemy.orm import Session +from sqlalchemy import and_ + +from server.models.group_run import GroupRun +from server.schemas.group_run_schema import GroupRunSchema, GroupRunBase + + +def create(db: Session, group_run: GroupRunBase) -> GroupRun: + db_group_run: GroupRun = GroupRun(**group_run.model_dump(exclude={'group_run_id'})) + db.add(db_group_run) + db.commit() + db.refresh(db_group_run) + return db_group_run + + +def read(db: Session, id: int) -> GroupRun | None: + return (db.query(GroupRun) + .filter(GroupRun.group_run_id == id) + .first()) + + +def update(db: Session, id: int, group_run: GroupRunBase) -> GroupRun | None: + db_group_run: GroupRun | None = (db.query(GroupRun) + .filter(and_(GroupRun.group_run_id == id, + GroupRun.is_finished == group_run.is_finished)) + .one_or_none()) + if db_group_run is None: + return + + for group_run.is_finished, group_run_id in group_run.model_dump().items(): + setattr(db_group_run, group_run.is_finished, True) if group_run_id == group_run_id else False + + db.commit() + db.refresh(db_group_run) + return db_group_run + + +def delete(db: Session, id: int, submission: GroupRunBase) -> None: + db_group_run: GroupRun | None = (db.query(GroupRun) + .filter(GroupRun.group_run_id == id) + .one_or_none()) + if db_group_run is None: + return + + db.delete(db_group_run) + db.commit() From 7a5b2c54a0026235fc1f78aff8bc22166c389634 Mon Sep 17 00:00:00 2001 From: JuliaCaesar Date: Fri, 6 Oct 2023 22:41:36 -0500 Subject: [PATCH 3/4] group_run --- server/crud/crud_group_run.py | 9 ++++----- server/models/group_run.py | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/server/crud/crud_group_run.py b/server/crud/crud_group_run.py index df7288b..e989df8 100644 --- a/server/crud/crud_group_run.py +++ b/server/crud/crud_group_run.py @@ -22,21 +22,20 @@ def read(db: Session, id: int) -> GroupRun | None: def update(db: Session, id: int, group_run: GroupRunBase) -> GroupRun | None: db_group_run: GroupRun | None = (db.query(GroupRun) - .filter(and_(GroupRun.group_run_id == id, - GroupRun.is_finished == group_run.is_finished)) + .filter(GroupRun.group_run_id == id) .one_or_none()) if db_group_run is None: return - for group_run.is_finished, group_run_id in group_run.model_dump().items(): - setattr(db_group_run, group_run.is_finished, True) if group_run_id == group_run_id else False + for key, value in group_run.model_dump().items(): + setattr(db_group_run, key, value) if value is not None else None db.commit() db.refresh(db_group_run) return db_group_run -def delete(db: Session, id: int, submission: GroupRunBase) -> None: +def delete(db: Session, id: int, group_run: GroupRunBase) -> None: db_group_run: GroupRun | None = (db.query(GroupRun) .filter(GroupRun.group_run_id == id) .one_or_none()) diff --git a/server/models/group_run.py b/server/models/group_run.py index 89bdc31..a872631 100644 --- a/server/models/group_run.py +++ b/server/models/group_run.py @@ -4,7 +4,6 @@ from sqlalchemy.orm import relationship, Mapped, mapped_column from .base import Base -from .run import Run class GroupRun(Base): @@ -15,4 +14,4 @@ class GroupRun(Base): launcher_version: Mapped[str] = mapped_column(String(10), nullable=False) runs_per_client: Mapped[int] = mapped_column(Integer(), nullable=False) is_finished: Mapped[bool] = mapped_column(Boolean(), default=False, nullable=False) - runs: Mapped[list[Run]] = relationship(back_populates='group_run') + runs: Mapped[list['Run']] = relationship(back_populates='group_run') From aa320d3d42710913bf36de1c5371bae570519db6 Mon Sep 17 00:00:00 2001 From: JuliaCaesar Date: Fri, 6 Oct 2023 23:05:32 -0500 Subject: [PATCH 4/4] fixed stuff --- server/crud/crud_errors.py | 18 ++++++++++++++---- server/crud/crud_group_run.py | 19 ++++++++++++++----- server/crud/crud_submission.py | 6 ++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/server/crud/crud_errors.py b/server/crud/crud_errors.py index 776e93d..9ee4937 100644 --- a/server/crud/crud_errors.py +++ b/server/crud/crud_errors.py @@ -22,10 +22,20 @@ def read(db: Session, id: int) -> Errors | None: .first()) +def read_all(db: Session) -> [Errors]: + return db.query(Errors).all() + + +def read_all_W_filter(db: Session, **kwargs) -> [Errors]: + return (db.query(Errors) + .filter_by(**kwargs) + .all()) + + def update(db: Session, id: int, errors: ErrorsBase) -> Errors | None: db_errors: Errors | None = (db.query(Errors) - .filter(Errors.error_id == id) - .one_or_none()) + .filter(Errors.error_id == id) + .one_or_none()) if db_errors is None: return @@ -39,8 +49,8 @@ def update(db: Session, id: int, errors: ErrorsBase) -> Errors | None: def delete(db: Session, id: int, errors: ErrorsBase) -> None: db_errors: Errors | None = (db.query(Errors) - .filter(Errors.error_id == id) - .one_or_none()) + .filter(Errors.error_id == id) + .one_or_none()) if db_errors is None: return diff --git a/server/crud/crud_group_run.py b/server/crud/crud_group_run.py index e989df8..c4c5e19 100644 --- a/server/crud/crud_group_run.py +++ b/server/crud/crud_group_run.py @@ -1,4 +1,3 @@ - from sqlalchemy.orm import Session from sqlalchemy import and_ @@ -20,10 +19,20 @@ def read(db: Session, id: int) -> GroupRun | None: .first()) +def read_all(db: Session) -> [GroupRun]: + return db.query(GroupRun).all() + + +def read_all_W_filter(db: Session, **kwargs) -> [GroupRun]: + return (db.query(GroupRun) + .filter_by(**kwargs) + .all()) + + def update(db: Session, id: int, group_run: GroupRunBase) -> GroupRun | None: db_group_run: GroupRun | None = (db.query(GroupRun) - .filter(GroupRun.group_run_id == id) - .one_or_none()) + .filter(GroupRun.group_run_id == id) + .one_or_none()) if db_group_run is None: return @@ -37,8 +46,8 @@ def update(db: Session, id: int, group_run: GroupRunBase) -> GroupRun | None: def delete(db: Session, id: int, group_run: GroupRunBase) -> None: db_group_run: GroupRun | None = (db.query(GroupRun) - .filter(GroupRun.group_run_id == id) - .one_or_none()) + .filter(GroupRun.group_run_id == id) + .one_or_none()) if db_group_run is None: return diff --git a/server/crud/crud_submission.py b/server/crud/crud_submission.py index 8dafe97..ea10805 100644 --- a/server/crud/crud_submission.py +++ b/server/crud/crud_submission.py @@ -28,6 +28,12 @@ def read_all_by_team_id(db: Session, team_uuid: uuid) -> list[Type[Submission]]: .all()) +def read_all_W_filter(db: Session, **kwargs) -> [Submission]: + return (db.query(Submission) + .filter_by(**kwargs) + .all()) + + def update(db: Session, id: int, submission: SubmissionWTeam) -> Submission | None: db_submission: Submission | None = (db.query(Submission) .filter(and_(Submission.submission_id == id,