impl string.chars
Some checks failed
Build and Publish / build-release (push) Failing after 24s

This commit is contained in:
2026-05-15 13:29:03 -05:00
parent d2f67f1e04
commit ac114869be
2 changed files with 20 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ defmodule CustomerService.Aggregates.CustomerId do
customer_type: String.t(), customer_type: String.t(),
customer_id: String.t() customer_id: String.t()
} }
@derive {Jason.Encoder, only: [:org_id, :customer_type, :customer_id]} @derive Jason.Encoder
defstruct [:org_id, :customer_type, :customer_id] defstruct [:org_id, :customer_type, :customer_id]
def new(org_id, customer_type, customer_id) def new(org_id, customer_type, customer_id)
@@ -30,12 +30,14 @@ defmodule CustomerService.Aggregates.CustomerId do
{:error, :invalid_customer_id} {:error, :invalid_customer_id}
end end
def to_string(%__MODULE__{ defimpl String.Chars do
def to_string(%CustomerService.Aggregates.LeadId{
org_id: org_id, org_id: org_id,
customer_type: customer_type, customer_type: type,
customer_id: customer_id customer_id: customer_id
}) do }) do
org_id <> ":" <> customer_type <> ":" <> customer_id org_id <> ":" <> type <> ":" <> customer_id
end
end end
defimpl Commanded.Serialization.JsonDecoder do defimpl Commanded.Serialization.JsonDecoder do

View File

@@ -4,7 +4,7 @@ defmodule CustomerService.Aggregates.LeadId do
type: String.t(), type: String.t(),
lead_id: String.t() lead_id: String.t()
} }
@derive {Jason.Encoder, only: [:org_id, :type, :lead_id]} @derive Jason.Encoder
defstruct [:org_id, :type, :lead_id] defstruct [:org_id, :type, :lead_id]
def new(org_id, lead_id) when is_binary(org_id) and is_binary(lead_id) do def new(org_id, lead_id) when is_binary(org_id) and is_binary(lead_id) do
@@ -36,4 +36,14 @@ defmodule CustomerService.Aggregates.LeadId do
def decode(id), do: id def decode(id), do: id
end end
defimpl String.Chars do
def to_string(%CustomerService.Aggregates.LeadId{
org_id: org_id,
type: type,
lead_id: lead_id
}) do
org_id <> ":" <> type <> ":" <> lead_id
end
end
end end