Skip to content

Commit 0b810e9

Browse files
committed
Add job preferences fields and functionality to User schema
- Add min_compensation, willing_to_relocate, us_work_authorization fields - Create job_preferences_changeset for safe updates without authentication - Add update_job_preferences/2 function to Accounts context - Include URL validation for LinkedIn and Twitter fields
1 parent 70a6412 commit 0b810e9

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lib/algora/accounts/accounts.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ defmodule Algora.Accounts do
244244
user |> User.settings_changeset(attrs) |> Repo.update()
245245
end
246246

247+
def update_job_preferences(%User{} = user, attrs) do
248+
user |> User.job_preferences_changeset(attrs) |> Repo.update()
249+
end
250+
247251
## Database getters
248252

249253
@doc """

lib/algora/accounts/schemas/user.ex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ defmodule Algora.Accounts.User do
5959
field :hourly_rate_min, Money
6060
field :hourly_rate_max, Money
6161
field :hours_per_week, :integer
62+
field :min_compensation, Money
63+
field :willing_to_relocate, :boolean, default: false
64+
field :us_work_authorization, :boolean, default: false
6265

6366
field :total_earned, Money, virtual: true
6467
field :transactions_count, :integer, virtual: true
@@ -388,6 +391,24 @@ defmodule Algora.Accounts.User do
388391
cast(user, %{is_admin: is_admin}, [:is_admin])
389392
end
390393

394+
def job_preferences_changeset(%User{} = user, params) do
395+
user
396+
|> cast(params, [
397+
:min_compensation,
398+
:willing_to_relocate,
399+
:us_work_authorization,
400+
:linkedin_url,
401+
:twitter_url,
402+
:location
403+
])
404+
|> validate_url(:linkedin_url)
405+
|> validate_url(:twitter_url)
406+
end
407+
408+
defp validate_url(changeset, field) do
409+
validate_format(changeset, field, ~r/^https?:\/\/.*/, message: "must be a valid URL")
410+
end
411+
391412
def validate_timezone(changeset) do
392413
validate_inclusion(changeset, :timezone, Tzdata.zone_list())
393414
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmodule Algora.Repo.Migrations.AddJobPreferenceFieldsToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :min_compensation, :money_with_currency
7+
add :willing_to_relocate, :boolean, default: false
8+
add :us_work_authorization, :boolean, default: false
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)