From 99ccfb81d7108b06d3e1c8c70bf0cf7ce9a61d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Veikko=20Lintuj=C3=A4rvi?= Date: Sun, 25 Jun 2023 22:17:27 +0300 Subject: [PATCH] Sort yield list by date descending --- lib/osuuspuutarha/harvest.ex | 4 ++++ lib/osuuspuutarha_web/live/yield_live/index.ex | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/osuuspuutarha/harvest.ex b/lib/osuuspuutarha/harvest.ex index 959e438..c25795a 100644 --- a/lib/osuuspuutarha/harvest.ex +++ b/lib/osuuspuutarha/harvest.ex @@ -21,6 +21,10 @@ defmodule Osuuspuutarha.Harvest do Repo.all(Yield) end + def get_sorted_by_date do + Repo.all(Yield |> order_by({:desc, :date})) + end + @doc """ Gets a single yield. diff --git a/lib/osuuspuutarha_web/live/yield_live/index.ex b/lib/osuuspuutarha_web/live/yield_live/index.ex index 251331d..bd5c056 100644 --- a/lib/osuuspuutarha_web/live/yield_live/index.ex +++ b/lib/osuuspuutarha_web/live/yield_live/index.ex @@ -41,6 +41,6 @@ defmodule OsuuspuutarhaWeb.YieldLive.Index do end defp list_yields do - Harvest.list_yields() + Harvest.get_sorted_by_date() end end