philomena/lib/philomena_web/controllers/profile_controller.ex

57 lines
1.4 KiB
Elixir
Raw Normal View History

2019-11-12 02:27:09 +01:00
defmodule PhilomenaWeb.ProfileController do
use PhilomenaWeb, :controller
2019-11-13 04:12:46 +01:00
alias Philomena.{Images, Images.Image, Users.User}
2019-11-12 02:27:09 +01:00
import Ecto.Query
plug :load_and_authorize_resource, model: User, only: :show, id_field: "slug", preload: [awards: :badge, public_links: :tag]
def show(conn, _params) do
current_user = conn.assigns.current_user
filter = conn.assigns.compiled_filter
user = conn.assigns.user
{:ok, upload_query} = Images.Query.compile(current_user, "uploader_id:#{user.id}")
{:ok, fave_query} = Images.Query.compile(current_user, "faved_by_id:#{user.id}")
recent_uploads =
Image.search_records(
%{
query: %{
bool: %{
must_not: filter,
must: upload_query
}
2019-11-12 02:37:11 +01:00
},
sort: %{created_at: :desc}
2019-11-12 02:27:09 +01:00
},
%{page_number: 1, page_size: 6},
Image |> preload([:tags])
)
recent_faves =
Image.search_records(
%{
query: %{
bool: %{
must_not: filter,
must: fave_query
}
2019-11-12 02:37:11 +01:00
},
sort: %{created_at: :desc}
2019-11-12 02:27:09 +01:00
},
%{page_number: 1, page_size: 6},
Image |> preload([:tags])
)
render(
conn,
"show.html",
user: user,
recent_uploads: recent_uploads,
2019-11-18 15:14:26 +01:00
recent_faves: recent_faves,
layout_class: "layout--wide"
2019-11-12 02:27:09 +01:00
)
end
end