diff --git a/lib/outlook/autoren.ex b/lib/outlook/autoren.ex deleted file mode 100644 index f73ced7..0000000 --- a/lib/outlook/autoren.ex +++ /dev/null @@ -1,34 +0,0 @@ -defmodule Outlook.Autoren do - @moduledoc """ - The Autoren context. - """ - - import Ecto.Query, warn: false - alias Outlook.Repo - - alias Outlook.Articles.Article - alias Outlook.Translations.Translation - - alias Outlook.Authors.Author - - def list_autoren do - Repo.all(Author) - end - - def get_autor!(id) do - Repo.get!(Author, id) - |> Repo.preload([articles: [:translations]]) - end - - @doc "This is ugly" - def list_artikel(author) when is_struct(author), do: list_artikel(author.id) - def list_artikel(author_id) do - aids = Repo.all(from a in Article, - select: [:id], - where: a.author_id == ^author_id) - |> Enum.map(fn a -> a.id end) - Repo.all(from t in Translation, - select: [t.title, t.teaser, t.date, t.user_id], - where: t.article_id in ^aids and t.public == true) - end -end diff --git a/lib/outlook/public.ex b/lib/outlook/public.ex index b7fc0a8..5157c7c 100644 --- a/lib/outlook/public.ex +++ b/lib/outlook/public.ex @@ -61,4 +61,15 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation |> String.to_integer(36) |> get_artikel!() end + + # for /autoren/ + + def list_autoren do + Repo.all(Author) + end + + def get_autor!(id) do + Repo.get!(Author, id) + |> Repo.preload([articles: [:translations]]) + end end diff --git a/lib/outlook_web/controllers/autor_controller.ex b/lib/outlook_web/controllers/autor_controller.ex index 179fede..f51d581 100644 --- a/lib/outlook_web/controllers/autor_controller.ex +++ b/lib/outlook_web/controllers/autor_controller.ex @@ -1,15 +1,15 @@ defmodule OutlookWeb.AutorController do use OutlookWeb, :controller - alias Outlook.Autoren + alias Outlook.Public def index(conn, _params) do - autoren = Autoren.list_autoren() + autoren = Public.list_autoren() render(conn, :index, autoren: autoren, page_title: "Autoren") end def show(conn, %{"id" => id}) do - autor = Autoren.get_autor!(id) + autor = Public.get_autor!(id) # artikel = Autoren.list_artikel(autor) render(conn, :show, autor: autor, page_title: autor.name) end