Compare commits
2 Commits
3fe4a331ac
...
b20bbb232c
| Author | SHA1 | Date | |
|---|---|---|---|
| b20bbb232c | |||
| cbea9450e4 |
@ -8,7 +8,7 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
||||
alias Outlook.Translations.Translation
|
||||
alias Outlook.Articles.Article
|
||||
alias Outlook.Authors.Author
|
||||
alias Outlook.Public.Artikel
|
||||
alias Outlook.Public.{Artikel,Autor}
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Outlook.Repo
|
||||
@ -17,19 +17,17 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
||||
q = from t in Translation,
|
||||
join: a in Article, on: t.article_id == a.id,
|
||||
join: au in Author, on: a.author_id == au.id,
|
||||
select: [
|
||||
select: %Artikel{
|
||||
title: t.title,
|
||||
date: t.date,
|
||||
teaser: t.teaser,
|
||||
id: t.id,
|
||||
date_org: a.date,
|
||||
autor_name: au.name,
|
||||
],
|
||||
},
|
||||
where: t.public == true and t.language == ^language,
|
||||
order_by: [desc: t.date]
|
||||
Repo.all(q)
|
||||
# |> Enum.map(fn rec -> Enum.into(rec, %{}) end)
|
||||
|> Enum.map(fn map -> struct(Artikel, map) end)
|
||||
end
|
||||
|
||||
def get_artikel!(artikel) when is_struct(artikel), do: get_artikel!(artikel.id)
|
||||
@ -37,7 +35,7 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
||||
q = from t in Translation,
|
||||
join: a in Article, on: t.article_id == a.id,
|
||||
join: au in Author, on: a.author_id == au.id,
|
||||
select: [
|
||||
select: %Artikel{
|
||||
title: t.title,
|
||||
date: t.date,
|
||||
public_content: t.public_content,
|
||||
@ -45,12 +43,12 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
||||
url_org: a.url,
|
||||
date_org: a.date,
|
||||
autor_name: au.name,
|
||||
author_id: au.id
|
||||
],
|
||||
autor_id: au.id
|
||||
},
|
||||
where: t.id == ^id and t.public == true
|
||||
case Repo.one(q) do
|
||||
nil -> {:error, "Artikel does not exist, or isn't public."}
|
||||
artikel -> {:ok, struct(Artikel, artikel)}
|
||||
artikel -> {:ok, artikel}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ defmodule Outlook.Public.Artikel do
|
||||
field :url_org, :string
|
||||
field :date_org, :utc_datetime
|
||||
field :autor_name, :string
|
||||
field :author_id, :integer
|
||||
field :autor_id, :integer
|
||||
field :teaser, :string
|
||||
# field :autor, Autor
|
||||
end
|
||||
|
||||
13
lib/outlook/public/autor.ex
Normal file
13
lib/outlook/public/autor.ex
Normal file
@ -0,0 +1,13 @@
|
||||
defmodule Outlook.Public.Autor do
|
||||
use Ecto.Schema
|
||||
|
||||
alias Outlook.Public.Artikel
|
||||
|
||||
embedded_schema do
|
||||
field :name, :string
|
||||
field :description, :string
|
||||
field :homepage_name, :string
|
||||
field :homepage_url, :string
|
||||
has_many :artikel, Artikel
|
||||
end
|
||||
end
|
||||
@ -1,6 +1,6 @@
|
||||
<header class="mb-6">
|
||||
<h1 class="text-lg font-semibold leading-tight text-stone-800 dark:text-stone-200"><%= @artikel.title %></h1>
|
||||
<p class="my-2"><.link href={~p"/autoren/#{@artikel.author_id}"}><%= @artikel.autor_name %></.link>
|
||||
<p class="my-2"><.link href={~p"/autoren/#{@artikel.autor_id}"}><%= @artikel.autor_name %></.link>
|
||||
— <%= Calendar.strftime(@artikel.date_org, "%d.%m.%Y") %></p>
|
||||
<div>Original Artikel:
|
||||
<.link class="hover:text-sky-700" href={@artikel.url_org} >
|
||||
@ -14,4 +14,4 @@
|
||||
|
||||
<div class="article w-full mx-auto max-w-xs"><%= @artikel.public_content |> raw %></div>
|
||||
|
||||
<.back navigate={~p"/autoren/#{@artikel.author_id}"}>Back to Autor</.back>
|
||||
<.back navigate={~p"/autoren/#{@artikel.autor_id}"}>Back to Autor</.back>
|
||||
|
||||
Reference in New Issue
Block a user