diff options
Diffstat (limited to 'internal/gallery/query_photos.go')
| -rw-r--r-- | internal/gallery/query_photos.go | 24 |
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] +} |