Can filter collection records by purchase year

This commit is contained in:
Claudio Ortolina
2025-10-31 12:25:10 +00:00
parent 9b15ef587a
commit fcd558066e
2 changed files with 25 additions and 2 deletions
+15 -1
View File
@@ -61,7 +61,8 @@ defmodule MusicLibrary.Records do
end
defp build_search(initial_search, query, order \\ :alphabetical) do
{:ok, parsed_query} = SearchParser.parse(query)
{:ok, parsed_query} =
SearchParser.parse(query)
search_with_order =
case order do
@@ -121,6 +122,19 @@ defmodule MusicLibrary.Records do
{:type, type}, search ->
search |> where([r], r.type == ^type)
{:purchase_year, year}, search ->
search
|> where(
[r],
fragment(
"? >= ? and ? < ?",
r.purchased_at,
^to_string(year),
r.purchased_at,
^to_string(year + 1)
)
)
{:query, ""}, search ->
search