Add /api/collection endpoint

This commit is contained in:
Claudio Ortolina
2025-03-10 11:17:51 +00:00
parent bd9f88ab02
commit 3d0eec3bff
4 changed files with 67 additions and 0 deletions
@@ -2,7 +2,21 @@ defmodule MusicLibraryWeb.CollectionJSON do
use MusicLibraryWeb, :json
def show(%{record: record}) do
record(record)
end
def index(%{records: records, total: total, limit: limit, offset: offset}) do
%{
total: total,
limit: limit,
offset: offset,
records: Enum.map(records, &record/1)
}
end
defp record(record) do
%{
id: record.id,
artists: Enum.map(record.artists, & &1.name),
title: record.title,
cover_url: url(~p"/api/covers/#{record.id}?#{[vsn: record.cover_hash]}"),