-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add TaskAssignmentLog * Add assign_task and unassign_task * Defensive coding * Log task assignment in rider signuop * Log events when dispatcher assigns * Move taskassignmentlog to its own context
- Loading branch information
Showing
9 changed files
with
224 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule BikeBrigade.History do | ||
import Ecto.Query, warn: false | ||
alias BikeBrigade.Repo | ||
|
||
alias BikeBrigade.History.TaskAssignmentLog | ||
|
||
@doc """ | ||
List all task assignment logs | ||
Currently this table is used for analytics and not exposed in the app. | ||
""" | ||
def list_task_assignment_logs() do | ||
Repo.all(TaskAssignmentLog) | ||
end | ||
|
||
def create_task_assignment_log(attrs \\ %{}) do | ||
%TaskAssignmentLog{timestamp: DateTime.utc_now()} | ||
|> TaskAssignmentLog.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule BikeBrigade.History.TaskAssignmentLog do | ||
use BikeBrigade.Schema | ||
|
||
import Ecto.Changeset | ||
|
||
alias BikeBrigade.Delivery.Task | ||
alias BikeBrigade.Riders.Rider | ||
alias BikeBrigade.Accounts.User | ||
|
||
schema "task_assignment_logs" do | ||
belongs_to :task, Task | ||
belongs_to :rider, Rider | ||
belongs_to :user, User | ||
|
||
field :timestamp, :utc_datetime_usec | ||
field :action, Ecto.Enum, values: [:assigned, :unassigned] | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(struct, params \\ %{}) do | ||
struct | ||
|> cast(params, [ | ||
:task_id, | ||
:rider_id, | ||
:user_id, | ||
:timestamp, | ||
:action | ||
]) | ||
|> validate_required([:task_id, :rider_id, :user_id, :timestamp, :action]) | ||
|> validate_inclusion(:action, [:assigned, :unassigned]) | ||
end | ||
end |
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
15 changes: 15 additions & 0 deletions
15
priv/repo/migrations/20240416185206_create_task_assignment_log.exs
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule BikeBrigade.Repo.Migrations.CreateTaskAssgignmentLog do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:task_assignment_logs) do | ||
add :task_id, references(:tasks) | ||
add :rider_id, references(:riders) | ||
add :user_id, references(:users) | ||
add :timestamp, :utc_datetime_usec | ||
add :action, :string | ||
|
||
timestamps() | ||
end | ||
end | ||
end |
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