This repository has been archived on 2022-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
dedibox_prices/lib/dedibox_prices/entities/offer.ex

49 lines
1.0 KiB
Elixir

defmodule DediboxPrices.Entities.Offer do
use DediboxPrices.Schema
import Ecto.Changeset
@required_fields [
:name,
:tag,
:cpu,
:memory,
:disk_amount,
:disk_size,
:disk_properties,
:bandwith,
:rpn,
:disponibility,
:price
]
@optional_fields []
# @derive {Jason.Encoder, only: [:name, :price, :memory, :disponibility, :inserted_at]}
# @derive Jason.Encoder
schema "offers" do
field :bandwith, :integer
field :cpu, :string
field :disk_amount, :integer
field :disk_properties, :string
field :disk_size, :integer
field :disponibility, :integer
field :memory, :integer
field :name, :string
field :price, :float
field :rpn, :string
field :tag, :string
timestamps()
end
def as_json(offer) do
offer |> Map.from_struct |> Map.reject(fn {k, v} -> k == :__meta__ end)
end
@doc false
def changeset(offer, attrs) do
offer
|> cast(attrs, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
end
end