defmodule BrightWeb.UrlJSON do alias Bright.Urls.Url @doc """ Renders a list of urls. """ def index(%{urls: urls}) do %{data: for(url <- urls, do: data(url))} end @doc """ Renders a single url. """ def show(%{url: url}) do %{data: data(url)} end defp data(%Url{} = url) do %{ id: url.id, link: url.link, title: url.title } end end