aboutsummaryrefslogtreecommitdiff
path: root/internal/gallery/query_photos.go
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-07-22 17:32:55 +0530
committerGitHub <noreply@github.com>2026-07-22 17:32:55 +0530
commit9b541ca2d0a639eebd9610fcd6385e841da68e0a (patch)
treed331e8d858f62cf82d0cb6c3ca96400d4e28edca /internal/gallery/query_photos.go
parent46d2bf8bb5a0d18bdbe613a9346a5757b39e0a35 (diff)
parentddd8a37a0eb5623960e4528802263c7cec23af87 (diff)
downloadgalleryd-9b541ca2d0a639eebd9610fcd6385e841da68e0a.tar.xz
galleryd-9b541ca2d0a639eebd9610fcd6385e841da68e0a.zip
Merge pull request #13 from RanXom/feat/api
Feat/api: add sorting support to gallery queries
Diffstat (limited to 'internal/gallery/query_photos.go')
-rw-r--r--internal/gallery/query_photos.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/gallery/query_photos.go b/internal/gallery/query_photos.go
new file mode 100644
index 0000000..e024090
--- /dev/null
+++ b/internal/gallery/query_photos.go
@@ -0,0 +1,24 @@
+package gallery
+
+func QueryPhotos(
+ photos []Photo,
+ query Query,
+) []Photo {
+ if query.Sort != "" {
+ photos = append([]Photo(nil), photos...)
+
+ sortQueryPhotos(photos, query)
+ }
+
+ if query.Offset >= len(photos) {
+ return []Photo{}
+ }
+
+ photos = photos[query.Offset:]
+
+ if query.Limit == 0 || query.Limit >= len(photos) {
+ return photos
+ }
+
+ return photos[:query.Limit]
+}