Files
customer-service/lib/customer_service/aggregates/customer.ex
HaimKortovich b1b1c21e4e
Some checks failed
Build and Publish / build-release (push) Failing after 1s
init commit
2026-04-15 16:20:22 -05:00

51 lines
1.1 KiB
Elixir

defmodule CustomerService.Aggregates.Customer do
defstruct [
:id,
:first_name,
:last_name,
:birth_date,
:gender,
:email,
:phone,
:address,
:document_id
]
alias __MODULE__
alias Commanded.Aggregates.Aggregate
alias CustomerService.Commands
alias CustomerService.Events
@behaviour Aggregate
@impl Aggregate
def execute(%Customer{id: nil}, %Commands.CreateCustomer{} = cmd) do
%Events.CustomerCreated{
id: cmd.id,
first_name: cmd.first_name,
last_name: cmd.last_name,
birth_date: cmd.birth_date,
gender: cmd.gender,
email: cmd.email,
phone: cmd.phone,
document_id: cmd.document_id,
address: cmd.address
}
end
@impl Aggregate
def apply(%Customer{} = c, %Events.CustomerCreated{} = e) do
%__MODULE__{
c
| id: e.id,
first_name: e.first_name,
last_name: e.last_name,
birth_date: e.birth_date,
gender: e.gender,
email: e.email,
phone: e.phone,
address: e.address,
document_id: e.document_id
}
end
end