Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filtering by date to buildQuery #816

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/sqlx/querybuilder_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,32 @@ func (qb *sceneQueryBuilder) buildQuery(filter models.SceneQueryInput, userID uu
}
}

if q := filter.Date; q != nil {
column := "scenes.date"
switch q.Modifier {
case models.CriterionModifierEquals:
query.AddWhere(fmt.Sprintf("%s = ?", column))
query.AddArg(q.Value)
case models.CriterionModifierNotEquals:
query.AddWhere(fmt.Sprintf("%s != ?", column))
query.AddArg(q.Value)
case models.CriterionModifierGreaterThan:
query.AddWhere(fmt.Sprintf("%s > ?", column))
query.AddArg(q.Value)
case models.CriterionModifierLessThan:
query.AddWhere(fmt.Sprintf("%s < ?", column))
query.AddArg(q.Value)
case models.CriterionModifierIsNull:
query.AddWhere(fmt.Sprintf("%s IS NULL", column))
case models.CriterionModifierNotNull:
query.AddWhere(fmt.Sprintf("%s IS NOT NULL", column))
case models.CriterionModifierIncludesAll, models.CriterionModifierIncludes, models.CriterionModifierExcludes:
return nil, fmt.Errorf("unsupported modifier %s for scenes.date", q.Modifier)
default:
return nil, fmt.Errorf("unsupported modifier %s for scenes.date", q.Modifier)
}
}

if q := filter.Favorites; q != nil {
var clauses []string
if *q == models.FavoriteFilterPerformer || *q == models.FavoriteFilterAll {
Expand Down
Loading