View Source Teiserver.Communication.RoomLib (Teiserver v0.0.4)
Library of room related functions.
Summary
Functions
Returns an %Ecto.Changeset{}
for tracking room changes.
Creates a room.
Deletes a room.
Gets a room of a given name, if the room does not exist it is created.
Gets a single room.
Gets a single room.
Gets a single room by name or id (must be an integer).
Returns the list of rooms.
Updates a room.
Functions
@spec change_room(Teiserver.Communication.Room.t(), map()) :: Ecto.Changeset.t()
Returns an %Ecto.Changeset{}
for tracking room changes.
Examples
iex> change_room(room)
%Ecto.Changeset{data: %Room{}}
@spec create_room(map()) :: {:ok, Teiserver.Communication.Room.t()} | {:error, Ecto.Changeset.t()}
Creates a room.
Examples
iex> create_room(%{field: value})
{:ok, %Room{}}
iex> create_room(%{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec delete_room(Teiserver.Communication.Room.t()) :: {:ok, Teiserver.Communication.Room.t()} | {:error, Ecto.Changeset.t()}
Deletes a room.
Examples
iex> delete_room(room)
{:ok, %Room{}}
iex> delete_room(room)
{:error, %Ecto.Changeset{}}
@spec get_or_create_room(String.t()) :: Teiserver.Communication.Room.t()
Gets a room of a given name, if the room does not exist it is created.
Examples
iex> get_or_create_room("name")
%Room{}
iex> get_or_create_room("not a room"")
%Room{}
@spec get_room(Teiserver.Communication.Room.id(), Teiserver.query_args()) :: Teiserver.Communication.Room.t() | nil
Gets a single room.
Returns nil if the Room does not exist.
Examples
iex> get_room(123)
%Room{}
iex> get_room(456)
nil
@spec get_room!(Teiserver.Communication.Room.id(), Teiserver.query_args()) :: Teiserver.Communication.Room.t()
Gets a single room.
Raises Ecto.NoResultsError
if the Room does not exist.
Examples
iex> get_room!(123)
%Room{}
iex> get_room!(456)
** (Ecto.NoResultsError)
@spec get_room_by_name_or_id(String.t() | Teiserver.Communication.Room.id()) :: Teiserver.Communication.Room.t() | nil
Gets a single room by name or id (must be an integer).
Returns nil if the Room does not exist.
Examples
iex> get_room_by_name_or_id("main")
%Room{}
iex> get_room_by_name_or_id(123)
%Room{}
iex> get_room_by_name_or_id("not a name")
nil
iex> get_room_by_name_or_id(456)
nil
@spec list_rooms(Teiserver.query_args()) :: [Teiserver.Communication.Room.t()]
Returns the list of rooms.
Examples
iex> list_rooms()
[%Room{}, ...]
@spec update_room(Teiserver.Communication.Room.t(), map()) :: {:ok, Teiserver.Communication.Room.t()} | {:error, Ecto.Changeset.t()}
Updates a room.
Examples
iex> update_room(room, %{field: new_value})
{:ok, %Room{}}
iex> update_room(room, %{field: bad_value})
{:error, %Ecto.Changeset{}}