Skip to content

feat(query-parser): allow inheritance and method overrides #191

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

Merged
merged 1 commit into from
Nov 13, 2017
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
16 changes: 8 additions & 8 deletions src/JsonApiDotNetCore/Services/QueryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public QueryParser(
_options = options;
}

public QuerySet Parse(IQueryCollection query)
public virtual QuerySet Parse(IQueryCollection query)
{
var querySet = new QuerySet();
var disabledQueries = _controllerContext.GetControllerAttribute<DisableQueryAttribute>()?.QueryParams ?? QueryParams.None;
Expand Down Expand Up @@ -78,7 +78,7 @@ public QuerySet Parse(IQueryCollection query)
return querySet;
}

private List<FilterQuery> ParseFilterQuery(string key, string value)
protected virtual List<FilterQuery> ParseFilterQuery(string key, string value)
{
// expected input = filter[id]=1
// expected input = filter[id]=eq:1
Expand All @@ -96,7 +96,7 @@ private List<FilterQuery> ParseFilterQuery(string key, string value)
return queries;
}

private (string operation, string value) ParseFilterOperation(string value)
protected virtual (string operation, string value) ParseFilterOperation(string value)
{
if (value.Length < 3)
return (string.Empty, value);
Expand All @@ -116,7 +116,7 @@ private List<FilterQuery> ParseFilterQuery(string key, string value)
return (prefix, value);
}

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

// sort=id,name
// sort=-id
private List<SortQuery> ParseSortParameters(string value)
protected virtual List<SortQuery> ParseSortParameters(string value)
{
var sortParameters = new List<SortQuery>();
value.Split(',').ToList().ForEach(p =>
Expand All @@ -154,7 +154,7 @@ private List<SortQuery> ParseSortParameters(string value)
return sortParameters;
}

private List<string> ParseIncludedRelationships(string value)
protected virtual List<string> ParseIncludedRelationships(string value)
{
if (value.Contains("."))
throw new JsonApiException(400, "Deeply nested relationships are not supported");
Expand All @@ -164,7 +164,7 @@ private List<string> ParseIncludedRelationships(string value)
.ToList();
}

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

private AttrAttribute GetAttribute(string propertyName)
protected virtual AttrAttribute GetAttribute(string propertyName)
=> _controllerContext
.RequestEntity
.Attributes
Expand Down