Skip to content

Commit 03e819d

Browse files
committed
feat: new job match fields
1 parent 043472d commit 03e819d

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

lib/algora/matches/matches.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ defmodule Algora.Matches do
2727
|> Repo.get!(id)
2828
end
2929

30+
def get_job_match_by_id(id) do
31+
JobMatch
32+
|> preload([:user, :job_posting])
33+
|> Repo.get(id)
34+
end
35+
3036
def get_job_match(user_id, job_posting_id) do
3137
JobMatch
3238
|> where([m], m.user_id == ^user_id and m.job_posting_id == ^job_posting_id)
@@ -162,6 +168,14 @@ defmodule Algora.Matches do
162168
JobMatch.changeset(job_match, attrs)
163169
end
164170

171+
def list_user_approved_matches(user_id) do
172+
list_job_matches(
173+
user_id: user_id,
174+
status: [:approved, :highlighted],
175+
preload: [job_posting: :user]
176+
)
177+
end
178+
165179
# Private helper functions
166180
defp filter_by_job_posting_id(query, nil), do: query
167181

@@ -183,6 +197,10 @@ defmodule Algora.Matches do
183197

184198
defp filter_by_status(query, nil), do: query
185199

200+
defp filter_by_status(query, status) when is_list(status) do
201+
where(query, [m], m.status in ^status)
202+
end
203+
186204
defp filter_by_status(query, status) do
187205
where(query, [m], m.status == ^status)
188206
end

lib/algora/matches/schemas/job_match.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ defmodule Algora.Matches.JobMatch do
88
field :status, Ecto.Enum, values: [:pending, :discarded, :approved, :highlighted], default: :pending
99
field :score, :decimal
1010
field :notes, :string
11-
field :approved_at, :utc_datetime_usec
12-
field :bookmarked_at, :utc_datetime_usec
13-
field :discarded_at, :utc_datetime_usec
11+
field :company_approved_at, :utc_datetime_usec
12+
field :company_bookmarked_at, :utc_datetime_usec
13+
field :company_discarded_at, :utc_datetime_usec
14+
field :candidate_approved_at, :utc_datetime_usec
15+
field :candidate_bookmarked_at, :utc_datetime_usec
16+
field :candidate_discarded_at, :utc_datetime_usec
1417

1518
belongs_to :user, Algora.Accounts.User
1619
belongs_to :job_posting, Algora.Jobs.JobPosting
@@ -20,7 +23,7 @@ defmodule Algora.Matches.JobMatch do
2023

2124
def changeset(job_match, attrs) do
2225
job_match
23-
|> cast(attrs, [:user_id, :job_posting_id, :status, :score, :notes, :approved_at, :bookmarked_at, :discarded_at])
26+
|> cast(attrs, [:user_id, :job_posting_id, :status, :score, :notes, :company_approved_at, :company_bookmarked_at, :company_discarded_at, :candidate_approved_at, :candidate_bookmarked_at, :candidate_discarded_at])
2427
|> validate_required([:user_id, :job_posting_id])
2528
|> validate_inclusion(:status, [:pending, :discarded, :approved, :highlighted])
2629
|> foreign_key_constraint(:user_id)

lib/algora_web/components/tech_badge.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ defmodule AlgoraWeb.Components.TechBadge do
7373

7474
defp normalize(tech) do
7575
case String.downcase(tech) do
76+
"golang" ->
77+
"go"
78+
7679
"plpgsql" ->
7780
"postgresql"
7881

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
defmodule Algora.Repo.Migrations.SplitJobMatchTimestampsBySide do
2+
use Ecto.Migration
3+
4+
def up do
5+
# Add new timestamp fields for company and candidate sides
6+
alter table(:job_matches) do
7+
add :company_approved_at, :utc_datetime_usec
8+
add :company_bookmarked_at, :utc_datetime_usec
9+
add :company_discarded_at, :utc_datetime_usec
10+
add :candidate_approved_at, :utc_datetime_usec
11+
add :candidate_bookmarked_at, :utc_datetime_usec
12+
add :candidate_discarded_at, :utc_datetime_usec
13+
end
14+
15+
# Migrate existing data - all existing timestamps are from company side
16+
execute """
17+
UPDATE job_matches
18+
SET company_approved_at = approved_at,
19+
company_bookmarked_at = bookmarked_at,
20+
company_discarded_at = discarded_at
21+
WHERE approved_at IS NOT NULL
22+
OR bookmarked_at IS NOT NULL
23+
OR discarded_at IS NOT NULL
24+
"""
25+
26+
# Drop the obsolete fields
27+
alter table(:job_matches) do
28+
remove :approved_at
29+
remove :bookmarked_at
30+
remove :discarded_at
31+
end
32+
end
33+
34+
def down do
35+
# Add back the original fields
36+
alter table(:job_matches) do
37+
add :approved_at, :utc_datetime_usec
38+
add :bookmarked_at, :utc_datetime_usec
39+
add :discarded_at, :utc_datetime_usec
40+
end
41+
42+
# Migrate data back from company fields
43+
execute """
44+
UPDATE job_matches
45+
SET approved_at = company_approved_at,
46+
bookmarked_at = company_bookmarked_at,
47+
discarded_at = company_discarded_at
48+
WHERE company_approved_at IS NOT NULL
49+
OR company_bookmarked_at IS NOT NULL
50+
OR company_discarded_at IS NOT NULL
51+
"""
52+
53+
# Drop the new fields
54+
alter table(:job_matches) do
55+
remove :company_approved_at
56+
remove :company_bookmarked_at
57+
remove :company_discarded_at
58+
remove :candidate_approved_at
59+
remove :candidate_bookmarked_at
60+
remove :candidate_discarded_at
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)