-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
5 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,19 @@ | ||
defmodule CodeCorps.FilterHelpers do | ||
use CodeCorps.Web, :model | ||
|
||
import CodeCorps.StringHelpers, only: [coalesce_id_string: 1, coalesce_string: 1] | ||
|
||
def id_filter(query, id_list) do | ||
ids = id_list |> coalesce_id_string | ||
query |> where([object], object.id in ^ids) | ||
end | ||
|
||
def limit_filter(query, count) do | ||
query |> limit(^count) | ||
end | ||
|
||
def number_as_id_filter(query, number) do | ||
query |> where([object], object.number == ^number) | ||
end | ||
|
||
def organization_filter(query, organization_id) do | ||
query |> where([object], object.organization_id == ^organization_id) | ||
end | ||
|
||
def project_filter(query, project_id) do | ||
query |> where([object], object.project_id == ^project_id) | ||
end | ||
|
||
def role_filter(query, roles_list) do | ||
roles = roles_list |> coalesce_string | ||
query |> where([object], object.role in ^roles) | ||
end | ||
|
||
def task_filter(query, task_id) do | ||
query |> where([object], object.task_id == ^task_id) | ||
end | ||
|
||
def task_status_filter(query, status) do | ||
query |> where([object], object.status == ^status) | ||
end | ||
|
||
def task_type_filter(query, task_type_list) do | ||
task_types = task_type_list |> coalesce_string | ||
query |> where([object], object.task_type in ^task_types) | ||
end | ||
|
||
def title_filter(query, title) do | ||
query |> where([object], ilike(object.title, ^"%#{title}%")) | ||
end | ||
|
||
defp coalesce_id_string(string) do | ||
string | ||
|> String.split(",") | ||
|> Enum.map(&String.to_integer(&1)) | ||
end | ||
|
||
defp coalesce_string(string) do | ||
string | ||
|> String.split(",") | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
web/controllers/controller_helpers.ex → lib/code_corps/helpers/string_helpers.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters