26 lines
737 B
Elixir
26 lines
737 B
Elixir
defmodule DediboxPrices.Entities.Offers do
|
|
@moduledoc """
|
|
The module generate new DediboxPrices.Offer that can be saved
|
|
"""
|
|
alias DediboxPrices.Entities.Offer
|
|
use EctoCrux, module: Offer
|
|
|
|
def create_all_entities(offers) do
|
|
offers
|
|
|> Enum.map(fn offer ->
|
|
offer
|
|
|> Map.from_struct()
|
|
|> create()
|
|
end)
|
|
|> Enum.filter(fn value -> elem(value, 0) == :ok end)
|
|
|> Enum.map(fn value -> elem(value, 1) end)
|
|
end
|
|
|
|
import Ecto.Query, only: [from: 2]
|
|
def most_recents do
|
|
# TODO understand how to do this properly, it looks like a dirty hack
|
|
repo = Ecto.Repo.all_running() |> Enum.at(0)
|
|
(from offer in Offer, order_by: [desc: offer.inserted_at], distinct: :name) |> repo.all
|
|
end
|
|
end
|