Further improve only_tag filtering

This commit is contained in:
Liam 2024-04-27 19:49:24 -04:00
parent 101aec001b
commit ba87c1679e

View file

@ -31,7 +31,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
# params.permit(:added, :only_tag) ...
pagination_params =
[added: conn.params["added"], only_tag: conn.params["only_tag"]]
|> Keyword.filter(fn {k, _v} -> Map.has_key?(conn.params, "#{k}") end)
|> Keyword.filter(fn {_k, v} -> not is_nil(v) and v != "" end)
render(conn, "index.html",
title: "Tag Changes for User `#{user.name}'",
@ -50,13 +50,15 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
defp added_filter(query, _params),
do: query
defp only_tag_join(query, %{"only_tag" => only_tag}) when only_tag != "",
defp only_tag_join(query, %{"only_tag" => only_tag})
when is_binary(only_tag) and only_tag != "",
do: join(query, :inner, [tc], t in Tag, on: tc.tag_id == t.id)
defp only_tag_join(query, _params),
do: query
defp only_tag_filter(query, %{"only_tag" => only_tag}) when only_tag != "",
defp only_tag_filter(query, %{"only_tag" => only_tag})
when is_binary(only_tag) and only_tag != "",
do: where(query, [_, _, t], t.name == ^only_tag)
defp only_tag_filter(query, _params),