add parameter recoder

This commit is contained in:
byte[] 2019-12-08 01:00:53 -05:00
parent 5f9fe0cb98
commit caaeb3ad2e
3 changed files with 20 additions and 0 deletions

View file

@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Api.Json.TagController do
alias Philomena.Tags.Tag alias Philomena.Tags.Tag
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
plug :load_resource, model: Tag, id_field: "slug", persisted: true, preload: [:aliased_tag, :aliases, :implied_tags, :implied_by_tags, :dnp_entries] plug :load_resource, model: Tag, id_field: "slug", persisted: true, preload: [:aliased_tag, :aliases, :implied_tags, :implied_by_tags, :dnp_entries]
def show(conn, _params) do def show(conn, _params) do

View file

@ -8,6 +8,8 @@ defmodule PhilomenaWeb.TagController do
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
def index(conn, params) do def index(conn, params) do
query_string = params["tq"] || "*" query_string = params["tq"] || "*"

View file

@ -0,0 +1,17 @@
defmodule PhilomenaWeb.RecodeParameterPlug do
def init(opts), do: opts
def call(conn, [name: name]) do
fixed_value =
conn
|> Map.get(:params)
|> Map.get(name)
|> to_string()
|> URI.encode_www_form()
|> String.replace("%2B", "+")
params = Map.put(conn.params, name, fixed_value)
%{conn | params: params}
end
end