mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 12:37:58 +01:00
55 lines
1.4 KiB
Elixir
55 lines
1.4 KiB
Elixir
defmodule PhilomenaWeb.ProfileController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.{Images, Images.Image, Users.User}
|
|
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
|
|
}
|
|
},
|
|
sort: %{created_at: :desc}
|
|
},
|
|
%{page_number: 1, page_size: 6},
|
|
Image |> preload([:tags])
|
|
)
|
|
|
|
recent_faves =
|
|
Image.search_records(
|
|
%{
|
|
query: %{
|
|
bool: %{
|
|
must_not: filter,
|
|
must: fave_query
|
|
}
|
|
},
|
|
sort: %{created_at: :desc}
|
|
},
|
|
%{page_number: 1, page_size: 6},
|
|
Image |> preload([:tags])
|
|
)
|
|
|
|
render(
|
|
conn,
|
|
"show.html",
|
|
user: user,
|
|
recent_uploads: recent_uploads,
|
|
recent_faves: recent_faves
|
|
)
|
|
end
|
|
end
|