Changed how services work and updated csv_import
This commit is contained in:
@@ -48,13 +48,14 @@ class ReservationService:
|
||||
return Reservation(**data)
|
||||
|
||||
async def create_reservation(
|
||||
self, reservation_data: ReservationData, customer_id: int
|
||||
self, reservation_data: ReservationData, customer_id: int, auto_commit: bool = True
|
||||
) -> Reservation:
|
||||
"""Create a new reservation.
|
||||
|
||||
Args:
|
||||
reservation_data: ReservationData containing reservation details
|
||||
customer_id: ID of the customer making the reservation
|
||||
auto_commit: If True, commits the transaction. If False, caller must commit.
|
||||
|
||||
Returns:
|
||||
Created Reservation instance
|
||||
@@ -63,8 +64,13 @@ class ReservationService:
|
||||
reservation_data, customer_id
|
||||
)
|
||||
self.session.add(reservation)
|
||||
await self.session.commit()
|
||||
await self.session.refresh(reservation)
|
||||
|
||||
if auto_commit:
|
||||
await self.session.commit()
|
||||
await self.session.refresh(reservation)
|
||||
else:
|
||||
await self.session.flush() # Flush to get the reservation.id
|
||||
|
||||
return reservation
|
||||
|
||||
async def get_reservation_by_unique_id(
|
||||
@@ -220,7 +226,7 @@ class ReservationService:
|
||||
]
|
||||
|
||||
async def record_acknowledgement(
|
||||
self, client_id: str, unique_id: str, username: Optional[str] = None
|
||||
self, client_id: str, unique_id: str, username: Optional[str] = None, auto_commit: bool = True
|
||||
) -> AckedRequest:
|
||||
"""Record that a client has acknowledged a reservation.
|
||||
|
||||
@@ -228,6 +234,7 @@ class ReservationService:
|
||||
client_id: The client ID
|
||||
unique_id: The unique_id of the reservation (md5_unique_id)
|
||||
username: The username of the client making the request (optional)
|
||||
auto_commit: If True, commits the transaction. If False, caller must commit.
|
||||
|
||||
Returns:
|
||||
Created AckedRequest instance
|
||||
@@ -239,8 +246,13 @@ class ReservationService:
|
||||
timestamp=datetime.now(UTC),
|
||||
)
|
||||
self.session.add(acked)
|
||||
await self.session.commit()
|
||||
await self.session.refresh(acked)
|
||||
|
||||
if auto_commit:
|
||||
await self.session.commit()
|
||||
await self.session.refresh(acked)
|
||||
else:
|
||||
await self.session.flush() # Flush to get the acked.id
|
||||
|
||||
return acked
|
||||
|
||||
async def is_acknowledged(self, unique_id: str, username: Optional[str] = None, client_id: Optional[str] = None) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user