zoeys.computer/lib/zoeyscomputer_web/controllers/gist_json.ex
2024-10-26 23:30:25 -04:00

28 lines
505 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,
author_id: gist.author_id,
desc: gist.desc,
title: gist.title
}
end
end