rename policy_details to insured_object
All checks were successful
Build and Publish / build-release (push) Successful in 1m36s
All checks were successful
Build and Publish / build-release (push) Successful in 1m36s
This commit is contained in:
@@ -64,25 +64,6 @@ services:
|
||||
exit 0;
|
||||
"
|
||||
|
||||
app:
|
||||
image: policy_service:3vhql9vd8pm9fwad3q5hp5qs4i7nqb3n
|
||||
ports:
|
||||
- "4000:4000"
|
||||
environment:
|
||||
MIX_ENV: prod
|
||||
PORT: "4000"
|
||||
PHX_HOST: "0.0.0.0"
|
||||
PHX_SERVER: "true"
|
||||
DATABASE_URL: "ecto://postgres:postgres@postgres:5432/policy_service_dev"
|
||||
SECRET_KEY_BASE: "dGVzdF9zZWNyZXRrZXlfYmFzZV9mb3JfdGVzdGluZ19wdXJwb3Nlcw=="
|
||||
AMQP_URL: "amqp://guest:guest@rabbitmq:5672"
|
||||
RELEASE_COOKIE: "test-cookie"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
|
||||
volumes:
|
||||
customer_pg_data:
|
||||
rabbitmq_data:
|
||||
|
||||
@@ -6,7 +6,7 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
@valid_use_types ~w(private commercial bus taxi school)
|
||||
@valid_car_types ~w(sedan suv hatchback coupe convertible pickup van minivan truck)
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"plate" => plate,
|
||||
"make" => make,
|
||||
"model" => model,
|
||||
@@ -32,7 +32,7 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"plate" => plate,
|
||||
"make" => make,
|
||||
"model" => model,
|
||||
@@ -61,5 +61,5 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_car_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_car_details}
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ defmodule PolicyService.Aggregates.FireContentsPolicyApplication do
|
||||
policy_type: "fire_contents",
|
||||
commands: PolicyService.Commands.FireContentsPolicy
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"location" => location,
|
||||
"contents_value" => value,
|
||||
"property_use" => use_type,
|
||||
@@ -18,5 +18,5 @@ defmodule PolicyService.Aggregates.FireContentsPolicyApplication do
|
||||
:ok
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_fire_contents_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_fire_contents_details}
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ defmodule PolicyService.Aggregates.FireStructurePolicyApplication do
|
||||
policy_type: "fire_structure",
|
||||
commands: PolicyService.Commands.FireStructurePolicy
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"location" => location,
|
||||
"property_value" => value,
|
||||
"property_use" => use_type,
|
||||
@@ -18,5 +18,5 @@ defmodule PolicyService.Aggregates.FireStructurePolicyApplication do
|
||||
:ok
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_fire_structure_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_fire_structure_details}
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ defmodule PolicyService.Aggregates.LifePolicyApplication do
|
||||
|
||||
@valid_coverage_types ~w(banking protection)
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"coverage_type" => coverage_type,
|
||||
"coverage_amount" => coverage_amount,
|
||||
"coverage_years" => coverage_years,
|
||||
@@ -30,7 +30,7 @@ defmodule PolicyService.Aggregates.LifePolicyApplication do
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_life_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_life_details}
|
||||
|
||||
def validate_insured(%{"type" => "corporate"}), do: {:error, :life_insurance_requires_individual}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
@moduledoc """
|
||||
Behaviour and __using__ macro for policy application aggregates.
|
||||
Each policy type implements validate_details/1 and declares its detail fields.
|
||||
Each policy type implements validate_insured_object/1 and declares its insured object fields.
|
||||
|
||||
Usage:
|
||||
defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
@@ -10,7 +10,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
end
|
||||
"""
|
||||
|
||||
@callback validate_details(map()) :: :ok | {:error, term()}
|
||||
@callback validate_insured_object(map()) :: :ok | {:error, term()}
|
||||
|
||||
defmacro __using__(opts) do
|
||||
policy_type = Keyword.fetch!(opts, :policy_type)
|
||||
@@ -41,7 +41,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
:submitted_by,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:selected_providers,
|
||||
:accepted_plan_id,
|
||||
:accepted_by,
|
||||
@@ -61,7 +61,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
:ok <- validate_insured(cmd.insured),
|
||||
:ok <-
|
||||
PolicyService.Aggregates.PolicyApplication.validate_buyer(cmd.buyer),
|
||||
:ok <- validate_details(cmd.policy_details),
|
||||
:ok <- validate_insured_object(cmd.insured_object),
|
||||
:ok <-
|
||||
PolicyService.Aggregates.PolicyApplication.validate_providers(
|
||||
cmd.selected_providers
|
||||
@@ -74,7 +74,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
provider_email: provider.email,
|
||||
insured: cmd.insured,
|
||||
buyer: cmd.buyer,
|
||||
policy_details: cmd.policy_details,
|
||||
insured_object: cmd.insured_object,
|
||||
requested_at: DateTime.utc_now()
|
||||
}
|
||||
end)
|
||||
@@ -85,7 +85,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
submitted_by: cmd.submitted_by,
|
||||
insured: cmd.insured,
|
||||
buyer: cmd.buyer,
|
||||
policy_details: cmd.policy_details,
|
||||
insured_object: cmd.insured_object,
|
||||
selected_providers: cmd.selected_providers,
|
||||
submitted_at: DateTime.utc_now()
|
||||
}
|
||||
@@ -192,7 +192,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
submitted_by: e.submitted_by,
|
||||
insured: e.insured,
|
||||
buyer: e.buyer,
|
||||
policy_details: e.policy_details,
|
||||
insured_object: e.insured_object,
|
||||
selected_providers: e.selected_providers,
|
||||
quotes: %{},
|
||||
state: :awaiting_quotes
|
||||
|
||||
@@ -13,7 +13,7 @@ defmodule PolicyService.Commands.Policy do
|
||||
field :submitted_by, String.t(), enforce: true
|
||||
field :insured, map(), enforce: true
|
||||
field :buyer, map(), enforce: true
|
||||
field :policy_details, map()
|
||||
field :insured_object, map()
|
||||
field :selected_providers, list(), enforce: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ defmodule PolicyService.Events.Policy do
|
||||
:submitted_by,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:selected_providers,
|
||||
:submitted_at
|
||||
]
|
||||
@@ -49,7 +49,7 @@ defmodule PolicyService.Events.Policy do
|
||||
:provider_email,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:requested_at
|
||||
]
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ defmodule PolicyService.Projections.PolicyApplication do
|
||||
:policy_type,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:selected_providers,
|
||||
:quotes,
|
||||
:accepted_plan_id,
|
||||
@@ -53,7 +53,7 @@ defmodule PolicyService.Projections.PolicyApplication do
|
||||
|
||||
field :insured, :map
|
||||
field :buyer, :map
|
||||
field :policy_details, :map
|
||||
field :insured_object, :map
|
||||
|
||||
field :selected_providers, {:array, :string}, default: []
|
||||
field :quotes, :map, default: %{}
|
||||
|
||||
@@ -26,7 +26,7 @@ defmodule PolicyService.Projectors.PolicyProjector do
|
||||
policy_type: e.id.policy_type,
|
||||
insured: atomize(e.insured),
|
||||
buyer: atomize(e.buyer),
|
||||
policy_details: atomize(e.policy_details),
|
||||
insured_object: atomize(e.insured_object),
|
||||
selected_providers: Enum.map(e.selected_providers, & &1["provider_id"]),
|
||||
quotes: %{},
|
||||
status: "quote_requested",
|
||||
|
||||
@@ -95,7 +95,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
with {:ok, policy_type} <- parse_policy_type(params["policy_type"]),
|
||||
{:ok, insured} <- parse_insured(params["insured"]),
|
||||
{:ok, buyer} <- parse_buyer(params["buyer"]),
|
||||
{:ok, policy_details} <- parse_policy_details(policy_type, params["policy_details"]),
|
||||
{:ok, insured_object} <- parse_insured_object(policy_type, params["insured_object"]),
|
||||
{:ok, providers} <- parse_providers(params["selected_providers"]) do
|
||||
command =
|
||||
case policy_type do
|
||||
@@ -105,7 +105,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
submitted_by: submitted_by,
|
||||
insured: insured,
|
||||
buyer: buyer,
|
||||
policy_details: policy_details,
|
||||
insured_object: insured_object,
|
||||
selected_providers: providers
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
submitted_by: submitted_by,
|
||||
insured: insured,
|
||||
buyer: buyer,
|
||||
policy_details: policy_details,
|
||||
insured_object: insured_object,
|
||||
selected_providers: providers
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
submitted_by: submitted_by,
|
||||
insured: insured,
|
||||
buyer: buyer,
|
||||
policy_details: policy_details,
|
||||
insured_object: insured_object,
|
||||
selected_providers: providers
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
submitted_by: submitted_by,
|
||||
insured: insured,
|
||||
buyer: buyer,
|
||||
policy_details: policy_details,
|
||||
insured_object: insured_object,
|
||||
selected_providers: providers
|
||||
}
|
||||
end
|
||||
@@ -235,7 +235,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
status: p.status,
|
||||
insured: p.insured,
|
||||
buyer: p.buyer,
|
||||
policy_details: p.policy_details,
|
||||
insured_object: p.insured_object,
|
||||
provider_policy_number: p.provider_policy_number,
|
||||
submitted_at: p.submitted_at
|
||||
}
|
||||
@@ -250,7 +250,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
status: p.status,
|
||||
insured: p.insured,
|
||||
buyer: p.buyer,
|
||||
policy_details: p.policy_details,
|
||||
insured_object: p.insured_object,
|
||||
selected_providers: p.selected_providers,
|
||||
quotes: p.quotes,
|
||||
accepted_plan_id: p.accepted_plan_id,
|
||||
@@ -367,9 +367,9 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
# individual — has document_id
|
||||
|
||||
# car details
|
||||
defp parse_policy_details("car", nil), do: {:error, :missing_policy_details}
|
||||
defp parse_insured_object("car", nil), do: {:error, :missing_insured_object}
|
||||
|
||||
defp parse_policy_details("car", d) do
|
||||
defp parse_insured_object("car", d) do
|
||||
{:ok,
|
||||
%{
|
||||
"plate" => d["plate"],
|
||||
@@ -390,9 +390,9 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
end
|
||||
|
||||
# life details
|
||||
defp parse_policy_details("life", nil), do: {:error, :missing_policy_details}
|
||||
defp parse_insured_object("life", nil), do: {:error, :missing_insured_object}
|
||||
|
||||
defp parse_policy_details("life", d) do
|
||||
defp parse_insured_object("life", d) do
|
||||
{:ok,
|
||||
%{
|
||||
"coverage_type" => d["coverage_type"],
|
||||
@@ -407,9 +407,9 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
end
|
||||
|
||||
# fire_structure details
|
||||
defp parse_policy_details("fire_structure", nil), do: {:error, :missing_policy_details}
|
||||
defp parse_insured_object("fire_structure", nil), do: {:error, :missing_insured_object}
|
||||
|
||||
defp parse_policy_details("fire_structure", d) do
|
||||
defp parse_insured_object("fire_structure", d) do
|
||||
{:ok,
|
||||
%{
|
||||
"location" => d["location"],
|
||||
@@ -421,9 +421,9 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
end
|
||||
|
||||
# fire_contents details
|
||||
defp parse_policy_details("fire_contents", nil), do: {:error, :missing_policy_details}
|
||||
defp parse_insured_object("fire_contents", nil), do: {:error, :missing_insured_object}
|
||||
|
||||
defp parse_policy_details("fire_contents", d) do
|
||||
defp parse_insured_object("fire_contents", d) do
|
||||
{:ok,
|
||||
%{
|
||||
"location" => d["location"],
|
||||
@@ -434,7 +434,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
||||
}}
|
||||
end
|
||||
|
||||
defp parse_policy_details(_, _), do: {:error, :invalid_policy_details}
|
||||
defp parse_insured_object(_, _), do: {:error, :invalid_insured_object}
|
||||
|
||||
defp parse_providers(nil), do: {:error, :missing_providers}
|
||||
defp parse_providers([]), do: {:error, :no_providers_selected}
|
||||
|
||||
@@ -282,11 +282,11 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
||||
})
|
||||
end
|
||||
|
||||
defmodule PolicyDetails do
|
||||
defmodule InsuredObject do
|
||||
require OpenApiSpex
|
||||
|
||||
OpenApiSpex.schema(%{
|
||||
title: "PolicyDetails",
|
||||
title: "InsuredObject",
|
||||
oneOf: [
|
||||
CarPolicyDetails,
|
||||
LifePolicyDetails,
|
||||
@@ -356,16 +356,16 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
||||
OpenApiSpex.schema(%{
|
||||
title: "CreatePolicyRequest",
|
||||
type: :object,
|
||||
required: [:policy_type, :insured, :buyer, :policy_details, :selected_providers],
|
||||
required: [:policy_type, :insured, :buyer, :insured_object, :selected_providers],
|
||||
properties: %{
|
||||
policy_type: %Schema{
|
||||
type: :string,
|
||||
enum: ["car", "life", "fire_structure", "fire_contents"],
|
||||
description: "Determines the shape of policy_details"
|
||||
description: "Determines the shape of insured_object"
|
||||
},
|
||||
insured: Insured,
|
||||
buyer: Buyer,
|
||||
policy_details: PolicyDetails,
|
||||
insured_object: InsuredObject,
|
||||
selected_providers: %Schema{type: :array, items: SelectedProvider, minItems: 1}
|
||||
}
|
||||
})
|
||||
@@ -422,7 +422,7 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
||||
},
|
||||
insured: Insured,
|
||||
buyer: Buyer,
|
||||
policy_details: PolicyDetails,
|
||||
insured_object: InsuredObject,
|
||||
provider_policy_number: %Schema{type: :string, nullable: true},
|
||||
submitted_at: %Schema{type: :string, format: :"date-time"}
|
||||
}
|
||||
@@ -449,7 +449,7 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
||||
},
|
||||
insured: Insured,
|
||||
buyer: Buyer,
|
||||
policy_details: PolicyDetails,
|
||||
insured_object: InsuredObject,
|
||||
selected_providers: %Schema{type: :array, items: %Schema{type: :string}},
|
||||
quotes: %Schema{type: :object, additionalProperties: QuoteData},
|
||||
accepted_plan_id: %Schema{type: :string, nullable: true},
|
||||
|
||||
@@ -16,8 +16,8 @@ defmodule PolicyService.Repo.Migrations.CreatePolicyApplications do
|
||||
# Buyer — full map, shape varies by individual vs corporate
|
||||
add :buyer, :map, default: %{}
|
||||
|
||||
# Policy-type-specific details — shape varies by policy_type
|
||||
add :policy_details, :map, default: %{}
|
||||
# Insured object — policy-type-specific details, shape varies by policy_type
|
||||
add :insured_object, :map, default: %{}
|
||||
|
||||
# Providers + quotes
|
||||
add :selected_providers, {:array, :string}, default: []
|
||||
|
||||
Reference in New Issue
Block a user