Skip to content
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

Moved QueryContext action parameter initialization to more common place #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 2 additions & 11 deletions Saule/Http/HandlesQueryAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Saule.Queries;
using Saule.Queries.Fieldset;
using Saule.Queries.Filtering;
using Saule.Queries.Including;
using Saule.Queries.Sorting;
Expand Down Expand Up @@ -33,6 +34,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
queryContext.IsHandledQuery = true;
queryContext.Sort = new SortContext(queryParams);
queryContext.Filter = new FilterContext(queryParams);
queryContext.Fieldset = new FieldsetContext(queryParams);

if (queryContext.Include == null)
{
Expand All @@ -43,17 +45,6 @@ public override void OnActionExecuting(HttpActionContext actionContext)
queryContext.Include.SetIncludes(queryParams);
}

// we validate if action has QueryContext parameter
// and if it has it, then we pass it
var parameters = actionContext.ActionDescriptor.GetParameters();
foreach (var parameter in parameters)
{
if (parameter.ParameterType == typeof(QueryContext))
{
actionContext.ActionArguments[parameter.ParameterName] = queryContext;
}
}

base.OnActionExecuting(actionContext);
}

Expand Down
11 changes: 11 additions & 0 deletions Saule/Http/QueryContextUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ internal static QueryContext GetQueryContext(HttpActionContext actionContext)
{
query = new QueryContext();
actionContext.Request.Properties.Add(Constants.PropertyNames.QueryContext, query);

// we validate if action has QueryContext parameter
// and if it has it, then we pass it
var parameters = actionContext.ActionDescriptor.GetParameters();
foreach (var parameter in parameters)
{
if (parameter.ParameterType == typeof(QueryContext))
{
actionContext.ActionArguments[parameter.ParameterName] = query;
}
}
}

return query;
Expand Down