resa-padel/resa_padel/booking.py

48 lines
1.4 KiB
Python

import asyncio
import logging
import config
from gestion_sports.gestion_sports_operations import GestionSportsOperations
from models import BookingFilter, Club, User
LOGGER = logging.getLogger(__name__)
async def book(club: Club, user: User, booking_filter: BookingFilter) -> int | None:
"""
Book a court for a user to a club following a booking filter
:param club: the club where to book a court
:param user: the user information
:param booking_filter: the information related to the booking
:return: the id of the booked court, or None if no court was booked
"""
async with GestionSportsOperations(club) as platform:
return await platform.book(user, booking_filter)
def main() -> int | None:
"""
Main function used to book a court
:return: the id of the booked court, or None if no court was booked
"""
user = config.get_user()
booking_filter = config.get_booking_filter()
club = config.get_club()
LOGGER.info(
"Starting booking court of %s for user %s at club %s at %s",
booking_filter.sport_id,
user.login,
club.id,
booking_filter.date,
)
court_booked = asyncio.run(book(club, user, booking_filter))
if court_booked:
LOGGER.info(
"Court %s booked successfully at %s", court_booked, booking_filter.date
)
else:
LOGGER.info("Booking did not work")
return court_booked