Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions app/core/tickets/cruds_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from app.core.tickets import models_tickets, schemas_tickets
from app.core.users import schemas_users
from app.types.exceptions import NoneResultWhenCountingDbError


async def get_all_events(db: AsyncSession) -> Sequence[schemas_tickets.EventSimple]:
Expand Down Expand Up @@ -711,7 +712,11 @@ async def count_tickets_by_event_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_tickets_by_category_id(
Expand All @@ -725,7 +730,11 @@ async def count_tickets_by_category_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_tickets_by_session_id(
Expand All @@ -739,7 +748,11 @@ async def count_tickets_by_session_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_valid_checkouts_by_event_id(
Expand All @@ -757,7 +770,11 @@ async def count_valid_checkouts_by_event_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_valid_checkouts_and_tickets_by_event_id(
Expand All @@ -777,7 +794,11 @@ async def count_valid_checkouts_and_tickets_by_event_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_valid_checkouts_and_tickets_by_session_id(
Expand All @@ -797,7 +818,11 @@ async def count_valid_checkouts_and_tickets_by_session_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_valid_checkouts_and_tickets_by_category_id(
Expand All @@ -817,7 +842,11 @@ async def count_valid_checkouts_and_tickets_by_category_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_valid_checkouts_by_category_id(
Expand All @@ -835,7 +864,11 @@ async def count_valid_checkouts_by_category_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_valid_checkouts_by_session_id(
Expand All @@ -853,7 +886,11 @@ async def count_valid_checkouts_by_session_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def count_answers_by_question_id(
Expand All @@ -866,7 +903,11 @@ async def count_answers_by_question_id(
),
)

return result.scalar() or 0
nb = result.scalar()
if nb is None:
raise NoneResultWhenCountingDbError()

return nb


async def update_event(
Expand Down
5 changes: 5 additions & 0 deletions app/types/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,8 @@ def __init__(self, object_name: str, object_id: str | UUID):
super().__init__(
f"Object {object_name} with id {object_id} was expected in database but not found",
)


class NoneResultWhenCountingDbError(Exception):
def __init__(self):
super().__init__("Counting rows in db should never return None")
Loading