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/offers.ex

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