Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
omzetten vanuit DAO: basic get operaties die geen domeinmodellen teru…
Browse files Browse the repository at this point in the history
…ggeven #45
  • Loading branch information
lbarraga committed Mar 5, 2024
1 parent 28cdf58 commit a5e833d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions backend/domain/logic/basic_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import TypeVar, Type

from sqlalchemy import select
from sqlalchemy.orm import Session

from db.errors.database_errors import ItemNotFoundError
from db.models.models import AbstractModel

T = TypeVar("T", bound=AbstractModel)


def get(session: Session, object_type: Type, ident: int) -> T:
generic_object: T | None = session.get(object_type, ident)

if not generic_object:
msg = f"object with id {ident} not found"
raise ItemNotFoundError(msg)

return generic_object.to_domain_model()


def get_all(session: Session) -> list[T]:
return list(session.scalars(select(T)).all())

0 comments on commit a5e833d

Please sign in to comment.