34 lines
838 B
Elixir
34 lines
838 B
Elixir
defmodule Outlook.Artikel do
|
|
@moduledoc """
|
|
The Artikel context.
|
|
"""
|
|
|
|
alias Outlook.Translations.Translation
|
|
|
|
import Ecto.Query, warn: false
|
|
alias Outlook.Repo
|
|
|
|
def list_artikel do
|
|
Repo.all(from t in Translation, where: t.public == true)
|
|
|> Repo.preload([article: :author])
|
|
end
|
|
|
|
def get_artikel!(artikel) when is_struct(artikel), do: get_artikel!(artikel.id)
|
|
def get_artikel!(id) do
|
|
Repo.one(from t in Translation, where: t.id == ^id and t.public == true)
|
|
|> Repo.preload([article: :author])
|
|
end
|
|
|
|
def get_artikel_by_tid(tid) do
|
|
artikel = tid
|
|
|> String.split(~r/--(?=[0-9A-Za-z])/)
|
|
|> List.last()
|
|
|> String.to_integer(36)
|
|
|> get_artikel!()
|
|
case artikel do
|
|
%Translation{} -> {:ok, artikel}
|
|
_ -> {:error, "Artikel does not exist, or isn't public."}
|
|
end
|
|
end
|
|
end
|