Refactor Autoren context into Public context
This commit is contained in:
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user