defmodule ZoeyscomputerWeb.GistJSON do alias Zoeyscomputer.Gists.Gist @doc """ Renders a list of gists. """ def index(%{gists: gists}) do %{data: for(gist <- gists, do: data(gist))} end @doc """ Renders a single gist. """ def show(%{gist: gist}) do %{data: data(gist)} end defp data(%Gist{} = gist) do %{ id: gist.id, code: gist.code, lang: gist.lang, author_id: gist.author_id, desc: gist.desc, title: gist.title } end end