add type specs and fix id issues
Some checks failed
Build and Publish / build-release (push) Failing after 37s
Some checks failed
Build and Publish / build-release (push) Failing after 37s
This commit is contained in:
@@ -4,6 +4,12 @@ defmodule WorkloadService.Aggregates.ApplicationId do
|
||||
Used to track which policy-service application this task belongs to.
|
||||
"""
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
org_id: String.t(),
|
||||
application_id: String.t(),
|
||||
policy_type: String.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:org_id, :application_id, :policy_type]
|
||||
|
||||
@@ -49,4 +55,4 @@ defmodule WorkloadService.Aggregates.ApplicationId do
|
||||
|
||||
def decode(id), do: id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,6 +10,15 @@ defmodule WorkloadService.Aggregates.Task do
|
||||
end
|
||||
"""
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t() | nil,
|
||||
application_id: WorkloadService.Aggregates.ApplicationId.t() | nil,
|
||||
task_info: map() | nil,
|
||||
submission: map() | nil,
|
||||
attachments: [String.t()],
|
||||
status: String.t() | nil
|
||||
}
|
||||
|
||||
@callback validate_submission(map()) :: :ok | {:error, term()}
|
||||
|
||||
defmacro __using__(opts) do
|
||||
@@ -55,8 +64,6 @@ defmodule WorkloadService.Aggregates.Task do
|
||||
def execute(%__MODULE__{status: status}, %SubmitResponse{} = cmd)
|
||||
when status in [nil, "created", "draft", "approved"] do
|
||||
with :ok <- validate_submission(cmd.submission) do
|
||||
new_status = if status == "approved", do: "draft", else: "draft"
|
||||
|
||||
%WorkloadService.Events.SubmissionUpdated{
|
||||
id: cmd.id,
|
||||
submission: cmd.submission,
|
||||
@@ -78,9 +85,9 @@ defmodule WorkloadService.Aggregates.Task do
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def execute(%__MODULE__{status: "approved"}, %CompleteTask{} = cmd) do
|
||||
def execute(%__MODULE__{status: "approved", id: id}, %CompleteTask{} = cmd) do
|
||||
%WorkloadService.Events.TaskCompleted{
|
||||
id: cmd.id,
|
||||
id: id,
|
||||
completed_by: cmd.completed_by
|
||||
}
|
||||
end
|
||||
|
||||
@@ -4,6 +4,12 @@ defmodule WorkloadService.Aggregates.TaskId do
|
||||
ID format: "org_id:type:task_id" (e.g., "test:quote:uuid")
|
||||
"""
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
org_id: String.t(),
|
||||
type: String.t(),
|
||||
task_id: String.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:org_id, :type, :task_id]
|
||||
|
||||
|
||||
@@ -7,47 +7,53 @@ defmodule WorkloadService.Commands.QuoteTask do
|
||||
@moduledoc """
|
||||
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()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :application_id, :task_info, :attachments]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule SubmitResponse do
|
||||
@moduledoc """
|
||||
Command to submit response for a quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
submission: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :submission, :attachments]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule ApproveSubmission do
|
||||
@moduledoc """
|
||||
Command to approve submission for a quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule CompleteTask do
|
||||
@moduledoc """
|
||||
Command to complete a quote task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
completed_by: String.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :completed_by]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,47 +7,53 @@ defmodule WorkloadService.Commands.SolicitationTask do
|
||||
@moduledoc """
|
||||
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()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :application_id, :task_info, :attachments]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule SubmitResponse do
|
||||
@moduledoc """
|
||||
Command to submit response for a solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
submission: map(),
|
||||
attachments: [String.t()]
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :submission, :attachments]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule ApproveSubmission do
|
||||
@moduledoc """
|
||||
Command to approve submission for a solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule CompleteTask do
|
||||
@moduledoc """
|
||||
Command to complete a solicitation task.
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
id: WorkloadService.Aggregates.TaskId.t(),
|
||||
completed_by: String.t()
|
||||
}
|
||||
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :completed_by]
|
||||
|
||||
def new(attrs) do
|
||||
struct(__MODULE__, attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -29,7 +29,7 @@ defmodule WorkloadService.Handlers.TaskCompletedHandler do
|
||||
{:ok, module} ->
|
||||
case Aggregate.aggregate_state(
|
||||
WorkloadService.CommandedApp,
|
||||
aggregate_module,
|
||||
module,
|
||||
event.id
|
||||
) do
|
||||
nil ->
|
||||
|
||||
Reference in New Issue
Block a user