ExBooking. Resource
(ExBooking v0.2.1)
View Source
A bookable resource.
A resource is usually a bookable person, but can also represent a pooled seat. Busy intervals, booking reservations, daily booking counts, capacity, and fairness counters are explicit inputs maintained by the consuming application, which keeps assignment stateless and repeatable.
Example
iex> resource = %ExBooking.Resource{id: "resource_1", timezone: "Etc/UTC", capacity: 2}
...> {resource.id, resource.capacity}
{"resource_1", 2}
Summary
Functions
Validates optional fairness fields without interpreting an assignment strategy.
Rejects repeated ids in an already validated resource list.
Types
@type fairness() :: %{ optional(:assignments_count) => non_neg_integer(), optional(:last_assigned_at) => DateTime.t() | nil, optional(:weight) => number(), optional(:priority) => integer() }
Explicit fairness inputs for assignment strategies.
@type t() :: %ExBooking.Resource{ busy: [ExBooking.Interval.t()], capacity: pos_integer(), daily_booking_counts: %{optional(Date.t()) => non_neg_integer()}, fairness: fairness() | nil, id: String.t(), meta: map() | nil, reservations: [ExBooking.Reservation.t()], timezone: String.t() }
A bookable resource.
Functions
@spec validate_fairness(String.t(), term()) :: :ok | {:error, {:invalid, :resource_fairness, {String.t(), term()}}}
Validates optional fairness fields without interpreting an assignment strategy.
Examples
iex> ExBooking.Resource.validate_fairness("a", %{assignments_count: 0})
:ok
iex> ExBooking.Resource.validate_fairness("a", %{weight: 0})
{:error, {:invalid, :resource_fairness, {"a", {:weight, 0}}}}
Rejects repeated ids in an already validated resource list.
Examples
iex> resource = %ExBooking.Resource{id: "a", timezone: "Etc/UTC"}
...> ExBooking.Resource.validate_ids([resource, resource])
{:error, {:invalid, :resource_id, {:duplicate, "a"}}}