created a gestion sports services class that handles the connection while the connector is dedicated to the requests
This commit is contained in:
parent
bcd8dc0733
commit
e6023e0687
12 changed files with 513 additions and 593 deletions
|
@ -2,17 +2,12 @@ import asyncio
|
|||
import logging
|
||||
|
||||
import config
|
||||
from connectors import Connector, GestionSportsConnector
|
||||
from gestion_sports_services import GestionSportsServices
|
||||
from models import Action, BookingFilter, Club, Court, User
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_connector(club: Club) -> Connector:
|
||||
if club.booking_platform.id == "gestion-sports":
|
||||
return GestionSportsConnector(club)
|
||||
|
||||
|
||||
async def book_court(
|
||||
club: Club, users: list[User], booking_filter: BookingFilter
|
||||
) -> tuple[Court, User]:
|
||||
|
@ -26,10 +21,10 @@ async def book_court(
|
|||
:return: a tuple containing the court that was booked and the user who made the
|
||||
booking
|
||||
"""
|
||||
connector = get_connector(club)
|
||||
service = GestionSportsServices()
|
||||
for user in users:
|
||||
if not await connector.has_user_ongoing_booking(user):
|
||||
return await connector.book(user, booking_filter), user
|
||||
if not await service.has_user_available_slots(user, club):
|
||||
return await service.book(club, user, booking_filter), user
|
||||
|
||||
|
||||
async def cancel_booking(club: Club, user: User, booking_filter: BookingFilter) -> None:
|
||||
|
@ -40,8 +35,8 @@ async def cancel_booking(club: Club, user: User, booking_filter: BookingFilter)
|
|||
:param user: the user who made the booking
|
||||
:param booking_filter: the conditions to meet to cancel the booking
|
||||
"""
|
||||
connector = get_connector(club)
|
||||
await connector.cancel_booking(user, booking_filter)
|
||||
service = GestionSportsServices()
|
||||
await service.cancel_booking(user, club, booking_filter)
|
||||
|
||||
|
||||
async def cancel_booking_id(club: Club, user: User, booking_id: int) -> None:
|
||||
|
@ -52,8 +47,8 @@ async def cancel_booking_id(club: Club, user: User, booking_id: int) -> None:
|
|||
:param user: the user who made the booking
|
||||
:param booking_id: the id of the booking to cancel
|
||||
"""
|
||||
connector = get_connector(club)
|
||||
await connector.cancel_booking_id(user, booking_id)
|
||||
service = GestionSportsServices()
|
||||
await service.cancel_booking_id(user, club, booking_id)
|
||||
|
||||
|
||||
def main() -> tuple[Court, User] | None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue