Display latest purchase in stats page

This commit is contained in:
Claudio Ortolina
2024-10-19 19:46:39 +01:00
parent 36333112a4
commit 28609dcf87
3 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -99,7 +99,7 @@ defmodule MusicLibrary.Records do
def get_latest_record! do def get_latest_record! do
q = q =
from r in Record, from r in Record,
order_by: [desc: r.inserted_at], order_by: [desc: r.purchased_at],
limit: 1, limit: 1,
select: ^@fields select: ^@fields
@@ -42,7 +42,7 @@ defmodule MusicLibraryWeb.StatsControllerTest do
end end
test "it shows the latest record", %{conn: conn, records: records} do test "it shows the latest record", %{conn: conn, records: records} do
latest_record = Enum.max_by(records, & &1.inserted_at) latest_record = Enum.max_by(records, & &1.purchased_at)
conn = get(conn, "/") conn = get(conn, "/")
@@ -50,6 +50,7 @@ defmodule MusicLibrary.RecordsFixtures do
def record_fixture(attrs \\ %{}) do def record_fixture(attrs \\ %{}) do
record_musicbrainz_id = Ecto.UUID.generate() record_musicbrainz_id = Ecto.UUID.generate()
artist_name = Enum.random(@artists) artist_name = Enum.random(@artists)
current_time = DateTime.utc_now()
artists_attrs = [ artists_attrs = [
%{ %{
@@ -71,6 +72,7 @@ defmodule MusicLibrary.RecordsFixtures do
type: :album, type: :album,
format: Record.formats() |> Enum.random(), format: Record.formats() |> Enum.random(),
release: Enum.random(1969..2024) |> Integer.to_string(), release: Enum.random(1969..2024) |> Integer.to_string(),
purchased_at: current_time,
artists: artists_attrs artists: artists_attrs
}) })
|> MusicLibrary.Records.create_record() |> MusicLibrary.Records.create_record()