mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
24 lines
755 B
Elixir
24 lines
755 B
Elixir
defmodule PhilomenaWeb.SearchController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias PhilomenaWeb.ImageLoader
|
|
alias Philomena.ImageSorter
|
|
alias Philomena.Interactions
|
|
|
|
def index(conn, params) do
|
|
user = conn.assigns.current_user
|
|
sort = ImageSorter.parse_sort(params)
|
|
|
|
case ImageLoader.search_string(conn, params["q"], sorts: sort.sorts, queries: sort.queries) do
|
|
{:ok, images} ->
|
|
interactions =
|
|
Interactions.user_interactions(images, user)
|
|
|
|
conn
|
|
|> render("index.html", images: images, search_query: params["q"], interactions: interactions, layout_class: "layout--wide")
|
|
|
|
{:error, msg} ->
|
|
render(conn, "index.html", images: [], error: msg, search_query: params["q"])
|
|
end
|
|
end
|
|
end
|