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
| from datetime import datetime | |
| # Test doubles implement the same interfaces as production code | |
| class FakeBookingRepository(BookingRepository): | |
| """In-memory repository for testing - no HTTP, no database.""" | |
| def __init__(self): | |
| self._bookings: dict[str, Booking] = {} | |
| def find_by_id(self, booking_id: BookingId) -> Booking | None: | |
| return self._bookings.get(booking_id.value) |
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 |
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
| from dataclasses import dataclass | |
| from datetime import datetime | |
| from abc import ABC, abstractmethod | |
| # Domain command + IDs used at the boundary of the application layer | |
| @dataclass | |
| class BookingId: | |
| value: str | |
| @dataclass |
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
| from datetime import datetime | |
| # Test doubles implement the same interfaces as production code | |
| class FakeBookingRepository(BookingRepository): | |
| """In-memory repository for testing - no HTTP, no database.""" | |
| def __init__(self): | |
| self._bookings: dict[str, Booking] = {} | |
| def find_by_id(self, booking_id: BookingId) -> Booking | None: | |
| return self._bookings.get(booking_id.value) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 visible to application services | |
| from abc import ABC, abstractmethod | |
| from dataclasses import dataclass | |
| class PaymentAdapter(ABC): | |
| @abstractmethod | |
| async def charge(self, request: "PaymentRequest") -> "PaymentResult": | |
| pass | |
| # Domain-facing request/result types |
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 |
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
| from dataclasses import dataclass | |
| from datetime import datetime | |
| from abc import ABC, abstractmethod | |
| # Domain command + IDs used at the boundary of the application layer | |
| @dataclass | |
| class BookingId: | |
| value: str | |
| @dataclass |
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
| from datetime import datetime | |
| # Test doubles implement the same interfaces as production code | |
| class FakeBookingRepository(BookingRepository): | |
| """In-memory repository for testing - no HTTP, no database.""" | |
| def __init__(self): | |
| self._bookings: dict[str, Booking] = {} | |
| def find_by_id(self, booking_id: BookingId) -> Booking | None: | |
| return self._bookings.get(booking_id.value) |
NewerOlder