Return more record information in the API
This commit is contained in:
@@ -25,6 +25,12 @@ defmodule MusicLibraryWeb.CollectionJSON do
|
|||||||
defp record(record) do
|
defp record(record) do
|
||||||
%{
|
%{
|
||||||
id: record.id,
|
id: record.id,
|
||||||
|
type: record.type,
|
||||||
|
format: record.format,
|
||||||
|
musicbrainz_id: record.musicbrainz_id,
|
||||||
|
genres: record.genres,
|
||||||
|
release_date: record.release_date,
|
||||||
|
purchased_at: record.purchased_at,
|
||||||
artists: Enum.map(record.artists, & &1.name),
|
artists: Enum.map(record.artists, & &1.name),
|
||||||
title: record.title,
|
title: record.title,
|
||||||
cover_url: url(~p"/api/assets/#{Transform.new(hash: record.cover_hash)}"),
|
cover_url: url(~p"/api/assets/#{Transform.new(hash: record.cover_hash)}"),
|
||||||
|
|||||||
@@ -27,15 +27,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
|> put_req_header("authorization", "Bearer #{api_token()}")
|
|> put_req_header("authorization", "Bearer #{api_token()}")
|
||||||
|> get(~p"/api/collection/latest")
|
|> get(~p"/api/collection/latest")
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response(conn, 200) == expected_record_json(record)
|
||||||
"id" => record.id,
|
|
||||||
"artists" => ["Steven Wilson"],
|
|
||||||
"title" => record.title,
|
|
||||||
"cover_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
|
||||||
"thumb_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,15 +47,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
|> put_req_header("authorization", "Bearer #{api_token()}")
|
|> put_req_header("authorization", "Bearer #{api_token()}")
|
||||||
|> get(~p"/api/collection/random")
|
|> get(~p"/api/collection/random")
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response(conn, 200) == expected_record_json(record)
|
||||||
"id" => record.id,
|
|
||||||
"artists" => ["Steven Wilson"],
|
|
||||||
"title" => record.title,
|
|
||||||
"cover_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
|
||||||
"thumb_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,17 +70,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
"total" => 1,
|
"total" => 1,
|
||||||
"limit" => 20,
|
"limit" => 20,
|
||||||
"offset" => 0,
|
"offset" => 0,
|
||||||
"records" => [
|
"records" => [expected_record_json(record)]
|
||||||
%{
|
|
||||||
"id" => record.id,
|
|
||||||
"artists" => ["Steven Wilson"],
|
|
||||||
"title" => record.title,
|
|
||||||
"cover_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
|
||||||
"thumb_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -117,18 +91,26 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
|||||||
|> get(~p"/api/collection/on_this_day?date=2025-06-21")
|
|> get(~p"/api/collection/on_this_day?date=2025-06-21")
|
||||||
|
|
||||||
assert json_response(conn, 200) == %{
|
assert json_response(conn, 200) == %{
|
||||||
"records" => [
|
"records" => [expected_record_json(record)]
|
||||||
%{
|
|
||||||
"id" => record.id,
|
|
||||||
"artists" => ["Steven Wilson"],
|
|
||||||
"title" => record.title,
|
|
||||||
"cover_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
|
||||||
"thumb_url" =>
|
|
||||||
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp expected_record_json(record) do
|
||||||
|
%{
|
||||||
|
"id" => record.id,
|
||||||
|
"type" => record.type |> to_string(),
|
||||||
|
"format" => record.format |> to_string(),
|
||||||
|
"musicbrainz_id" => record.musicbrainz_id,
|
||||||
|
"genres" => record.genres,
|
||||||
|
"release_date" => record.release_date,
|
||||||
|
"purchased_at" => record.purchased_at |> DateTime.to_iso8601(),
|
||||||
|
"artists" => Enum.map(record.artists, & &1.name),
|
||||||
|
"title" => record.title,
|
||||||
|
"cover_url" =>
|
||||||
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
|
||||||
|
"thumb_url" =>
|
||||||
|
"http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user