Created
November 25, 2025 00:30
-
-
Save jakkaj/0bcb83ee43bd26034a94e039256d1ef7 to your computer and use it in GitHub Desktop.
[md-export] constitution-code-3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Interface lives in the application/domain module | |
| from abc import ABC, abstractmethod | |
| from typing import Optional | |
| import httpx | |
| class BookingRepository(ABC): | |
| @abstractmethod | |
| async def find_by_id(self, booking_id: BookingId) -> Optional["Booking"]: | |
| pass | |
| @abstractmethod | |
| async def save(self, booking: "Booking") -> None: | |
| pass | |
| # Implementation lives in an infrastructure module | |
| class HttpBookingRepository(BookingRepository): | |
| def __init__(self, client: httpx.AsyncClient): | |
| self._client = client | |
| async def find_by_id(self, booking_id: BookingId) -> Optional["Booking"]: | |
| response = await self._client.get( | |
| f"https://api.example.com/bookings/{booking_id.value}" | |
| ) | |
| if response.status_code == 404: | |
| return None | |
| # Map HTTP/JSON → domain | |
| return Booking.from_dict(response.json()) | |
| async def save(self, booking: "Booking") -> None: | |
| await self._client.post( | |
| "https://api.example.com/bookings", | |
| json=booking.to_dict(), | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment