Skip to content

Commit bb90f9e

Browse files
authored
feat(query-parser): allow inheritance and method overrides (#191)
1 parent e6e4cce commit bb90f9e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: src/JsonApiDotNetCore/Services/QueryParser.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public QueryParser(
2929
_options = options;
3030
}
3131

32-
public QuerySet Parse(IQueryCollection query)
32+
public virtual QuerySet Parse(IQueryCollection query)
3333
{
3434
var querySet = new QuerySet();
3535
var disabledQueries = _controllerContext.GetControllerAttribute<DisableQueryAttribute>()?.QueryParams ?? QueryParams.None;
@@ -78,7 +78,7 @@ public QuerySet Parse(IQueryCollection query)
7878
return querySet;
7979
}
8080

81-
private List<FilterQuery> ParseFilterQuery(string key, string value)
81+
protected virtual List<FilterQuery> ParseFilterQuery(string key, string value)
8282
{
8383
// expected input = filter[id]=1
8484
// expected input = filter[id]=eq:1
@@ -96,7 +96,7 @@ private List<FilterQuery> ParseFilterQuery(string key, string value)
9696
return queries;
9797
}
9898

99-
private (string operation, string value) ParseFilterOperation(string value)
99+
protected virtual (string operation, string value) ParseFilterOperation(string value)
100100
{
101101
if (value.Length < 3)
102102
return (string.Empty, value);
@@ -116,7 +116,7 @@ private List<FilterQuery> ParseFilterQuery(string key, string value)
116116
return (prefix, value);
117117
}
118118

119-
private PageQuery ParsePageQuery(PageQuery pageQuery, string key, string value)
119+
protected virtual PageQuery ParsePageQuery(PageQuery pageQuery, string key, string value)
120120
{
121121
// expected input = page[size]=10
122122
// page[number]=1
@@ -134,7 +134,7 @@ private PageQuery ParsePageQuery(PageQuery pageQuery, string key, string value)
134134

135135
// sort=id,name
136136
// sort=-id
137-
private List<SortQuery> ParseSortParameters(string value)
137+
protected virtual List<SortQuery> ParseSortParameters(string value)
138138
{
139139
var sortParameters = new List<SortQuery>();
140140
value.Split(',').ToList().ForEach(p =>
@@ -154,7 +154,7 @@ private List<SortQuery> ParseSortParameters(string value)
154154
return sortParameters;
155155
}
156156

157-
private List<string> ParseIncludedRelationships(string value)
157+
protected virtual List<string> ParseIncludedRelationships(string value)
158158
{
159159
if (value.Contains("."))
160160
throw new JsonApiException(400, "Deeply nested relationships are not supported");
@@ -164,7 +164,7 @@ private List<string> ParseIncludedRelationships(string value)
164164
.ToList();
165165
}
166166

167-
private List<string> ParseFieldsQuery(string key, string value)
167+
protected virtual List<string> ParseFieldsQuery(string key, string value)
168168
{
169169
// expected: fields[TYPE]=prop1,prop2
170170
var typeName = key.Split('[', ']')[1];
@@ -187,7 +187,7 @@ private List<string> ParseFieldsQuery(string key, string value)
187187
return includedFields;
188188
}
189189

190-
private AttrAttribute GetAttribute(string propertyName)
190+
protected virtual AttrAttribute GetAttribute(string propertyName)
191191
=> _controllerContext
192192
.RequestEntity
193193
.Attributes

0 commit comments

Comments
 (0)