diff --git a/lib/code_corps/messages/conversation_query.ex b/lib/code_corps/messages/conversation_query.ex index fac4fad6c..95fdc5e22 100644 --- a/lib/code_corps/messages/conversation_query.ex +++ b/lib/code_corps/messages/conversation_query.ex @@ -20,6 +20,17 @@ defmodule CodeCorps.Messages.ConversationQuery do end def project_filter(queryable, %{}), do: queryable + @doc ~S""" + Narrows down a `CodeCorps.Conversation` query by `user_id`, if specified in a + params map + """ + @spec user_filter(Queryable.t, map) :: Queryable.t + def user_filter(queryable, %{"user_id" => user_id}) do + queryable + |> where([c], c.user_id == ^user_id) + end + def user_filter(queryable, %{}), do: queryable + @doc ~S""" Narrows down a `CodeCorps.Conversation` query to return only those records diff --git a/lib/code_corps/messages/messages.ex b/lib/code_corps/messages/messages.ex index 7857c5c94..96fc80ac0 100644 --- a/lib/code_corps/messages/messages.ex +++ b/lib/code_corps/messages/messages.ex @@ -33,6 +33,7 @@ defmodule CodeCorps.Messages do scope |> Messages.ConversationQuery.project_filter(params) |> Messages.ConversationQuery.status_filter(params) + |> Messages.ConversationQuery.user_filter(params) |> Repo.all() end diff --git a/priv/repo/structure.sql b/priv/repo/structure.sql index d50ccec7a..b6e5a54b0 100644 --- a/priv/repo/structure.sql +++ b/priv/repo/structure.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.0 --- Dumped by pg_dump version 10.0 +-- Dumped from database version 10.1 +-- Dumped by pg_dump version 10.1 SET statement_timeout = 0; SET lock_timeout = 0;