fp/services/bright/lib/bright_web/controllers/url_json.ex

26 lines
394 B
Elixir
Raw Normal View History

2025-01-03 14:45:35 +00:00
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