add type specs and fix id issues
Some checks failed
Build and Publish / build-release (push) Failing after 37s

This commit is contained in:
2026-04-21 12:55:38 -05:00
parent f857a5f900
commit 2bf99bfb37
7 changed files with 78 additions and 42 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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]