Skip to content

Commit 2239d52

Browse files
committed
rename where to filter, refactor
1 parent ac8160a commit 2239d52

File tree

8 files changed

+123
-76
lines changed

8 files changed

+123
-76
lines changed

Kontent.Ai.Delivery.Abstractions/QueryBuilders/Filtering/IItemFilters.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,29 @@ public interface IItemFilters
3838
/// </summary>
3939
IFilter Range(IPropertyPath path, RangeTuple range);
4040
/// <summary>
41-
/// Retrieves items where the property specified by path is in the specified collection.
41+
/// Retrieves items where the property specified by path is in the specified collection of strings.
4242
/// </summary>
43-
IFilter In(IPropertyPath path, ScalarArray values);
43+
IFilter In(IPropertyPath path, string[] values);
4444
/// <summary>
45-
/// Retrieves items where the property specified by path is not in the specified collection.
45+
/// Retrieves items where the property specified by path is not in the specified collection of strings.
4646
/// </summary>
47-
IFilter NotIn(IPropertyPath path, ScalarArray values);
47+
IFilter NotIn(IPropertyPath path, string[] values);
48+
/// <summary>
49+
/// Retrieves items where the property specified by path is in the specified collection of numbers.
50+
/// </summary>
51+
IFilter In(IPropertyPath path, double[] values);
52+
/// <summary>
53+
/// Retrieves items where the property specified by path is not in the specified collection of numbers.
54+
/// </summary>
55+
IFilter NotIn(IPropertyPath path, double[] values);
56+
/// <summary>
57+
/// Retrieves items where the property specified by path is in the specified collection of dates.
58+
/// </summary>
59+
IFilter In(IPropertyPath path, System.DateTime[] values);
60+
/// <summary>
61+
/// Retrieves items where the property specified by path is not in the specified collection of dates.
62+
/// </summary>
63+
IFilter NotIn(IPropertyPath path, System.DateTime[] values);
4864
/// <summary>
4965
/// Retrieves items where the property specified by path contains the specified value.
5066
/// </summary>

Kontent.Ai.Delivery.Abstractions/QueryBuilders/Filtering/PropertyPaths.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IPropertyPath
1010
}
1111

1212
/// <summary>
13-
/// Strongly-typed system property path for content items.
13+
/// Strongly-typed system property path for content items. Implicitly converts to string.
1414
/// </summary>
1515
public readonly record struct ItemSystemPath
1616
: IPropertyPath
@@ -68,12 +68,17 @@ public readonly record struct ItemSystemPath
6868
/// </summary>
6969
public static ItemSystemPath SitemapLocations { get; } = new("system.sitemap_locations");
7070

71+
/// <summary>
72+
/// Implicitly converts an <see cref="ItemSystemPath"/> to a string.
73+
/// </summary>
74+
public static implicit operator string(ItemSystemPath path) => path._value;
75+
7176
/// <inheritdoc />
7277
public string Serialize() => _value;
7378
}
7479

7580
/// <summary>
76-
/// Strongly-typed system property path for content types.
81+
/// Strongly-typed system property path for content types. Implicitly converts to string.
7782
/// </summary>
7883
public readonly record struct TypeSystemPath
7984
: IPropertyPath
@@ -106,7 +111,7 @@ public readonly record struct TypeSystemPath
106111
}
107112

108113
/// <summary>
109-
/// Strongly-typed system property path for taxonomy groups.
114+
/// Strongly-typed system property path for taxonomy groups. Implicitly converts to string.
110115
/// </summary>
111116
public readonly record struct TaxonomySystemPath
112117
: IPropertyPath
@@ -134,12 +139,17 @@ public readonly record struct TaxonomySystemPath
134139
/// </summary>
135140
public static TaxonomySystemPath LastModified { get; } = new("system.last_modified");
136141

142+
/// <summary>
143+
/// Implicitly converts an <see cref="TaxonomySystemPath"/> to a string.
144+
/// </summary>
145+
public static implicit operator string(TaxonomySystemPath path) => path._value;
146+
137147
/// <inheritdoc />
138148
public string Serialize() => _value;
139149
}
140150

141151
/// <summary>
142-
/// Strongly-typed element property path.
152+
/// Strongly-typed element property path. Implicitly converts to string.
143153
/// </summary>
144154
public readonly record struct ElementPath
145155
: IPropertyPath
@@ -157,6 +167,11 @@ internal static ElementPath FromCodename(string codename)
157167
/// </summary>
158168
/// <inheritdoc />
159169
public string Serialize() => _value;
170+
171+
/// <summary>
172+
/// Implicitly converts an <see cref="ElementPath"/> to a string.
173+
/// </summary>
174+
public static implicit operator string(ElementPath path) => path._value;
160175
}
161176

