zoeys.computer/lib/zoeyscomputer_web/controllers/gist_json.ex
2024-10-26 15:01:33 -04:00

25 lines
424 B
Elixir

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
}
end
end