mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-05 00:57:59 +01:00
21 lines
409 B
Elixir
21 lines
409 B
Elixir
defmodule PhilomenaWeb.LoadPollPlug do
|
|
alias Philomena.Polls.Poll
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
def init(opts), do: opts
|
|
|
|
def call(%{assigns: %{topic: topic}} = conn, _opts) do
|
|
Poll
|
|
|> where(topic_id: ^topic.id)
|
|
|> Repo.one()
|
|
|> case do
|
|
nil ->
|
|
PhilomenaWeb.NotFoundPlug.call(conn)
|
|
|
|
poll ->
|
|
Plug.Conn.assign(conn, :poll, poll)
|
|
end
|
|
end
|
|
end
|