From 476363d4f70868e3a4cce750097f86804439515d Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Jul 2024 14:47:45 -0400 Subject: [PATCH] Use compile with opts for post queries --- lib/philomena/posts/query.ex | 3 ++- .../controllers/api/json/search/post_controller.ex | 2 +- lib/philomena_web/controllers/post_controller.ex | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/philomena/posts/query.ex b/lib/philomena/posts/query.ex index 331655c7..0722b10c 100644 --- a/lib/philomena/posts/query.ex +++ b/lib/philomena/posts/query.ex @@ -90,7 +90,8 @@ defmodule Philomena.Posts.Query do |> Parser.parse(query_string, context) end - def compile(user, query_string) do + def compile(query_string, opts \\ []) do + user = Keyword.get(opts, :user) query_string = query_string || "" case user do diff --git a/lib/philomena_web/controllers/api/json/search/post_controller.ex b/lib/philomena_web/controllers/api/json/search/post_controller.ex index 919a5b13..c305de12 100644 --- a/lib/philomena_web/controllers/api/json/search/post_controller.ex +++ b/lib/philomena_web/controllers/api/json/search/post_controller.ex @@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Json.Search.PostController do def index(conn, params) do user = conn.assigns.current_user - case Query.compile(user, params["q"] || "") do + case Query.compile(params["q"], user: user) do {:ok, query} -> posts = Post diff --git a/lib/philomena_web/controllers/post_controller.ex b/lib/philomena_web/controllers/post_controller.ex index 17b8fcd5..6f00ff7c 100644 --- a/lib/philomena_web/controllers/post_controller.ex +++ b/lib/philomena_web/controllers/post_controller.ex @@ -13,8 +13,8 @@ defmodule PhilomenaWeb.PostController do conn = Map.put(conn, :params, params) user = conn.assigns.current_user - user - |> Query.compile(pq) + pq + |> Query.compile(user: user) |> render_index(conn, user) end