mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
37 lines
912 B
Elixir
37 lines
912 B
Elixir
defmodule PhilomenaWeb.ImageController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.{Images.Image, Comments.Comment}
|
|
alias Philomena.Repo
|
|
import Ecto.Query
|
|
|
|
plug ImageFilter
|
|
plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, :user]
|
|
|
|
def index(conn, _params) do
|
|
query = conn.assigns.compiled_filter
|
|
|
|
images =
|
|
Image.search_records(
|
|
%{
|
|
query: %{bool: %{must_not: query}},
|
|
sort: %{created_at: :desc}
|
|
},
|
|
Image |> preload([:tags, :user])
|
|
)
|
|
|
|
render(conn, "index.html", images: images)
|
|
end
|
|
|
|
def show(conn, %{"id" => _id}) do
|
|
comments =
|
|
Comment
|
|
|> where(image_id: ^conn.assigns.image.id)
|
|
|> preload([:user, :image])
|
|
|> order_by(desc: :created_at)
|
|
|> limit(25)
|
|
|> Repo.all()
|
|
|
|
render(conn, "show.html", image: conn.assigns.image, comments: comments)
|
|
end
|
|
end
|