partition by org_id and add auth
All checks were successful
Build and Publish / build-release (push) Successful in 3m7s
All checks were successful
Build and Publish / build-release (push) Successful in 3m7s
This commit is contained in:
39
lib/customer_service/aggregates/lead_id.ex
Normal file
39
lib/customer_service/aggregates/lead_id.ex
Normal file
@@ -0,0 +1,39 @@
|
||||
defmodule CustomerService.Aggregates.LeadId do
|
||||
@type t :: %__MODULE__{
|
||||
org_id: String.t(),
|
||||
type: String.t(),
|
||||
lead_id: String.t()
|
||||
}
|
||||
@derive {Jason.Encoder, only: [: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
|
||||
%__MODULE__{
|
||||
org_id: org_id,
|
||||
type: "lead",
|
||||
lead_id: lead_id
|
||||
}
|
||||
end
|
||||
|
||||
def parse(<<_::binary>> = string) do
|
||||
case String.split(string, ":", parts: 3) do
|
||||
[org_id, "lead", lead_id] ->
|
||||
{:ok, %__MODULE__{org_id: org_id, type: "lead", lead_id: lead_id}}
|
||||
|
||||
_ ->
|
||||
{:error, :invalid_lead_id}
|
||||
end
|
||||
end
|
||||
|
||||
def to_string(%__MODULE__{org_id: org_id, type: "lead", lead_id: lead_id}) do
|
||||
org_id <> ":" <> "lead" <> ":" <> lead_id
|
||||
end
|
||||
|
||||
defimpl Commanded.Serialization.JsonDecoder do
|
||||
def decode(%{org_id: org_id, type: "lead", lead_id: lead_id}) do
|
||||
CustomerService.Aggregates.LeadId.new(org_id, lead_id)
|
||||
end
|
||||
|
||||
def decode(id), do: id
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user