Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Created July 8, 2017 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/b9412937106ac7526898eff99718c87b to your computer and use it in GitHub Desktop.
Save shankardevy/b9412937106ac7526898eff99718c87b to your computer and use it in GitHub Desktop.
defmodule Mango.Catalog do
@moduledoc """
API boundary for the Catalog system.
"""
alias Mango.Catalog.Product
alias Mango.Repo
def get_product!(id), do: Product |> Repo.get!(id)
def list_products do
Product
|> Repo.all
end
def list_seasonal_products do
list_products()
|> Enum.filter(fn(product) -> product.is_seasonal == true end)
end
def get_category_products(name) do
list_products()
|> Enum.filter(fn(product) -> product.category == name end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment