Order gallery images by path (#2390)

This commit is contained in:
WithoutPants 2022-03-20 17:51:02 +11:00 committed by GitHub
parent 6ceb9c73dd
commit e4ad42caf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -26,7 +26,10 @@ func (r *galleryResolver) Title(ctx context.Context, obj *models.Gallery) (*stri
func (r *galleryResolver) Images(ctx context.Context, obj *models.Gallery) (ret []*models.Image, err error) {
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
var err error
ret, err = repo.Image().FindByGalleryID(obj.ID)
// #2376 - sort images by path
ret, err = image.FindByGalleryID(repo.Image(), obj.ID, "path", models.SortDirectionEnumAsc)
return err
}); err != nil {
return nil, err
@ -37,7 +40,7 @@ func (r *galleryResolver) Images(ctx context.Context, obj *models.Gallery) (ret
func (r *galleryResolver) Cover(ctx context.Context, obj *models.Gallery) (ret *models.Image, err error) {
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
imgs, err := repo.Image().FindByGalleryID(obj.ID)
imgs, err := image.FindByGalleryID(repo.Image(), obj.ID, "", "")
if err != nil {
return err
}

View File

@ -68,3 +68,26 @@ func CountByTagID(r models.ImageReader, id int) (int, error) {
return r.QueryCount(filter, nil)
}
func FindByGalleryID(r models.ImageReader, galleryID int, sortBy string, sortDir models.SortDirectionEnum) ([]*models.Image, error) {
perPage := -1
findFilter := models.FindFilterType{
PerPage: &perPage,
}
if sortBy != "" {
findFilter.Sort = &sortBy
}
if sortDir.IsValid() {
findFilter.Direction = &sortDir
}
return Query(r, &models.ImageFilterType{
Galleries: &models.MultiCriterionInput{
Value: []string{strconv.Itoa(galleryID)},
Modifier: models.CriterionModifierIncludes,
},
}, &findFilter)
}