~homeworkprod/byceps

7d53072ee4883f70b04658c43af5a1cdd66101eb — Jochen Kupperschmidt a month ago 39776cb
Introduce `get_seat`
M byceps/blueprints/admin/ticketing/service.py => byceps/blueprints/admin/ticketing/service.py +3 -3
@@ 150,12 150,12 @@ def _get_additional_data_for_seat_occupied_event(
    event: TicketEvent,
) -> Iterator[tuple[str, Any]]:
    seat_id = event.data['seat_id']
    seat = seat_service.find_seat(seat_id)
    seat = seat_service.get_seat(seat_id)
    yield 'seat_label', seat.label

    previous_seat_id = event.data.get('previous_seat_id')
    if previous_seat_id:
        previous_seat = seat_service.find_seat(previous_seat_id)
        previous_seat = seat_service.get_seat(previous_seat_id)
        yield 'previous_seat_label', previous_seat.label




@@ 164,7 164,7 @@ def _get_additional_data_for_seat_released_event(
) -> Iterator[tuple[str, Any]]:
    seat_id = event.data.get('seat_id')
    if seat_id:
        seat = seat_service.find_seat(seat_id)
        seat = seat_service.get_seat(seat_id)
        yield 'seat_label', seat.label



M byceps/services/seating/seat_service.py => byceps/services/seating/seat_service.py +10 -0
@@ 116,6 116,16 @@ def find_seat(seat_id: SeatID) -> Optional[DbSeat]:
    return DbSeat.query.get(seat_id)


def get_seat(seat_id: SeatID) -> DbSeat:
    """Return the seat with that id, or raise an exception."""
    seat = find_seat(seat_id)

    if seat is None:
        raise ValueError(f'Unknown seat ID "{seat_id}"')

    return seat


def find_seats(seat_ids: set[SeatID]) -> set[DbSeat]:
    """Return the seats with those IDs."""
    if not seat_ids:

M byceps/services/ticketing/ticket_seat_management_service.py => byceps/services/ticketing/ticket_seat_management_service.py +1 -3
@@ 74,9 74,7 @@ def occupy_seat(

    _deny_seat_management_if_ticket_belongs_to_bundle(ticket)

    seat = seat_service.find_seat(seat_id)
    if seat is None:
        raise ValueError('Invalid seat ID')
    seat = seat_service.get_seat(seat_id)

    if seat.category_id != ticket.category_id:
        raise TicketCategoryMismatch(