Skip to content

Commit

Permalink
group_run (#112)
Browse files Browse the repository at this point in the history
* fixed crud error stuff

* group run

* group_run

* fixed stuff
  • Loading branch information
JuliaCaesar authored Oct 7, 2023
1 parent 3886e4b commit e4b6437
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 8 deletions.
18 changes: 14 additions & 4 deletions server/crud/crud_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
55 changes: 55 additions & 0 deletions server/crud/crud_group_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 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())
if db_group_run is None:
return

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, group_run: 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()
6 changes: 6 additions & 0 deletions server/crud/crud_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions server/models/group_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from sqlalchemy.orm import relationship, Mapped, mapped_column

from .base import Base
from .run import Run


class GroupRun(Base):
Expand All @@ -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')
8 changes: 8 additions & 0 deletions server/schemas/errors_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion server/schemas/run_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
2 changes: 1 addition & 1 deletion server/schemas/submission_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class SubmissionWTeam(SubmissionBase):

class SubmissionSchema(SubmissionWTeam):
team: team_schema.TeamBase
error: errors_schema.ErrorsBase
error: errors_schema.ErrorsWRun

0 comments on commit e4b6437

Please sign in to comment.