Include artists and cover in latest record JSON
This commit is contained in:
@@ -50,6 +50,12 @@ defmodule MusicLibraryWeb do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def json do
|
||||||
|
quote do
|
||||||
|
unquote(verified_routes())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def live_view do
|
def live_view do
|
||||||
quote do
|
quote do
|
||||||
use Phoenix.LiveView,
|
use Phoenix.LiveView,
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
defmodule MusicLibraryWeb.CollectionJSON do
|
defmodule MusicLibraryWeb.CollectionJSON do
|
||||||
|
use MusicLibraryWeb, :json
|
||||||
|
|
||||||
def show(%{record: record}) do
|
def show(%{record: record}) do
|
||||||
Map.take(record, [:title])
|
%{
|
||||||
|
artists: Enum.map(record.artists, & &1.name),
|
||||||
|
title: record.title,
|
||||||
|
cover_url: url(~p"/covers/#{record.id}?#{[vsn: record.cover_hash]}")
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
import MusicLibrary.RecordsFixtures
|
import MusicLibrary.RecordsFixtures
|
||||||
|
|
||||||
defp create_record(_) do
|
defp create_record(_) do
|
||||||
%{record: record_fixture()}
|
%{record: record_fixture_with_artist("Steven Wilson")}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /api/collection/latest" do
|
describe "GET /api/collection/latest" do
|
||||||
@@ -12,7 +12,12 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
|
|
||||||
test "it returns the latest record", %{conn: conn, record: record} do
|
test "it returns the latest record", %{conn: conn, record: record} do
|
||||||
conn = get(conn, ~p"/api/collection/latest")
|
conn = get(conn, ~p"/api/collection/latest")
|
||||||
assert json_response(conn, 200) == %{"title" => record.title}
|
|
||||||
|
assert json_response(conn, 200) == %{
|
||||||
|
"artists" => ["Steven Wilson"],
|
||||||
|
"title" => record.title,
|
||||||
|
"cover_url" => "http://localhost:4002/covers/#{record.id}?vsn=#{record.cover_hash}"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user