Skip to content

Commit 1c80eb7

Browse files
committed
allow custom attribute filters
1 parent 67edb7f commit 1c80eb7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
9090

9191
public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> source, AttrFilterQuery filterQuery)
9292
{
93-
if (filterQuery == null)
93+
if (filterQuery == null || filterQuery.IsAttribute == false)
9494
return source;
9595

9696
var concreteType = typeof(TSource);

src/JsonApiDotNetCore/Internal/Query/AttrFilterQuery.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public AttrFilterQuery(
1818
var attribute = GetAttribute(filterQuery.Attribute);
1919

2020
if (attribute == null)
21-
throw new JsonApiException(400, $"'{filterQuery.Attribute}' is not a valid attribute.");
21+
return; // we don't want to throw...we should allow custom filter implementations
22+
23+
IsAttribute = true;
2224

2325
if (attribute.IsFilterable == false)
2426
throw new JsonApiException(400, $"Filter is not allowed for attribute '{attribute.PublicAttributeName}'.");
@@ -32,6 +34,12 @@ public AttrFilterQuery(
3234
public string PropertyValue { get; }
3335
public FilterOperations FilterOperation { get; }
3436

37+
/// <summary>
38+
/// Whether or not the filter is an actual attribute on the model.
39+
/// We use this to allow custom filters that have to be handled by the application.
40+
/// </summary>
41+
internal bool IsAttribute { get; set; }
42+
3543
private AttrAttribute GetAttribute(string attribute) =>
3644
_jsonApiContext.RequestEntity.Attributes.FirstOrDefault(attr => attr.Is(attribute));
3745
}

0 commit comments

Comments
 (0)