This commit is contained in:
51
lib/customer_service/aggregates/corporate_customer.ex
Normal file
51
lib/customer_service/aggregates/corporate_customer.ex
Normal file
@@ -0,0 +1,51 @@
|
||||
defmodule CustomerService.Aggregates.CorporateCustomer do
|
||||
defstruct [
|
||||
:id,
|
||||
:legal_name,
|
||||
:commercial_name,
|
||||
:ruc,
|
||||
:legal_rep_name,
|
||||
:legal_rep_document_id,
|
||||
:email,
|
||||
:phone,
|
||||
:address
|
||||
]
|
||||
|
||||
alias __MODULE__
|
||||
alias Commanded.Aggregates.Aggregate
|
||||
alias CustomerService.Commands
|
||||
alias CustomerService.Events
|
||||
|
||||
@behaviour Aggregate
|
||||
|
||||
@impl Aggregate
|
||||
def execute(%CorporateCustomer{id: nil}, %Commands.CreateCorporateCustomer{} = cmd) do
|
||||
%Events.CorporateCustomerCreated{
|
||||
id: cmd.id,
|
||||
legal_name: cmd.legal_name,
|
||||
commercial_name: cmd.commercial_name,
|
||||
ruc: cmd.ruc,
|
||||
legal_rep_name: cmd.legal_rep_name,
|
||||
legal_rep_document_id: cmd.legal_rep_document_id,
|
||||
email: cmd.email,
|
||||
phone: cmd.phone,
|
||||
address: cmd.address
|
||||
}
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def apply(%CorporateCustomer{} = c, %Events.CorporateCustomerCreated{} = e) do
|
||||
%CorporateCustomer{
|
||||
c
|
||||
| id: e.id,
|
||||
legal_name: e.legal_name,
|
||||
commercial_name: e.commercial_name,
|
||||
ruc: e.ruc,
|
||||
legal_rep_name: e.legal_rep_name,
|
||||
legal_rep_document_id: e.legal_rep_document_id,
|
||||
email: e.email,
|
||||
phone: e.phone,
|
||||
address: e.address
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,9 @@ defmodule CustomerService.Aggregates.Customer do
|
||||
:birth_date,
|
||||
:gender,
|
||||
:email,
|
||||
:phone
|
||||
:phone,
|
||||
:address,
|
||||
:document_id
|
||||
]
|
||||
|
||||
alias __MODULE__
|
||||
@@ -24,13 +26,15 @@ defmodule CustomerService.Aggregates.Customer do
|
||||
birth_date: cmd.birth_date,
|
||||
gender: cmd.gender,
|
||||
email: cmd.email,
|
||||
phone: cmd.phone
|
||||
phone: cmd.phone,
|
||||
document_id: cmd.document_id,
|
||||
address: cmd.address
|
||||
}
|
||||
end
|
||||
|
||||
@impl Aggregate
|
||||
def apply(%Customer{} = c, %Events.CustomerCreated{} = e) do
|
||||
%Customer{
|
||||
%__MODULE__{
|
||||
c
|
||||
| id: e.id,
|
||||
first_name: e.first_name,
|
||||
@@ -38,7 +42,9 @@ defmodule CustomerService.Aggregates.Customer do
|
||||
birth_date: e.birth_date,
|
||||
gender: e.gender,
|
||||
email: e.email,
|
||||
phone: e.phone
|
||||
phone: e.phone,
|
||||
address: e.address,
|
||||
document_id: e.document_id
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user