forked from code-corps/code-corps-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_event_query.ex
More file actions
39 lines (34 loc) · 1.12 KB
/
github_event_query.ex
File metadata and controls
39 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
defmodule CodeCorps.Admin.GithubEventQuery do
@moduledoc ~S"""
Holds helpers to query `CodeCorps.GithubEvent` records using a map of params.
"""
import Ecto.Query
alias Ecto.Queryable
@doc ~S"""
Filters a `CodeCorps.GithubEvent` query by `action`, if specified in params
"""
@spec action_filter(Queryable.t, map) :: Queryable.t
def action_filter(queryable, %{"action" => action}) do
queryable
|> where([c], c.action == ^action)
end
def action_filter(queryable, %{}), do: queryable
@doc ~S"""
Filters a `CodeCorps.GithubEvent` query by `status`, if specified in params
"""
@spec status_filter(Queryable.t, map) :: Queryable.t
def status_filter(queryable, %{"status" => status}) do
queryable
|> where([c], c.status == ^status)
end
def status_filter(queryable, %{}), do: queryable
@doc ~S"""
Filters a `CodeCorps.GithubEvent` query by `type`, if specified in params
"""
@spec type_filter(Queryable.t, map) :: Queryable.t
def type_filter(queryable, %{"type" => type}) do
queryable
|> where([c], c.type == ^type)
end
def type_filter(queryable, %{}), do: queryable
end