This commit is contained in:
@@ -44,6 +44,7 @@ defmodule WorkloadService.Aggregates.Task do
|
||||
|
||||
alias unquote(commands_module).CreateTask
|
||||
alias unquote(commands_module).SubmitResponse
|
||||
alias unquote(commands_module).RequestApproval
|
||||
alias unquote(commands_module).ApproveSubmission
|
||||
alias unquote(commands_module).CompleteTask
|
||||
|
||||
@@ -86,6 +87,18 @@ defmodule WorkloadService.Aggregates.Task do
|
||||
end
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def execute(%__MODULE__{status: "draft"}, %RequestApproval{} = cmd) do
|
||||
%WorkloadService.Events.ApprovalRequested{
|
||||
id: cmd.id
|
||||
}
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def execute(%__MODULE__{status: status}, %RequestApproval{}) do
|
||||
{:error, {:invalid_state, "cannot request approval in state: #{status}"}}
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def execute(%__MODULE__{id: id, status: "draft"}, %ApproveSubmission{}) do
|
||||
%WorkloadService.Events.SubmissionApproved{
|
||||
@@ -141,6 +154,14 @@ defmodule WorkloadService.Aggregates.Task do
|
||||
}
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def apply(%__MODULE__{} = agg, %WorkloadService.Events.ApprovalRequested{}) do
|
||||
%{
|
||||
agg
|
||||
| status: "approval_requested"
|
||||
}
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def apply(%__MODULE__{} = agg, %WorkloadService.Events.TaskCompleted{}) do
|
||||
%{
|
||||
|
||||
@@ -15,6 +15,11 @@ defmodule WorkloadService.Application do
|
||||
WorkloadServiceWeb.Telemetry,
|
||||
{DNSCluster, query: Application.get_env(:workload_service, :dns_cluster_query) || :ignore},
|
||||
{Phoenix.PubSub, name: WorkloadService.PubSub},
|
||||
{Oidcc.ProviderConfiguration.Worker,
|
||||
%{
|
||||
issuer: Application.get_env(:workload_service, :zitadel)[:issuer],
|
||||
name: WorkloadService.ZitadelProvider
|
||||
}},
|
||||
WorkloadServiceWeb.Endpoint
|
||||
]
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ defmodule WorkloadService.Router do
|
||||
[
|
||||
WorkloadService.Commands.QuoteTask.CreateTask,
|
||||
WorkloadService.Commands.QuoteTask.SubmitResponse,
|
||||
WorkloadService.Commands.QuoteTask.RequestApproval,
|
||||
WorkloadService.Commands.QuoteTask.ApproveSubmission,
|
||||
WorkloadService.Commands.QuoteTask.CompleteTask
|
||||
],
|
||||
@@ -16,6 +17,7 @@ defmodule WorkloadService.Router do
|
||||
[
|
||||
WorkloadService.Commands.SolicitationTask.CreateTask,
|
||||
WorkloadService.Commands.SolicitationTask.SubmitResponse,
|
||||
WorkloadService.Commands.SolicitationTask.RequestApproval,
|
||||
WorkloadService.Commands.SolicitationTask.ApproveSubmission,
|
||||
WorkloadService.Commands.SolicitationTask.CompleteTask
|
||||
],
|
||||
|
||||
@@ -8,11 +8,11 @@ defmodule WorkloadService.Commands.QuoteTask do
|
||||
Command to create a new quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
application_id: WorkloadService.Aggregates.ApplicationId.t(),
|
||||
task_info: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
application_id: WorkloadService.Aggregates.ApplicationId.t(),
|
||||
task_info: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :application_id, :task_info, :attachments]
|
||||
@@ -23,10 +23,10 @@ defmodule WorkloadService.Commands.QuoteTask do
|
||||
Command to submit response for a quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
submission: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
submission: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :submission, :attachments]
|
||||
@@ -37,8 +37,21 @@ defmodule WorkloadService.Commands.QuoteTask do
|
||||
Command to approve submission for a quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
end
|
||||
|
||||
defmodule RequestApproval do
|
||||
@moduledoc """
|
||||
Command to request approval for a quote task.
|
||||
Moves task from 'draft' to 'approval_requested'.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
@@ -49,9 +62,9 @@ defmodule WorkloadService.Commands.QuoteTask do
|
||||
Command to complete a quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
completed_by: String.t()
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
completed_by: String.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :completed_by]
|
||||
|
||||
@@ -8,11 +8,11 @@ defmodule WorkloadService.Commands.SolicitationTask do
|
||||
Command to create a new solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
application_id: WorkloadService.Aggregates.ApplicationId.t(),
|
||||
task_info: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
application_id: WorkloadService.Aggregates.ApplicationId.t(),
|
||||
task_info: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :application_id, :task_info, :attachments]
|
||||
@@ -23,10 +23,10 @@ defmodule WorkloadService.Commands.SolicitationTask do
|
||||
Command to submit response for a solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
submission: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
submission: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :submission, :attachments]
|
||||
@@ -37,8 +37,21 @@ defmodule WorkloadService.Commands.SolicitationTask do
|
||||
Command to approve submission for a solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
end
|
||||
|
||||
defmodule RequestApproval do
|
||||
@moduledoc """
|
||||
Command to request approval for a solicitation task.
|
||||
Moves task from 'draft' to 'approval_requested'.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
@@ -49,11 +62,11 @@ defmodule WorkloadService.Commands.SolicitationTask do
|
||||
Command to complete a solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
completed_by: String.t()
|
||||
}
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
completed_by: String.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :completed_by]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,6 +54,16 @@ defmodule WorkloadService.Events.SubmissionApproved do
|
||||
defstruct [:id]
|
||||
end
|
||||
|
||||
defmodule WorkloadService.Events.ApprovalRequested do
|
||||
@moduledoc """
|
||||
Emitted when a user requests approval for their submission.
|
||||
This transitions the task from 'draft' to 'approval_requested'.
|
||||
"""
|
||||
use WorkloadService.Events
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
end
|
||||
|
||||
defmodule WorkloadService.Events.TaskCompleted do
|
||||
@moduledoc """
|
||||
Emitted when task is completed and sent to policy-service.
|
||||
@@ -62,4 +72,4 @@ defmodule WorkloadService.Events.TaskCompleted do
|
||||
use WorkloadService.Events
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :completed_by]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,6 +45,16 @@ defmodule WorkloadService.Projectors.TaskProjector do
|
||||
end)
|
||||
end)
|
||||
|
||||
project(%Events.ApprovalRequested{} = e, _meta, fn multi ->
|
||||
multi
|
||||
|> Ecto.Multi.run(:fetch, fn repo, _ ->
|
||||
{:ok, repo.get(Task, to_string(e.id))}
|
||||
end)
|
||||
|> Ecto.Multi.update(:task, fn %{fetch: task} ->
|
||||
Ecto.Changeset.change(task, %{status: "approval_requested"})
|
||||
end)
|
||||
end)
|
||||
|
||||
project(%Events.TaskCompleted{} = e, _meta, fn multi ->
|
||||
multi
|
||||
|> Ecto.Multi.run(:fetch, fn repo, _ ->
|
||||
|
||||
@@ -18,8 +18,8 @@ defmodule WorkloadService.Workload.Queries do
|
||||
|> Flop.validate_and_run(params, for: Task)
|
||||
end
|
||||
|
||||
def get_task_by_id(id) do
|
||||
case Repo.get(Task, id) do
|
||||
def get_task_by_id(org_id, id) do
|
||||
case Repo.get_by(Task, id: id, org_id: org_id) do
|
||||
nil -> {:error, :not_found}
|
||||
task -> {:ok, task}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user