PhoenixLiveCalendar.Store.EventStore behaviour (PhoenixLiveCalendar v0.1.0)

Copy Markdown View Source

Behaviour defining the data access interface for calendar events.

Implement this behaviour to provide custom persistence. A default Ecto implementation is provided in PhoenixLiveCalendar.Store.Ecto.EventStoreEcto.

Example custom implementation

defmodule MyApp.InMemoryEventStore do
  @behaviour PhoenixLiveCalendar.Store.EventStore

  @impl true
  def list_events(opts) do
    # Your custom implementation
  end

  @impl true
  def get_event(id, _opts) do
    # Your custom implementation
  end

  # ... etc
end

Configure your store:

config :phoenix_live_calendar, event_store: MyApp.InMemoryEventStore

Summary

Callbacks

Creates a new event. Returns {:ok, event} or {:error, changeset}.

Deletes an event by ID.

Fetches a single event by ID.

Lists events within a date range.

Updates an existing event.

Types

event_id()

@type event_id() :: term()

opts()

@type opts() :: keyword()

Callbacks

create_event(map, opts)

(optional)
@callback create_event(map(), opts()) ::
  {:ok, PhoenixLiveCalendar.Event.t()} | {:error, term()}

Creates a new event. Returns {:ok, event} or {:error, changeset}.

delete_event(event_id, opts)

(optional)
@callback delete_event(event_id(), opts()) :: :ok | {:error, term()}

Deletes an event by ID.

get_event(event_id, opts)

(optional)
@callback get_event(event_id(), opts()) :: PhoenixLiveCalendar.Event.t() | nil

Fetches a single event by ID.

list_events(opts)

@callback list_events(opts()) :: [PhoenixLiveCalendar.Event.t()]

Lists events within a date range.

Options

  • :start — Range start (Date or DateTime)
  • :end — Range end (Date or DateTime, exclusive)
  • :resource_id — Filter by resource
  • :calendar_id — Filter by calendar
  • :limit — Maximum events to return

update_event(event_id, map, opts)

(optional)
@callback update_event(event_id(), map(), opts()) ::
  {:ok, PhoenixLiveCalendar.Event.t()} | {:error, term()}

Updates an existing event.