Tayori.Categories (Tayori v0.1.0)

Copy Markdown View Source

The categories of the news (Tayori.Category), in their order. The admin manages them; a script or a seed can too:

{:ok, _} = Tayori.Categories.create(%{"names" => %{"en" => "New"}, "color" => "blue"})

Summary

Functions

The categories by key, for rendering entries.

A changeset of a category, for a form.

Creates a category, at the end of the list.

Deletes a category, and takes it off the entries that have it.

A category by its key, or nil.

The categories, in their order.

Puts the categories in the order of the keys given.

Updates a category's names and colour. Its key stays.

Functions

by_key()

@spec by_key() :: %{required(String.t()) => Tayori.Category.t()}

The categories by key, for rendering entries.

change(category, attrs \\ %{})

@spec change(Tayori.Category.t(), map()) :: Ecto.Changeset.t()

A changeset of a category, for a form.

create(attrs)

@spec create(map()) :: {:ok, Tayori.Category.t()} | {:error, Ecto.Changeset.t()}

Creates a category, at the end of the list.

delete(category)

@spec delete(Tayori.Category.t()) ::
  {:ok, Tayori.Category.t()} | {:error, Ecto.Changeset.t()}

Deletes a category, and takes it off the entries that have it.

get(key)

@spec get(String.t()) :: Tayori.Category.t() | nil

A category by its key, or nil.

list()

@spec list() :: [Tayori.Category.t()]

The categories, in their order.

reorder(keys)

@spec reorder([String.t()]) :: :ok

Puts the categories in the order of the keys given.

update(category, attrs)

@spec update(Tayori.Category.t(), map()) ::
  {:ok, Tayori.Category.t()} | {:error, Ecto.Changeset.t()}

Updates a category's names and colour. Its key stays.