~homeworkprod/byceps-bungalows

720c10ca9b7a57e747a5372c2c21f70a6573f21c — Jochen Kupperschmidt 2 months ago ed3659c
Fix return type hints
M byceps/services/bungalow/bungalow_occupancy_service.py => byceps/services/bungalow/bungalow_occupancy_service.py +19 -13
@@ 9,6 9,7 @@ byceps.services.bungalow.bungalow_occupancy_service
from __future__ import annotations

from collections import defaultdict
from collections.abc import Sequence
from datetime import datetime

from sqlalchemy import select


@@ 492,7 493,7 @@ def find_occupancy_managed_by_user(
    ).one_or_none()


def get_occupied_bungalows_for_party(party_id: PartyID) -> list[DbBungalow]:
def get_occupied_bungalows_for_party(party_id: PartyID) -> Sequence[DbBungalow]:
    """Return all occupied (but not reserved) bungalows for the party,
    ordered by number.
    """


@@ 518,22 519,27 @@ def get_occupied_bungalows_for_party(party_id: PartyID) -> list[DbBungalow]:

def get_occupied_bungalow_numbers_and_titles(
    party_id: PartyID,
) -> list[tuple[int, str]]:
) -> Sequence[tuple[int, str]]:
    """Return the numbers and titles of all occupied bungalows for the
    party, ordered by number.
    """
    return db.session.execute(
        select(
            DbBungalow.number,
            DbBungalowOccupancy.title,
        )
        .join(DbBungalowOccupancy)
        .filter(DbBungalow.party_id == party_id)
        .filter(
            DbBungalowOccupancy._state == BungalowOccupationState.occupied.name
    return (
        db.session.execute(
            select(
                DbBungalow.number,
                DbBungalowOccupancy.title,
            )
            .join(DbBungalowOccupancy)
            .filter(DbBungalow.party_id == party_id)
            .filter(
                DbBungalowOccupancy._state
                == BungalowOccupationState.occupied.name
            )
            .order_by(DbBungalow.number)
        )
        .order_by(DbBungalow.number)
    ).all()
        .tuples()
        .all()
    )


def has_user_occupied_any_bungalow(party_id: PartyID, user_id: UserID) -> bool:

M byceps/services/bungalow/bungalow_service.py => byceps/services/bungalow/bungalow_service.py +3 -1
@@ 8,6 8,8 @@ byceps.services.bungalow.bungalow_service

from __future__ import annotations

from collections.abc import Sequence

from sqlalchemy import select

from byceps.database import db, paginate, Pagination


@@ 130,7 132,7 @@ def get_bungalows_for_party(party_id: PartyID) -> list[DbBungalow]:
    ).all()


def get_bungalows_extended_for_party(party_id: PartyID) -> list[DbBungalow]:
def get_bungalows_extended_for_party(party_id: PartyID) -> Sequence[DbBungalow]:
    """Return all bungalows for the party, ordered by number."""
    return db.session.scalars(
        select(DbBungalow)