From 41ad7da084544b3b8eea5b009cc3cab652988b8d Mon Sep 17 00:00:00 2001 From: RanXom Date: Fri, 17 Jul 2026 22:05:17 +0530 Subject: feat(gallery): add sorting options to queries --- internal/gallery/query.go | 18 ++++++++++++++++++ internal/gallery/query_photos_test.go | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'internal') diff --git a/internal/gallery/query.go b/internal/gallery/query.go index fd11762..f528906 100644 --- a/internal/gallery/query.go +++ b/internal/gallery/query.go @@ -1,9 +1,27 @@ package gallery +type SortField string + +const ( + SortByDateTime SortField = "dateTaken" + SortByPath SortField = "path" +) + +// SortOrder identifies the sort direction +type SortOrder string + +const ( + SortAsc SortOrder = "asc" + SortDesc SortOrder = "desc" +) + // Query describes how photos should be selected. // // The zero value returns the entire gallery. type Query struct { Limit int Offset int + + Sort SortField + Order SortOrder } diff --git a/internal/gallery/query_photos_test.go b/internal/gallery/query_photos_test.go index 45e7149..d5a25d0 100644 --- a/internal/gallery/query_photos_test.go +++ b/internal/gallery/query_photos_test.go @@ -122,4 +122,21 @@ func TestQueryPhotos(t *testing.T) { "5", "6", "7", "8", "9", ) }) + + t.Run("ignores sorting for now", func(t *testing.T) { + got := QueryPhotos( + photos, + Query{ + Sort: SortByPath, + Order: SortAsc, + }, + ) + + assertIDs( + t, + got, + "0", "1", "2", "3", "4", + "5", "6", "7", "8", "9", + ) + }) } -- cgit v1.2.3