Skip to content

Commit ba36658

Browse files
committed
feat: update job listing logic
- Added a new boolean field `contract_signed` to the User schema with a default value of false. - Enhanced job listing functionality to include filtering and ordering based on the `contract_signed` status of users. - Introduced a migration to add the `contract_signed` field to the users table.
1 parent 3146c70 commit ba36658

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ defmodule Algora.Accounts.User do
5050
field :max_open_attempts, :integer, default: 3
5151
field :manual_assignment, :boolean, default: false
5252
field :is_admin, :boolean, default: false
53+
field :contract_signed, :boolean, default: false
5354
field :last_active_at, :utc_datetime_usec
5455

5556
field :seeking_bounties, :boolean, default: false

lib/algora/jobs/jobs.ex

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,33 @@ defmodule Algora.Jobs do
1212
alias Algora.Payments.Transaction
1313
alias Algora.Repo
1414
alias Algora.Util
15+
alias AlgoraCloud.Interviews.JobInterview
1516

1617
require Logger
1718

1819
def list_jobs(opts \\ []) do
1920
JobPosting
20-
|> apply_ordering(opts)
21+
|> maybe_filter_by_status(opts[:status])
2122
|> maybe_filter_by_user(opts)
2223
|> join(:inner, [j], u in User, on: u.id == j.user_id)
23-
|> maybe_filter_by_users(opts[:handles])
2424
|> maybe_filter_by_tech_stack(opts[:tech_stack])
25+
|> join(:left, [j], i in JobInterview, on: i.job_posting_id == j.id)
26+
|> group_by([j, u, i], [u.contract_signed, j.id, j.inserted_at])
27+
|> order_by([j, u, i],
28+
desc: u.contract_signed,
29+
desc: coalesce(max(i.inserted_at), j.inserted_at),
30+
desc: j.inserted_at
31+
)
2532
|> maybe_limit(opts[:limit])
2633
|> Repo.all()
2734
|> apply_preloads(opts)
2835
end
2936

3037
def count_jobs(opts \\ []) do
3138
JobPosting
32-
|> order_by([j], desc: j.inserted_at)
39+
|> maybe_filter_by_status(opts[:status])
3340
|> maybe_filter_by_user(opts)
3441
|> join(:inner, [j], u in User, on: u.id == j.user_id)
35-
|> maybe_filter_by_users(opts[:handles])
3642
|> maybe_filter_by_tech_stack(opts[:tech_stack])
3743
|> Repo.aggregate(:count)
3844
end
@@ -53,18 +59,14 @@ defmodule Algora.Jobs do
5359

5460
defp maybe_filter_by_user(query, _), do: query
5561

56-
defp maybe_filter_by_users(query, nil), do: query
57-
58-
defp maybe_filter_by_users(query, handles) do
59-
# Need to handle different query structures based on joins
60-
case query.joins do
61-
# When we have interview join, the user table is the 3rd binding ([j, i, u])
62-
[_interview_join, _user_join] -> where(query, [j, i, u], u.provider_login in ^handles or u.handle in ^handles)
63-
# When we only have user join, it's the 2nd binding ([j, u])
64-
[_user_join] -> where(query, [j, u], u.provider_login in ^handles or u.handle in ^handles)
65-
# No joins yet, will be added later
66-
[] -> where(query, [j, u], u.provider_login in ^handles or u.handle in ^handles)
67-
end
62+
defp maybe_filter_by_status(query, nil), do: where(query, [j], j.status in [:active])
63+
64+
defp maybe_filter_by_status(query, :all) do
65+
where(query, [j], j.status in [:active, :processing])
66+
end
67+
68+
defp maybe_filter_by_status(query, status) do
69+
where(query, [j], j.status == ^status)
6870
end
6971

7072
defp maybe_filter_by_tech_stack(query, nil), do: query
@@ -77,22 +79,6 @@ defmodule Algora.Jobs do
7779
defp maybe_limit(query, nil), do: query
7880
defp maybe_limit(query, limit), do: limit(query, ^limit)
7981

80-
defp apply_ordering(query, opts) do
81-
case opts[:order_by] do
82-
:last_interview_desc ->
83-
# Sort by most recent interview, then by job posting date
84-
# Use LEFT JOIN to include all jobs, even those without interviews
85-
query
86-
|> join(:left, [j], i in "job_interviews", on: i.job_posting_id == j.id)
87-
|> group_by([j], [j.id, j.inserted_at])
88-
|> order_by([j, i], desc: coalesce(max(i.inserted_at), j.inserted_at), desc: j.inserted_at)
89-
90-
_ ->
91-
# Default ordering by job posting date
92-
order_by(query, [j], desc: j.inserted_at)
93-
end
94-
end
95-
9682
defp apply_preloads(jobs, opts) do
9783
preloads = [:user | opts[:preload] || []]
9884
Repo.preload(jobs, preloads)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Algora.Repo.Migrations.AddContractSignedToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :contract_signed, :boolean, default: false
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)