Choose a user with booking availability among many

This commit is contained in:
Stanislas Jouffroy 2024-03-05 00:24:28 +01:00
parent a8322d6be0
commit 559c3b6d69
18 changed files with 1810 additions and 147 deletions

View file

@ -1,23 +1,48 @@
from exceptions import ArgumentMissing
from gestion_sports.gestion_sports_config import BOOKING_TEMPLATE, LOGIN_TEMPLATE
from gestion_sports.gestion_sports_config import (
BOOKING_TEMPLATE,
LOGIN_TEMPLATE,
USERS_BOOKINGS_TEMPLATE,
)
from jinja2 import Environment, FileSystemLoader
from models import BookingFilter, Club, User
class GestionSportsLoginPayloadBuilder:
"""
Build the payload for the login page
"""
def __init__(self):
self._user: User | None = None
self._club: Club | None = None
def user(self, user: User):
"""
Set the user
:param user: the user
:return: the class itself
"""
self._user = user
return self
def club(self, club: Club):
"""
Set the club
:param club: the club
:return: the class itself
"""
self._club = club
return self
def build(self):
def build(self) -> str:
"""
Build the payload
:return: the string representation of the payload
"""
if self._user is None:
raise ArgumentMissing("No user was provided")
if self._club is None:
@ -35,14 +60,31 @@ class GestionSportsBookingPayloadBuilder:
self._court_id: int | None = None
def booking_filter(self, booking_filter: BookingFilter):
"""
Set the booking filter
:param booking_filter: the booking filter
:return: the class itself
"""
self._booking_filter = booking_filter
return self
def court_id(self, court_id: int):
"""
Set the court id
:param court_id: the court id
:return: the class itself
"""
self._court_id = court_id
return self
def build(self):
def build(self) -> str:
"""
Build the payload
:return: the string representation of the payload
"""
if self._booking_filter is None:
raise ArgumentMissing("No booking filter was provided")
if self.court_id is None:
@ -54,3 +96,33 @@ class GestionSportsBookingPayloadBuilder:
return template.render(
court_id=self._court_id, booking_filter=self._booking_filter
)
class GestionSportsUsersBookingsPayloadBuilder:
def __init__(self):
self._hash: str | None = None
def hash(self, hash_value: str):
"""
Set the hash
:param hash_value: the hash
:return: the class itself
"""
self._hash = hash_value
def build(self) -> str:
"""
Build the payload
:return: the string representation of the payload
"""
if self._hash is None:
raise ArgumentMissing("No hash was provided")
environment = Environment(
loader=FileSystemLoader(USERS_BOOKINGS_TEMPLATE.parent)
)
template = environment.get_template(USERS_BOOKINGS_TEMPLATE.name)
return template.render(hash=self._hash)