Skip to content

Commit

Permalink
FIND-13264: Filter by enumerated properties
Browse files Browse the repository at this point in the history
- Remove incorrect function
  • Loading branch information
ManhOptimizely committed Oct 21, 2024
1 parent ec20618 commit 6b6050a
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 378 deletions.
65 changes: 65 additions & 0 deletions APIs/src/EpiServer.ContentGraph/Api/Filters/AndFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public AndFilter(Expression<Func<T, int>> fieldSelector, NumericFilterOperators
And(fieldSelector, filterOperators);
}
#endregion
#region Base type
public AndFilter<T> And(Expression<Func<T, string>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Expand All @@ -61,6 +62,12 @@ public AndFilter<T> And(Expression<Func<T, double?>> fieldSelector, IFilterOpera
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, float?>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, int>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Expand All @@ -73,6 +80,64 @@ public AndFilter<T> And(Expression<Func<T, bool>> fieldSelector, IFilterOperator
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
#endregion
#region Enumerable
public AndFilter<T> And(Expression<Func<T, IEnumerable<string>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter(Expression<Func<T, IEnumerable<string>>> fieldSelector, StringFilterOperators filterOperators)
{
And(fieldSelector, filterOperators);
}
public AndFilter<T> And(Expression<Func<T, IEnumerable<bool>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, IEnumerable<int>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, IEnumerable<double>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, IEnumerable<long>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, IEnumerable<float>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And(Expression<Func<T, IEnumerable<DateTime>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
And(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public AndFilter<T> And<TField>(Expression<Func<T, IEnumerable<TField>>> rootSelector,
Expression<Func<TField, object>> fieldSelector,
IFilterOperator filterOperator)
{
rootSelector.ValidateNotNullArgument("rootSelector");
fieldSelector.ValidateNotNullArgument("fieldSelector");
And($"{rootSelector.GetFieldPath()}.{fieldSelector.GetFieldPath()}", filterOperator);
return this;
}
#endregion
private AndFilter<T> And(Expression<Func<T, Filter>> fieldSelector)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Expand Down
63 changes: 63 additions & 0 deletions APIs/src/EpiServer.ContentGraph/Api/Filters/NotFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public NotFilter<T> Not(Expression<Func<T, double?>> fieldSelector, IFilterOpera
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, float?>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, DateTime?>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Expand Down Expand Up @@ -85,6 +91,63 @@ public NotFilter<T> Not(params Expression<Func<T, Filter>>[] fieldSelectors)
}
return this;
}
#region Enumerable
public NotFilter<T> Not(Expression<Func<T, IEnumerable<string>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter(Expression<Func<T, IEnumerable<string>>> fieldSelector, StringFilterOperators filterOperators)
{
Not(fieldSelector, filterOperators);
}
public NotFilter<T> Not(Expression<Func<T, IEnumerable<bool>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, IEnumerable<int>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, IEnumerable<double>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, IEnumerable<long>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, IEnumerable<float>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not(Expression<Func<T, IEnumerable<DateTime>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public NotFilter<T> Not<TField>(Expression<Func<T, IEnumerable<TField>>> rootSelector,
Expression<Func<TField, object>> fieldSelector,
IFilterOperator filterOperator)
{
rootSelector.ValidateNotNullArgument("rootSelector");
fieldSelector.ValidateNotNullArgument("fieldSelector");
Not($"{rootSelector.GetFieldPath()}.{fieldSelector.GetFieldPath()}", filterOperator);
return this;
}
#endregion
}

public class NotFilter : Filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ public NumericFilterOperators InRange(int? from, int? to)
}
return this;
}
public NumericFilterOperators InRanges(params (int? from, int? to)[] ranges)
{
foreach (var range in ranges)
{
InRange(range.from, range.to);
}
return this;
}

public NumericFilterOperators Eq(float value)
{
Expand Down Expand Up @@ -164,21 +156,5 @@ public NumericFilterOperators InRange(double? from, double? to)
}
return this;
}
public NumericFilterOperators InRanges(params (float? from, float? to)[] ranges)
{
foreach (var range in ranges)
{
InRange(range.from, range.to);
}
return this;
}
public NumericFilterOperators InRanges(params (double? from, double? to)[] ranges)
{
foreach (var range in ranges)
{
InRange(range.from, range.to);
}
return this;
}
}
}
63 changes: 63 additions & 0 deletions APIs/src/EpiServer.ContentGraph/Api/Filters/OrFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public OrFilter<T> Or(Expression<Func<T, long?>> fieldSelector, IFilterOperator
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Not(Expression<Func<T, float?>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or(Expression<Func<T, double?>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Expand Down Expand Up @@ -92,6 +98,63 @@ public OrFilter<T> Or(params Expression<Func<T, Filter>>[] fieldSelectors)
}
return this;
}
#region Enumerable
public OrFilter<T> Or(Expression<Func<T, IEnumerable<string>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter(Expression<Func<T, IEnumerable<string>>> fieldSelector, StringFilterOperators filterOperators)
{
Or(fieldSelector, filterOperators);
}
public OrFilter<T> Or(Expression<Func<T, IEnumerable<bool>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or(Expression<Func<T, IEnumerable<int>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or(Expression<Func<T, IEnumerable<double>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or(Expression<Func<T, IEnumerable<long>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or(Expression<Func<T, IEnumerable<float>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or(Expression<Func<T, IEnumerable<DateTime>>> fieldSelector, IFilterOperator filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or(fieldSelector.GetFieldPath(), filterOperator);
return this;
}
public OrFilter<T> Or<TField>(Expression<Func<T, IEnumerable<TField>>> rootSelector,
Expression<Func<TField, object>> fieldSelector,
IFilterOperator filterOperator)
{
rootSelector.ValidateNotNullArgument("rootSelector");
fieldSelector.ValidateNotNullArgument("fieldSelector");
Or($"{rootSelector.GetFieldPath()}.{fieldSelector.GetFieldPath()}", filterOperator);
return this;
}
#endregion
}

public class OrFilter : Filter
Expand Down
48 changes: 48 additions & 0 deletions APIs/src/EpiServer.ContentGraph/Api/Querying/TypeQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,54 @@ public TypeQueryBuilder<T> Where(Expression<Func<T, IEnumerable<long>>> fieldSel

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, int?>> fieldSelector, NumericFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
filterOperator.ValidateNotNullArgument("filterOperator");
Where(fieldSelector.GetFieldPath(), filterOperator);

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, IEnumerable<int>>> fieldSelector, NumericFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
filterOperator.ValidateNotNullArgument("filterOperator");
Where(fieldSelector.GetFieldPath(), filterOperator);

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, float?>> fieldSelector, NumericFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
filterOperator.ValidateNotNullArgument("filterOperator");
Where(fieldSelector.GetFieldPath(), filterOperator);

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, IEnumerable<float>>> fieldSelector, NumericFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
filterOperator.ValidateNotNullArgument("filterOperator");
Where(fieldSelector.GetFieldPath(), filterOperator);

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, double?>> fieldSelector, NumericFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
filterOperator.ValidateNotNullArgument("filterOperator");
Where(fieldSelector.GetFieldPath(), filterOperator);

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, IEnumerable<double>>> fieldSelector, NumericFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
filterOperator.ValidateNotNullArgument("filterOperator");
Where(fieldSelector.GetFieldPath(), filterOperator);

return this;
}
public TypeQueryBuilder<T> Where(Expression<Func<T, string>> fieldSelector, DateFilterOperators filterOperator)
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
Expand Down
Loading

0 comments on commit 6b6050a

Please sign in to comment.