revamp aggregate and use typestruct
All checks were successful
Build and Publish / build-release (push) Successful in 1m41s

This commit is contained in:
2026-04-22 11:37:04 -05:00
parent 5f2f9e9085
commit a7160aadcf
19 changed files with 228 additions and 185 deletions

View File

@@ -1,8 +1,6 @@
defmodule PolicyService.Commands.CarPolicy do
alias PolicyService.Commands.Policy
defmodule SubmitPolicyApplication, do: use(Policy.SubmitPolicyApplication)
defmodule RecordProviderQuote, do: use(Policy.RecordProviderQuote)
defmodule AcceptQuoteAndSolicit, do: use(Policy.AcceptQuoteAndSolicit)
defmodule RecordPolicyIssued, do: use(Policy.RecordPolicyIssued)
end
defmodule SubmitPolicyApplication, do: use(PolicyService.Commands.Policy.SubmitPolicyApplication)
defmodule RecordProviderQuote, do: use(PolicyService.Commands.Policy.RecordProviderQuote)
defmodule AcceptQuoteAndSolicit, do: use(PolicyService.Commands.Policy.AcceptQuoteAndSolicit)
defmodule RecordPolicyIssued, do: use(PolicyService.Commands.Policy.RecordPolicyIssued)
end

View File

@@ -1,8 +1,6 @@
defmodule PolicyService.Commands.FirePolicy do
alias PolicyService.Commands.Policy
defmodule SubmitPolicyApplication, do: use(Policy.SubmitPolicyApplication)
defmodule RecordProviderQuote, do: use(Policy.RecordProviderQuote)
defmodule AcceptQuoteAndSolicit, do: use(Policy.AcceptQuoteAndSolicit)
defmodule RecordPolicyIssued, do: use(Policy.RecordPolicyIssued)
end
defmodule SubmitPolicyApplication, do: use(PolicyService.Commands.Policy.SubmitPolicyApplication)
defmodule RecordProviderQuote, do: use(PolicyService.Commands.Policy.RecordProviderQuote)
defmodule AcceptQuoteAndSolicit, do: use(PolicyService.Commands.Policy.AcceptQuoteAndSolicit)
defmodule RecordPolicyIssued, do: use(PolicyService.Commands.Policy.RecordPolicyIssued)
end

View File

@@ -1,19 +1,20 @@
defmodule PolicyService.Commands.Policy do
@moduledoc """
Base templates for Policy commands.
Use these macros to ensure all policy types share the same structure.
Base templates for Policy commands using TypedStruct.
"""
defmodule SubmitPolicyApplication do
defmacro __using__(_opts) do
quote do
defstruct [
:id,
:submitted_by,
:applicant_info,
:policy_details,
:selected_providers
]
use TypedStruct
typedstruct do
field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true
field :submitted_by, String.t(), enforce: true
field :applicant_info, map(), enforce: true
field :policy_details, map()
field :selected_providers, list(), enforce: true
end
end
end
end
@@ -21,16 +22,18 @@ defmodule PolicyService.Commands.Policy do
defmodule RecordProviderQuote do
defmacro __using__(_opts) do
quote do
defstruct [
:id,
:recorded_by,
:provider_id,
:quote_id,
:premium,
:coverage_details,
:valid_until,
:plans
]
use TypedStruct
typedstruct do
field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true
field :recorded_by, String.t(), enforce: true
field :provider_id, String.t(), enforce: true
field :quote_id, String.t(), enforce: true
field :premium, String.t()
field :coverage_details, map()
field :valid_until, String.t(), enforce: true
field :plans, list(), enforce: true
end
end
end
end
@@ -38,13 +41,13 @@ defmodule PolicyService.Commands.Policy do
defmodule AcceptQuoteAndSolicit do
defmacro __using__(_opts) do
quote do
defstruct [
:id,
:accepted_by,
:quote_id,
:plan_id,
:solicitation_fields
]
use TypedStruct
typedstruct do
field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true
field :accepted_by, String.t(), enforce: true
field :accepted_plan_id, String.t(), enforce: true
end
end
end
end
@@ -52,14 +55,16 @@ defmodule PolicyService.Commands.Policy do
defmodule RecordPolicyIssued do
defmacro __using__(_opts) do
quote do
defstruct [
:id,
:policy_number,
:effective_date,
:expiry_date,
:issued_at
]
use TypedStruct
typedstruct do
field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true
field :provider_policy_number, String.t(), enforce: true
field :effective_date, String.t(), enforce: true
field :expiry_date, String.t(), enforce: true
field :issued_at, String.t()
end
end
end
end
end
end