Add scenes filter to galleries (#4840)

This commit is contained in:
bob123491234
2024-05-19 22:04:45 -05:00
committed by GitHub
parent 769540be55
commit 3e3e8b95e2
10 changed files with 51 additions and 1 deletions

View File

@@ -27,6 +27,8 @@ type GalleryFilterType struct {
AverageResolution *ResolutionCriterionInput `json:"average_resolution"`
// Filter to only include scenes which have chapters. `true` or `false`
HasChapters *string `json:"has_chapters"`
// Filter to only include galleries with these scenes
Scenes *MultiCriterionInput `json:"scenes"`
// Filter to only include galleries with this studio
Studios *HierarchicalMultiCriterionInput `json:"studios"`
// Filter to only include galleries with these tags

View File

@@ -1034,7 +1034,7 @@ type TagQueryInput struct {
// Filter to search name - assumes like query unless quoted
Name *string `json:"name,omitempty"`
// Filter to category ID
IsFavorite *bool `json:"is_favorite,omitempty"`
IsFavorite *bool `json:"is_favorite,omitempty"`
CategoryID *string `json:"category_id,omitempty"`
Page int `json:"page"`
PerPage int `json:"per_page"`

View File

@@ -699,6 +699,7 @@ func (qb *GalleryStore) makeFilter(ctx context.Context, galleryFilter *models.Ga
query.handleCriterion(ctx, galleryPerformersCriterionHandler(qb, galleryFilter.Performers))
query.handleCriterion(ctx, galleryPerformerCountCriterionHandler(qb, galleryFilter.PerformerCount))
query.handleCriterion(ctx, hasChaptersCriterionHandler(galleryFilter.HasChapters))
query.handleCriterion(ctx, galleryScenesCriterionHandler(qb, galleryFilter.Scenes))
query.handleCriterion(ctx, studioCriterionHandler(galleryTable, galleryFilter.Studios))
query.handleCriterion(ctx, galleryPerformerTagsCriterionHandler(qb, galleryFilter.PerformerTags))
query.handleCriterion(ctx, galleryAverageResolutionCriterionHandler(qb, galleryFilter.AverageResolution))
@@ -827,6 +828,17 @@ func galleryURLsCriterionHandler(url *models.StringCriterionInput) criterionHand
return h.handler(url)
}
func (qb *GalleryStore) getMultiCriterionHandlerBuilder(foreignTable, joinTable, foreignFK string, addJoinsFunc func(f *filterBuilder)) multiCriterionHandlerBuilder {
return multiCriterionHandlerBuilder{
primaryTable: galleryTable,
foreignTable: foreignTable,
joinTable: joinTable,
primaryFK: galleryIDColumn,
foreignFK: foreignFK,
addJoinsFunc: addJoinsFunc,
}
}
func (qb *GalleryStore) galleryPathCriterionHandler(c *models.StringCriterionInput) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if c != nil {
@@ -958,6 +970,15 @@ func galleryTagCountCriterionHandler(qb *GalleryStore, tagCount *models.IntCrite
return h.handler(tagCount)
}
func galleryScenesCriterionHandler(qb *GalleryStore, scenes *models.MultiCriterionInput) criterionHandlerFunc {
addJoinsFunc := func(f *filterBuilder) {
qb.scenesRepository().join(f, "", "galleries.id")
f.addLeftJoin("scenes", "", "scenes_galleries.scene_id = scenes.id")
}
h := qb.getMultiCriterionHandlerBuilder(sceneTable, galleriesScenesTable, "scene_id", addJoinsFunc)
return h.handler(scenes)
}
func galleryPerformersCriterionHandler(qb *GalleryStore, performers *models.MultiCriterionInput) criterionHandlerFunc {
h := joinedMultiCriterionHandlerBuilder{
primaryTable: galleryTable,