Skip to content

Commit 8d90ac9

Browse files
authored
Merge pull request #574 from json-api-dotnet/feat/queryparams
Query Parameter Services
2 parents 32b3c64 + d1af7cc commit 8d90ac9

File tree

101 files changed

+1707
-1867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1707
-1867
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ charset = utf-8
1212

1313
[*.{csproj,props}]
1414
indent_size = 2
15+
16+
[*.{cs,vb}]
17+
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
18+
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
19+
dotnet_naming_rule.private_members_with_underscore.severity = suggestion
20+
21+
dotnet_naming_symbols.private_fields.applicable_kinds = field
22+
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
23+
24+
dotnet_naming_style.prefix_underscore.capitalization = camel_case
25+
dotnet_naming_style.prefix_underscore.required_prefix = _

benchmarks/Query/QueryParser_Benchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private void Run(int iterations, Action action) {
5757
}
5858

5959
// this facade allows us to expose and micro-benchmark protected methods
60-
private class BenchmarkFacade : QueryParser {
60+
private class BenchmarkFacade : QueryParameterDiscovery {
6161
public BenchmarkFacade(
6262
IRequestContext currentRequest,
6363
JsonApiOptions options) : base(currentRequest, options) { }

benchmarks/RequestMiddleware/ContainsMediaTypeParameters_Benchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ContainsMediaTypeParameters_Benchmarks
1414

1515
[Benchmark]
1616
public void Current()
17-
=> JsonApiDotNetCore.Middleware.RequestMiddleware.ContainsMediaTypeParameters(MEDIA_TYPE);
17+
=> JsonApiDotNetCore.Middleware.CurrentRequestMiddleware.ContainsMediaTypeParameters(MEDIA_TYPE);
1818

1919
private bool UsingSplitImpl(string mediaType)
2020
{

src/Examples/JsonApiDotNetCoreExample/Properties/launchSettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"launchUrl": "http://localhost:5000/api/values",
2323
"environmentVariables": {
2424
"ASPNETCORE_ENVIRONMENT": "Development"
25-
}
25+
},
26+
"applicationUrl": "http://localhost:5000/"
2627
}
2728
}
2829
}

src/Examples/JsonApiDotNetCoreExample/Resources/UserResource.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public override QueryFilters GetQueryFilters()
2424

2525
private IQueryable<User> FirstCharacterFilter(IQueryable<User> users, FilterQuery filterQuery)
2626
{
27-
switch(filterQuery.Operation)
28-
{
29-
case "lt":
30-
return users.Where(u => u.Username[0] < filterQuery.Value[0]);
31-
default:
32-
return users.Where(u => u.Username[0] == filterQuery.Value[0]);
33-
}
27+
switch (filterQuery.Operation)
28+
{
29+
case "lt":
30+
return users.Where(u => u.Username[0] < filterQuery.Value[0]);
31+
default:
32+
return users.Where(u => u.Username[0] == filterQuery.Value[0]);
33+
}
3434
}
3535
}
3636
}

src/Examples/JsonApiDotNetCoreExample/Services/CustomArticleService.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ namespace JsonApiDotNetCoreExample.Services
1616
{
1717
public class CustomArticleService : EntityResourceService<Article>
1818
{
19-
public CustomArticleService(IEntityRepository<Article, int> repository, IJsonApiOptions options,
20-
ITargetedFields updatedFields, ICurrentRequest currentRequest,
21-
IIncludeService includeService, ISparseFieldsService sparseFieldsService,
22-
IPageQueryService pageManager, IResourceGraph resourceGraph,
23-
IResourceHookExecutor hookExecutor = null, ILoggerFactory loggerFactory = null)
24-
: base(repository, options, updatedFields, currentRequest, includeService, sparseFieldsService, pageManager, resourceGraph, hookExecutor, loggerFactory)
19+
public CustomArticleService(ISortService sortService,
20+
IFilterService filterService,
21+
IEntityRepository<Article, int> repository,
22+
IJsonApiOptions options,
23+
ICurrentRequest currentRequest,
24+
IIncludeService includeService,
25+
ISparseFieldsService sparseFieldsService,
26+
IPageService pageManager,
27+
IResourceGraph resourceGraph,
28+
IResourceHookExecutor hookExecutor = null,
29+
ILoggerFactory loggerFactory = null)
30+
: base(sortService, filterService, repository, options, currentRequest, includeService, sparseFieldsService,
31+
pageManager, resourceGraph, hookExecutor, loggerFactory)
2532
{
2633
}
2734

src/Examples/NoEntityFrameworkExample/Properties/launchSettings.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
}
99
},
1010
"profiles": {
11+
"NoEntityFrameworkExample": {
12+
"commandName": "Project",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
},
17+
"applicationUrl": "http://localhost:5000/"
18+
},
1119
"IIS Express": {
1220
"commandName": "IISExpress",
1321
"launchBrowser": true,
1422
"environmentVariables": {
1523
"ASPNETCORE_ENVIRONMENT": "Development"
1624
}
17-
},
18-
"NoEntityFrameworkExample": {
19-
"commandName": "Project",
20-
"environmentVariables": {}
2125
}
2226
}
2327
}

src/Examples/ReportsExample/Properties/launchSettings.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
}
99
},
1010
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"launchBrowser": true,
14-
"environmentVariables": {
15-
"ASPNETCORE_ENVIRONMENT": "Development"
16-
}
17-
},
1811
"ReportsExample": {
1912
"commandName": "Project",
2013
"launchBrowser": true,
2114
"environmentVariables": {
2215
"ASPNETCORE_ENVIRONMENT": "Development"
2316
},
2417
"applicationUrl": "http://localhost:55654/"
18+
},
19+
"IIS Express": {
20+
"commandName": "IISExpress",
21+
"launchBrowser": true,
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
2525
}
2626
}
2727
}

src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Generic;
21
using System.Threading.Tasks;
32
using JsonApiDotNetCore.Configuration;
43
using JsonApiDotNetCore.Extensions;
@@ -51,13 +50,8 @@ public BaseJsonApiController(
5150
_update = resourceService;
5251
_updateRelationships = resourceService;
5352
_delete = resourceService;
54-
ParseQueryParams();
5553
}
5654

57-
private void ParseQueryParams()
58-
{
59-
60-
}
6155

6256
public BaseJsonApiController(
6357
IJsonApiOptions jsonApiOptions,

src/JsonApiDotNetCore/Controllers/DisableQueryAttribute.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@
33
namespace JsonApiDotNetCore.Controllers
44
{
55
public class DisableQueryAttribute : Attribute
6-
{
6+
{
7+
/// <summary>
8+
/// Disabled one of the native query parameters for a controller.
9+
/// </summary>
10+
/// <param name="queryParams"></param>
711
public DisableQueryAttribute(QueryParams queryParams)
812
{
9-
QueryParams = queryParams;
13+
QueryParams = queryParams.ToString("G").ToLower();
1014
}
1115

12-
public QueryParams QueryParams { get; set; }
16+
/// <summary>
17+
/// It is allowed to use strings to indicate which query parameters
18+
/// should be disabled, because the user may have defined a custom
19+
/// query parameter that is not included in the <see cref="QueryParams"/> enum.
20+
/// </summary>
21+
/// <param name="customQueryParams"></param>
22+
public DisableQueryAttribute(string customQueryParams)
23+
{
24+
QueryParams = customQueryParams.ToLower();
25+
}
26+
27+
public string QueryParams { get; }
1328
}
1429
}

0 commit comments

Comments
 (0)