All methods are in the right class
This commit is contained in:
parent
0d541e82a5
commit
7f59443b64
12 changed files with 585 additions and 1729 deletions
|
@ -1,7 +1,11 @@
|
|||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import config
|
||||
import pendulum
|
||||
from exceptions import MissingProperty
|
||||
from pendulum import Date, Time
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from pydantic_extra_types.pendulum_dt import DateTime
|
||||
|
@ -84,6 +88,166 @@ class BookingPlatform(BaseModel):
|
|||
sports: list[Sport]
|
||||
urls: dict[str, Url]
|
||||
|
||||
def get_url_path(self, name: str) -> str:
|
||||
"""
|
||||
Get the URL path for the service with the given name
|
||||
|
||||
:param name: the name of the service
|
||||
:return: the URL path
|
||||
"""
|
||||
self.check_url_path_exists(name)
|
||||
|
||||
return urljoin(self.url, self.urls.get(name).path)
|
||||
|
||||
def get_payload_template(self, name: str) -> Path:
|
||||
"""
|
||||
Get the path to the template file for the service with the given name
|
||||
|
||||
:param name: the name of the service
|
||||
:return: the path to the template file
|
||||
"""
|
||||
self.check_payload_template_exists(name)
|
||||
|
||||
return config.get_resources_folder() / self.urls.get(name).payload_template
|
||||
|
||||
def get_url_parameter(self, name: str) -> str:
|
||||
self.check_url_path_exists(name)
|
||||
|
||||
return self.urls.get(name).parameter
|
||||
|
||||
def check_url_path_exists(self, name: str) -> None:
|
||||
"""
|
||||
Check that the URL path for the given service is defined
|
||||
|
||||
:param name: the name of the service
|
||||
"""
|
||||
if (
|
||||
self.urls is None
|
||||
or self.urls.get(name) is None
|
||||
or self.urls.get(name).path is None
|
||||
):
|
||||
raise MissingProperty(
|
||||
f"The booking platform internal URL path for page {name} are not set"
|
||||
)
|
||||
|
||||
def check_payload_template_exists(self, name: str) -> None:
|
||||
"""
|
||||
Check that the payload template for the given service is defined
|
||||
|
||||
:param name: the name of the service
|
||||
"""
|
||||
if (
|
||||
self.urls is None
|
||||
or self.urls.get(name) is None
|
||||
or self.urls.get(name).path is None
|
||||
):
|
||||
raise ValueError(
|
||||
f"The booking platform internal URL path for page {name} are not set"
|
||||
)
|
||||
|
||||
@property
|
||||
def landing_url(self) -> str:
|
||||
"""
|
||||
Get the URL to the landing page of Gestion-Sports
|
||||
|
||||
:return: the URL to the landing page
|
||||
"""
|
||||
return self.get_url_path("landing-page")
|
||||
|
||||
@property
|
||||
def login_url(self) -> str:
|
||||
"""
|
||||
Get the URL to the connection login of Gestion-Sports
|
||||
|
||||
:return: the URL to the login page
|
||||
"""
|
||||
return self.get_url_path("login")
|
||||
|
||||
@property
|
||||
def login_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to log in the website
|
||||
|
||||
:return: the payload template for logging in
|
||||
"""
|
||||
return self.get_payload_template("login")
|
||||
|
||||
@property
|
||||
def booking_url(self) -> str:
|
||||
"""
|
||||
Get the URL to the booking page of Gestion-Sports
|
||||
|
||||
:return: the URL to the booking page
|
||||
"""
|
||||
return self.get_url_path("booking")
|
||||
|
||||
@property
|
||||
def booking_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to book a court
|
||||
|
||||
:return: the payload template for booking a court
|
||||
"""
|
||||
return self.get_payload_template("booking")
|
||||
|
||||
@property
|
||||
def user_bookings_url(self) -> str:
|
||||
"""
|
||||
Get the URL where all the user's bookings are available
|
||||
|
||||
:return: the URL to the user's bookings
|
||||
"""
|
||||
return self.get_url_path("user-bookings")
|
||||
|
||||
@property
|
||||
def user_bookings_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to get all the user's bookings that are
|
||||
available
|
||||
|
||||
:return: the payload template for the user's bookings
|
||||
"""
|
||||
return self.get_payload_template("user-bookings")
|
||||
|
||||
@property
|
||||
def booking_cancellation_url(self) -> str:
|
||||
"""
|
||||
Get the URL where all the user's bookings are available
|
||||
|
||||
:return: the URL to the user's bookings
|
||||
"""
|
||||
return self.get_url_path("cancellation")
|
||||
|
||||
@property
|
||||
def booking_cancel_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to get all the user's bookings that are
|
||||
available
|
||||
|
||||
:return: the payload template for the user's bookings
|
||||
"""
|
||||
return self.get_payload_template("cancellation")
|
||||
|
||||
@property
|
||||
def tournaments_sessions_url(self) -> str:
|
||||
return self.get_url_path("tournament-sessions")
|
||||
|
||||
@property
|
||||
def tournaments_sessions_template(self) -> Path:
|
||||
return self.get_payload_template("tournament-sessions")
|
||||
|
||||
@property
|
||||
def tournaments_list_url(self) -> str:
|
||||
return self.get_url_path("tournaments-list")
|
||||
|
||||
@property
|
||||
def available_sports(self) -> dict[str, Sport]:
|
||||
"""
|
||||
Get a dictionary of all sports, the key is the sport name lowered case
|
||||
:return: the dictionary of all sports
|
||||
"""
|
||||
return {sport.name.lower(): sport for sport in self.sports}
|
||||
|
||||
|
||||
class Club(BaseModel):
|
||||
id: str
|
||||
|
@ -91,6 +255,109 @@ class Club(BaseModel):
|
|||
url: str
|
||||
booking_platform: BookingPlatform = Field(alias="bookingPlatform")
|
||||
|
||||
@property
|
||||
def landing_url(self) -> str:
|
||||
"""
|
||||
Get the URL to the landing page of Gestion-Sports
|
||||
|
||||
:return: the URL to the landing page
|
||||
"""
|
||||
return self.booking_platform.landing_url
|
||||
|
||||
@property
|
||||
def login_url(self) -> str:
|
||||
"""
|
||||
Get the URL to the connection login of Gestion-Sports
|
||||
|
||||
:return: the URL to the login page
|
||||
"""
|
||||
return self.booking_platform.login_url
|
||||
|
||||
@property
|
||||
def login_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to log in the website
|
||||
|
||||
:return: the payload template for logging in
|
||||
"""
|
||||
return self.booking_platform.login_template
|
||||
|
||||
@property
|
||||
def booking_url(self) -> str:
|
||||
"""
|
||||
Get the URL to the booking page of Gestion-Sports
|
||||
|
||||
:return: the URL to the booking page
|
||||
"""
|
||||
return self.booking_platform.booking_url
|
||||
|
||||
@property
|
||||
def booking_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to book a court
|
||||
|
||||
:return: the payload template for booking a court
|
||||
"""
|
||||
return self.booking_platform.booking_template
|
||||
|
||||
@property
|
||||
def user_bookings_url(self) -> str:
|
||||
"""
|
||||
Get the URL where all the user's bookings are available
|
||||
|
||||
:return: the URL to the user's bookings
|
||||
"""
|
||||
return self.booking_platform.user_bookings_url
|
||||
|
||||
@property
|
||||
def user_bookings_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to get all the user's bookings that are
|
||||
available
|
||||
|
||||
:return: the payload template for the user's bookings
|
||||
"""
|
||||
return self.booking_platform.user_bookings_template
|
||||
|
||||
@property
|
||||
def cancel_url(self) -> str:
|
||||
"""
|
||||
Get the URL where all the user's bookings are available
|
||||
|
||||
:return: the URL to the user's bookings
|
||||
"""
|
||||
return self.booking_platform.booking_cancellation_url
|
||||
|
||||
@property
|
||||
def cancel_template(self) -> Path:
|
||||
"""
|
||||
Get the payload template to send to get all the user's bookings that are
|
||||
available
|
||||
|
||||
:return: the payload template for the user's bookings
|
||||
"""
|
||||
return self.booking_platform.booking_cancel_template
|
||||
|
||||
@property
|
||||
def sessions_url(self) -> str:
|
||||
return self.booking_platform.tournaments_sessions_url
|
||||
|
||||
@property
|
||||
def sessions_template(self) -> Path:
|
||||
return self.booking_platform.tournaments_sessions_template
|
||||
|
||||
@property
|
||||
def tournaments_url(self) -> str:
|
||||
return self.booking_platform.tournaments_list_url
|
||||
|
||||
@property
|
||||
def sports(self) -> dict[str, Sport]:
|
||||
"""
|
||||
Get a dictionary of all sports, the key is the sport name lowered case
|
||||
:return: the dictionary of all sports
|
||||
"""
|
||||
return self.booking_platform.available_sports
|
||||
|
||||
|
||||
class PlatformDefinition(BaseModel):
|
||||
id: str
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue