Skip to content

Instantly share code, notes, and snippets.

@polvalente
Created July 17, 2019 18:50
Show Gist options
  • Save polvalente/71290e04fde939a227b824b6f1e149c3 to your computer and use it in GitHub Desktop.
Save polvalente/71290e04fde939a227b824b6f1e149c3 to your computer and use it in GitHub Desktop.
bla
defmodule Web.CardParams do
defstruct holder_name: "name",
last_digits: "1234",
address: %Web.AddressParams{street: "rua dos bobos", number: "zero"}
@enforce_keys [:holder_name, :last_digits, :address]
# esse cara aqui pra mim é problemático
# Ou você continua dependendo do Core.Address
# ou você tem que tirar o nome da struct e passar um map
def to_domain(%__MODULE__{
holder_name: name,
last_digits: digits,
address: %Web.AddressParams{street: street, number: zero}
}) do
Core.CardSchema{
holder_name: name,
last_digits: digits,
address: %Core.Address{
street: street,
number: zero,
extra: ""
}
}
end
# Aqui, você só precisa definir o mapeamento no próprio tipo da web
def to_domain(def to_domain(%__MODULE__{
holder_name: name,
last_digits: digits,
address: %Web.AdressParams{} = address
}) do
Core.CardSchema{
holder_name: name,
last_digits: digits,
address: Web.AddressParams.to_domain(address)
}
end)
end
defmodule Web.AddressParams do
defstruct [:street, :number]
@enforce_keys [:street, :number]
def to_domain(%__MODULE__{street: street, number: number}) do
%Core.Address{
street: street,
number: number,
extra: ""
}
end
end
defmodule Core.Address do
defstruct [:street, :number, :extra]
@enforce_keys [:street, :number, :extra]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment