Added reservation_service aswell
This commit is contained in:
@@ -32,6 +32,7 @@ from .db import Base, get_database_url
|
||||
from .db import Customer as DBCustomer
|
||||
from .db import Reservation as DBReservation
|
||||
from .logging_config import get_logger, setup_logging
|
||||
from .reservation_service import ReservationService
|
||||
from .rate_limit import (
|
||||
BURST_RATE_LIMIT,
|
||||
DEFAULT_RATE_LIMIT,
|
||||
@@ -305,22 +306,6 @@ async def health_check(request: Request):
|
||||
}
|
||||
|
||||
|
||||
def create_db_reservation_from_data(
|
||||
reservation_model: ReservationData, db_customer_id: int
|
||||
) -> DBReservation:
|
||||
"""Convert ReservationData to DBReservation, handling children_ages conversion."""
|
||||
data = reservation_model.model_dump(exclude_none=True)
|
||||
|
||||
children_list = data.pop("children_ages", [])
|
||||
children_csv = ",".join(str(int(a)) for a in children_list) if children_list else ""
|
||||
data["children_ages"] = children_csv
|
||||
|
||||
# Inject FK
|
||||
data["customer_id"] = db_customer_id
|
||||
|
||||
return DBReservation(**data)
|
||||
|
||||
|
||||
# Extracted business logic for handling Wix form submissions
|
||||
async def process_wix_form_submission(request: Request, data: dict[str, Any], db):
|
||||
"""Shared business logic for handling Wix form submissions (test and production)."""
|
||||
@@ -458,10 +443,11 @@ async def process_wix_form_submission(request: Request, data: dict[str, Any], db
|
||||
if reservation.md5_unique_id is None:
|
||||
raise HTTPException(status_code=400, detail="Failed to generate md5_unique_id")
|
||||
|
||||
db_reservation = create_db_reservation_from_data(reservation, db_customer.id)
|
||||
db.add(db_reservation)
|
||||
await db.commit()
|
||||
await db.refresh(db_reservation)
|
||||
# Use ReservationService to create reservation
|
||||
reservation_service = ReservationService(db)
|
||||
db_reservation = await reservation_service.create_reservation(
|
||||
reservation, db_customer.id
|
||||
)
|
||||
|
||||
async def push_event():
|
||||
# Fire event for listeners (push, etc.) - hotel-specific dispatch
|
||||
|
||||
Reference in New Issue
Block a user