Skip to content

Commit

Permalink
bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NodeJSmith committed Jan 20, 2025
1 parent 34fb692 commit 7c2c751
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/otf_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def _check_for_booking_conflicts(self, otf_class: models.OtfClass) -> None:
booking_uuid=booking.booking_uuid,
)

def cancel_booking(self, booking: str | models.Booking):
def cancel_booking(self, booking: str | models.Booking) -> None:
"""Cancel a booking by providing either the booking_uuid or the Booking object.
Args:
Expand All @@ -434,8 +434,6 @@ def cancel_booking(self, booking: str | models.Booking):
f"Booking {booking_uuid} is already cancelled.", booking_uuid=booking_uuid
)

return

def get_bookings(
self,
start_date: date | str | None = None,
Expand Down Expand Up @@ -494,17 +492,17 @@ def get_bookings(

params = {"startDate": start_date, "endDate": end_date, "statuses": status_value}

bookings = self._default_request("GET", f"/member/members/{self.member_uuid}/bookings", params=params)["data"]
resp = self._default_request("GET", f"/member/members/{self.member_uuid}/bookings", params=params)["data"]

# add studio details for each booking, instead of using the different studio model returned by this endpoint
studio_uuids = {b["class"]["studio"]["studioUUId"] for b in bookings}
studio_uuids = {b["class"]["studio"]["studioUUId"] for b in resp}
studios = {studio_uuid: self.get_studio_detail(studio_uuid) for studio_uuid in studio_uuids}

for b in bookings:
for b in resp:
b["class"]["studio"] = studios[b["class"]["studio"]["studioUUId"]]
b["is_home_studio"] = b["class"]["studio"].studio_uuid == self.home_studio_uuid

bookings = [models.Booking(**b) for b in bookings]
bookings = [models.Booking(**b) for b in resp]
bookings = sorted(bookings, key=lambda x: x.otf_class.starts_at)

if exclude_cancelled:
Expand Down Expand Up @@ -721,15 +719,10 @@ def get_studio_detail(self, studio_uuid: str | None = None) -> models.StudioDeta
studio_uuid = studio_uuid or self.home_studio_uuid

path = f"/mobile/v1/studios/{studio_uuid}"
# params = {"include": "locations"}
params = {}

no_location_res = self._default_request("GET", path, params=params)
location_res = self._default_request("GET", path, params={"include": "locations"})

assert no_location_res["data"] == location_res["data"]
res = self._default_request("GET", path)

return models.StudioDetail(**location_res["data"])
return models.StudioDetail(**res["data"])

def get_studios_by_geo(
self, latitude: float | None = None, longitude: float | None = None
Expand Down

0 comments on commit 7c2c751

Please sign in to comment.