Add /api/collection/on_this_day endpoint
This commit is contained in:
@@ -15,6 +15,18 @@ defmodule MusicLibraryWeb.CollectionController do
|
||||
render(conn, :show, record: random_record)
|
||||
end
|
||||
|
||||
def on_this_day(conn, params) do
|
||||
current_date =
|
||||
case Map.get(params, "date") do
|
||||
nil -> Date.utc_today()
|
||||
date_string -> Date.from_iso8601!(date_string)
|
||||
end
|
||||
|
||||
records_on_this_day = Collection.get_records_on_this_day(current_date)
|
||||
|
||||
render(conn, :on_this_day, records: records_on_this_day)
|
||||
end
|
||||
|
||||
def index(conn, params) do
|
||||
limit =
|
||||
params
|
||||
|
||||
@@ -16,6 +16,12 @@ defmodule MusicLibraryWeb.CollectionJSON do
|
||||
}
|
||||
end
|
||||
|
||||
def on_this_day(%{records: records}) do
|
||||
%{
|
||||
records: Enum.map(records, &record/1)
|
||||
}
|
||||
end
|
||||
|
||||
defp record(record) do
|
||||
%{
|
||||
id: record.id,
|
||||
|
||||
@@ -84,6 +84,7 @@ defmodule MusicLibraryWeb.Router do
|
||||
|
||||
get "/collection/latest", CollectionController, :latest
|
||||
get "/collection/random", CollectionController, :random
|
||||
get "/collection/on_this_day", CollectionController, :on_this_day
|
||||
get "/collection", CollectionController, :index
|
||||
get "/assets/:transform_payload", AssetController, :show
|
||||
get "/backup", ArchiveController, :backup
|
||||
|
||||
Reference in New Issue
Block a user