Skip to content

codex_services.booking._shared.dto

dto

codex_services.booking._shared.dto

Base DTOs shared across all booking types.

Each booking type (slot_master, room, etc.) inherits from these and adds domain-specific fields.

Classes

ResourceAvailability

Bases: BaseDTO

Base availability of a resource (executor, room, equipment, etc.).

Fields

resource_id (str): Unique identifier of the resource. free_windows (list[tuple[datetime, datetime]]): Available time windows. Each tuple is (start, end) where start < end.

Source code in src/codex_services/booking/_shared/dto.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ResourceAvailability(BaseDTO):
    """
    Base availability of a resource (executor, room, equipment, etc.).

    Fields:
        resource_id (str): Unique identifier of the resource.
        free_windows (list[tuple[datetime, datetime]]): Available time windows.
            Each tuple is (start, end) where start < end.
    """

    resource_id: str
    free_windows: list[tuple[datetime, datetime]] = Field(default_factory=list)

    @model_validator(mode="after")
    def validate_windows_order(self) -> "ResourceAvailability":
        """Validate that each free window is chronologically correct."""
        for start, end in self.free_windows:
            if start >= end:
                raise ValueError(f"Resource {self.resource_id}: start={start} >= end={end}")
        return self

    def __repr__(self) -> str:
        return f"<ResourceAvailability resource={self.resource_id} windows={len(self.free_windows)}>"
Functions
validate_windows_order()

Validate that each free window is chronologically correct.

Source code in src/codex_services/booking/_shared/dto.py
29
30
31
32
33
34
35
@model_validator(mode="after")
def validate_windows_order(self) -> "ResourceAvailability":
    """Validate that each free window is chronologically correct."""
    for start, end in self.free_windows:
        if start >= end:
            raise ValueError(f"Resource {self.resource_id}: start={start} >= end={end}")
    return self

BookingRequest

Bases: BaseDTO

Base booking request.

Fields

booking_date (date): Target date for the booking.

Source code in src/codex_services/booking/_shared/dto.py
41
42
43
44
45
46
47
48
49
class BookingRequest(BaseDTO):
    """
    Base booking request.

    Fields:
        booking_date (date): Target date for the booking.
    """

    booking_date: date

BookingSolution

Bases: BaseDTO

Base result — one booked slot.

Fields

resource_id (str): Assigned resource identifier. start_time (datetime): Scheduled start time. end_time (datetime): Scheduled end time.

Source code in src/codex_services/booking/_shared/dto.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class BookingSolution(BaseDTO):
    """
    Base result — one booked slot.

    Fields:
        resource_id (str): Assigned resource identifier.
        start_time (datetime): Scheduled start time.
        end_time (datetime): Scheduled end time.
    """

    resource_id: str
    start_time: datetime
    end_time: datetime

    @property
    def duration_minutes(self) -> int:
        """Calculate actual duration in minutes."""
        return int((self.end_time - self.start_time).total_seconds() / 60)
Attributes
duration_minutes property

Calculate actual duration in minutes.

BookingResult

Bases: BaseDTO

Base result — list of solutions.

Concrete booking types override the solutions field with a specific type.

Source code in src/codex_services/booking/_shared/dto.py
72
73
74
75
76
77
78
79
80
81
82
class BookingResult(BaseDTO):
    """
    Base result — list of solutions.

    Concrete booking types override the `solutions` field with a specific type.
    """

    @property
    def has_solutions(self) -> bool:
        """Return True if at least one solution was found."""
        raise NotImplementedError("Subclasses must implement has_solutions")
Attributes
has_solutions property

Return True if at least one solution was found.