162177
/// <summary>

Kontent.Ai.Delivery.Abstractions/QueryBuilders/IMultipleItemsQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public interface IMultipleItemsQuery<T>
5454
/// Adds a filter to the query using a filter builder function.
5555
/// </summary>
5656
/// <param name="filterBuilder">Function that builds a filter using the items filter builder.</param>
57-
IMultipleItemsQuery<T> Where(Func<IItemFilters, IFilter> filterBuilder);
57+
IMultipleItemsQuery<T> Filter(Func<IItemFilters, IFilter> filterBuilder);
5858

5959
/// <summary>
6060
/// Adds a filter to the query.

Kontent.Ai.Delivery/Api/QueryBuilders/Filtering/FilterValueMapper.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ public static IFilterValue From(Scalar s) => s.Match<IFilterValue>(
1111
BooleanValue.From
1212
);
1313

14-
public static IFilterValue From(ScalarArray arr) => arr.Match<IFilterValue>(
15-
StringArrayValue.From,
16-
NumericArrayValue.From,
17-
DateTimeArrayValue.From
18-
);
19-
2014
public static IFilterValue From(RangeTuple r) => r.Match<IFilterValue>(
2115
NumericRangeValue.From,
2216
DateRangeValue.From

Kontent.Ai.Delivery/Api/QueryBuilders/Filtering/ItemFilters.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ public IFilter GreaterThanOrEqual(IPropertyPath path, Comparable value)
2929
public IFilter Range(IPropertyPath path, RangeTuple bounds)
3030
=> new Filter(path.Serialize(), FilterOperator.Range, FilterValueMapper.From(bounds));
3131

32-
public IFilter In(IPropertyPath path, ScalarArray values)
33-
=> new Filter(path.Serialize(), FilterOperator.In, FilterValueMapper.From(values));
34-
35-
public IFilter NotIn(IPropertyPath path, ScalarArray values)
36-
=> new Filter(path.Serialize(), FilterOperator.NotIn, FilterValueMapper.From(values));
37-
3832
public IFilter Contains(IPropertyPath path, string value)
3933
=> new Filter(path.Serialize(), FilterOperator.Contains, StringValue.From(value));
4034

@@ -50,4 +44,22 @@ public IFilter Empty(IPropertyPath path)
5044
public IFilter NotEmpty(IPropertyPath path)
5145
=> new Filter(path.Serialize(), FilterOperator.NotEmpty, EmptyValue.From(string.Empty));
5246

47+
public IFilter In(IPropertyPath path, string[] values)
48+
=> new Filter(path.Serialize(), FilterOperator.In, StringArrayValue.From(values));
49+
50+
public IFilter NotIn(IPropertyPath path, string[] values)
51+
=> new Filter(path.Serialize(), FilterOperator.NotIn, StringArrayValue.From(values));
52+
53+
public IFilter In(IPropertyPath path, double[] values)
54+
=> new Filter(path.Serialize(), FilterOperator.In, NumericArrayValue.From(values));
55+
56+
public IFilter NotIn(IPropertyPath path, double[] values)
57+
=> new Filter(path.Serialize(), FilterOperator.NotIn, NumericArrayValue.From(values));
58+
59+
public IFilter In(IPropertyPath path, System.DateTime[] values)
60+
=> new Filter(path.Serialize(), FilterOperator.In, DateTimeArrayValue.From(values));
61+
62+
public IFilter NotIn(IPropertyPath path, System.DateTime[] values)
63+
=> new Filter(path.Serialize(), FilterOperator.NotIn, DateTimeArrayValue.From(values));
64+
5365
}

Kontent.Ai.Delivery/Api/QueryBuilders/MultipleItemsQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public IMultipleItemsQuery<T> WithTotalCount()
5959
return this;
6060
}
6161

62-
public IMultipleItemsQuery<T> Where(Func<IItemFilters, IFilter> filterBuilder)
62+
public IMultipleItemsQuery<T> Filter(Func<IItemFilters, IFilter> filterBuilder)
6363
{
6464
var filter = filterBuilder(_filters);
6565
_appliedFilters.Add(filter);

0 commit comments

Comments
 (0)