Skip to content

Commit 79a336c

Browse files
committed
refactor: enhance job status filtering logic
- Updated the `maybe_filter_by_status` function to accept options directly, allowing for more flexible filtering based on job status and user ID. - Simplified the conditional logic for filtering job postings, improving readability and maintainability.
1 parent cd70053 commit 79a336c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/algora/jobs/jobs.ex

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Algora.Jobs do
1919

2020
def list_jobs(opts \\ []) do
2121
JobPosting
22-
|> maybe_filter_by_status(opts[:status])
22+
|> maybe_filter_by_status(opts)
2323
|> maybe_filter_by_user(opts)
2424
|> join(:inner, [j], u in User, on: u.id == j.user_id)
2525
|> maybe_filter_by_tech_stack(opts[:tech_stack])
@@ -62,14 +62,12 @@ defmodule Algora.Jobs do
6262

6363
defp maybe_filter_by_user(query, _), do: query
6464

65-
defp maybe_filter_by_status(query, nil), do: where(query, [j], j.status in [:active])
66-
67-
defp maybe_filter_by_status(query, :all) do
68-
where(query, [j], j.status in [:active, :processing])
69-
end
70-
71-
defp maybe_filter_by_status(query, status) do
72-
where(query, [j], j.status == ^status)
65+
defp maybe_filter_by_status(query, opts) do
66+
cond do
67+
opts[:status] == :all -> where(query, [j], j.status in [:active, :processing])
68+
opts[:user_id] -> where(query, [j], j.status in [:active, :processing])
69+
true -> where(query, [j], j.status in [:active])
70+
end
7371
end
7472

7573
defp maybe_filter_by_tech_stack(query, nil), do: query

0 commit comments

Comments
 (0)