From 1d430f5707b7aeaede9bf3abb50c69fb18421476 Mon Sep 17 00:00:00 2001 From: summersamara Date: Wed, 20 Dec 2023 00:25:38 +0100 Subject: [PATCH] Supply sort and direction as arguments to list_public_local_events instead of hardcoding https://git.potsda.mn/potsda.mn/mobilizon/issues/37 --- lib/mobilizon/events/events.ex | 8 ++++---- lib/service/export/common.ex | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 9fa01246f..403d7fdf0 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -387,15 +387,15 @@ defmodule Mobilizon.Events do |> Repo.stream() end - @spec list_public_local_events(integer | nil, integer | nil) :: Page.t(Event.t()) - def list_public_local_events(page \\ nil, limit \\ nil) do + @spec list_public_local_events(integer | nil, integer | nil, atom | nil, atom | nil) :: Page.t(Event.t()) + def list_public_local_events(page \\ nil, limit \\ nil, sort \\ nil, direction \\ nil) do Event |> filter_public_visibility() |> filter_draft() |> filter_local() |> preload_for_event() - |> order_by(desc: :begins_on) - |> Page.build_page(page, limit, :begins_on) + |> event_order_by(sort, direction) + |> Page.build_page(page, limit) end @doc """ diff --git a/lib/service/export/common.ex b/lib/service/export/common.ex index 14da864de..9f3175642 100644 --- a/lib/service/export/common.ex +++ b/lib/service/export/common.ex @@ -96,7 +96,7 @@ defmodule Mobilizon.Service.Export.Common do @spec fetch_instance_public_content(integer()) :: {:ok, list(Event.t()), list(Post.t())} def fetch_instance_public_content(limit) do - %Page{elements: events} = Events.list_public_local_events(1, limit) + %Page{elements: events} = Events.list_public_local_events(1, limit, :begins_on, :desc) %Page{elements: posts} = Posts.list_public_local_posts(1, limit) {:ok, events, posts} end