New system for acknowledgments

This commit is contained in:
Jonas Linter
2025-11-13 16:23:09 +01:00
parent 189e44a7ff
commit 0ba70550c9
6 changed files with 144 additions and 22 deletions

View File

@@ -172,28 +172,39 @@ class ReservationService:
async def get_unacknowledged_reservations(
self,
client_id: str,
start_date: Optional[datetime] = None,
end_date: Optional[datetime] = None,
hotel_code: Optional[str] = None,
username: Optional[str] = None,
client_id: Optional[str] = None,
) -> list[tuple[Reservation, Customer]]:
"""Get reservations that haven't been acknowledged by a client.
Prioritizes checking by username if provided, falls back to client_id for backward compatibility.
Args:
client_id: The client ID to check acknowledgements for
start_date: Filter by start date >= this value
end_date: Filter by end date <= this value
hotel_code: Filter by hotel code
username: The username of the client (preferred for lookup)
client_id: The client ID (fallback for backward compatibility)
Returns:
List of (Reservation, Customer) tuples that are unacknowledged
"""
# Get all acknowledged md5_unique_ids for this client
acked_result = await self.session.execute(
select(AckedRequest.unique_id).where(
AckedRequest.client_id == client_id
# Get all acknowledged unique_ids for this client/username
if username:
acked_result = await self.session.execute(
select(AckedRequest.unique_id).where(
AckedRequest.username == username
)
)
else:
acked_result = await self.session.execute(
select(AckedRequest.unique_id).where(
AckedRequest.client_id == client_id
)
)
)
acked_md5_ids = {row[0] for row in acked_result.all()}
# Get all reservations with filters
@@ -209,19 +220,21 @@ class ReservationService:
]
async def record_acknowledgement(
self, client_id: str, unique_id: str
self, client_id: str, unique_id: str, username: Optional[str] = None
) -> AckedRequest:
"""Record that a client has acknowledged a reservation.
Args:
client_id: The client ID
unique_id: The unique_id of the reservation
unique_id: The unique_id of the reservation (md5_unique_id)
username: The username of the client making the request (optional)
Returns:
Created AckedRequest instance
"""
acked = AckedRequest(
client_id=client_id,
username=username,
unique_id=unique_id,
timestamp=datetime.now(UTC),
)
@@ -230,24 +243,37 @@ class ReservationService:
await self.session.refresh(acked)
return acked
async def is_acknowledged(self, client_id: str, unique_id: str) -> bool:
async def is_acknowledged(self, unique_id: str, username: Optional[str] = None, client_id: Optional[str] = None) -> bool:
"""Check if a reservation has been acknowledged by a client.
Prioritizes checking by username if provided, falls back to client_id for backward compatibility.
Args:
client_id: The client ID
unique_id: The reservation unique_id
username: The username of the client (preferred for lookup)
client_id: The client ID (fallback for backward compatibility)
Returns:
True if acknowledged, False otherwise
"""
result = await self.session.execute(
select(AckedRequest).where(
and_(
AckedRequest.client_id == client_id,
AckedRequest.unique_id == unique_id,
if username:
result = await self.session.execute(
select(AckedRequest).where(
and_(
AckedRequest.username == username,
AckedRequest.unique_id == unique_id,
)
)
)
else:
result = await self.session.execute(
select(AckedRequest).where(
and_(
AckedRequest.client_id == client_id,
AckedRequest.unique_id == unique_id,
)
)
)
)
return result.scalar_one_or_none() is not None
@staticmethod