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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user