@@ -30,14 +30,16 @@ public class UserDefinition : JsonApiResourceDefinition<User>
30
30
{
31
31
}
32
32
33
- public override SparseFieldSetExpression OnApplySparseFieldSet (SparseFieldSetExpression existingSparseFieldSet )
33
+ public override SparseFieldSetExpression OnApplySparseFieldSet (
34
+ SparseFieldSetExpression existingSparseFieldSet )
34
35
{
35
36
if (IsAdministrator )
36
37
{
37
38
return existingSparseFieldSet ;
38
39
}
39
40
40
- return existingSparseFieldSet .Excluding <User >(x => x .Password , ResourceGraph );
41
+ return existingSparseFieldSet .Excluding <User >(
42
+ user => user .Password , ResourceGraph );
41
43
}
42
44
}
43
45
```
@@ -82,6 +84,10 @@ You can define the default sort order if no `sort` query string parameter is pro
82
84
``` c#
83
85
public class AccountDefinition : JsonApiResourceDefinition <Account >
84
86
{
87
+ public AccountDefinition (IResourceGraph resourceGraph ) : base (resourceGraph )
88
+ {
89
+ }
90
+
85
91
public override SortExpression OnApplySort (SortExpression existingSort )
86
92
{
87
93
if (existingSort != null )
@@ -105,17 +111,25 @@ You may want to enforce pagination on large database tables.
105
111
``` c#
106
112
public class AccessLogDefinition : JsonApiResourceDefinition <AccessLog >
107
113
{
108
- public override PaginationExpression OnApplyPagination (PaginationExpression existingPagination )
114
+ public AccessLogDefinition (IResourceGraph resourceGraph ) : base (resourceGraph )
115
+ {
116
+ }
117
+
118
+ public override PaginationExpression OnApplyPagination (
119
+ PaginationExpression existingPagination )
109
120
{
110
121
var maxPageSize = new PageSize (10 );
111
122
112
123
if (existingPagination != null )
113
124
{
114
- var pageSize = existingPagination .PageSize ? .Value <= maxPageSize .Value ? existingPagination .PageSize : maxPageSize ;
125
+ var pageSize = existingPagination .PageSize ? .Value <= maxPageSize .Value
126
+ ? existingPagination .PageSize
127
+ : maxPageSize ;
128
+
115
129
return new PaginationExpression (existingPagination .PageNumber , pageSize );
116
130
}
117
131
118
- return new PaginationExpression (PageNumber .ValueOne , _maxPageSize );
132
+ return new PaginationExpression (PageNumber .ValueOne , maxPageSize );
119
133
}
120
134
}
121
135
```
@@ -127,17 +141,26 @@ Soft-deletion sets `IsSoftDeleted` to `true` instead of actually deleting the re
127
141
``` c#
128
142
public class AccountDefinition : JsonApiResourceDefinition <Account >
129
143
{
144
+ public AccountDefinition (IResourceGraph resourceGraph ) : base (resourceGraph )
145
+ {
146
+ }
147
+
130
148
public override FilterExpression OnApplyFilter (FilterExpression existingFilter )
131
149
{
132
150
var resourceContext = ResourceGraph .GetResourceContext <Account >();
133
- var isSoftDeletedAttribute = resourceContext .Attributes .Single (a => a .Property .Name == nameof (Account .IsSoftDeleted ));
151
+
152
+ var isSoftDeletedAttribute =
153
+ resourceContext .Attributes .Single (a =>
154
+ a .Property .Name == nameof (Account .IsSoftDeleted ));
134
155
135
156
var isNotSoftDeleted = new ComparisonExpression (ComparisonOperator .Equals ,
136
- new ResourceFieldChainExpression (isSoftDeletedAttribute ), new LiteralConstantExpression (bool .FalseString ));
157
+ new ResourceFieldChainExpression (isSoftDeletedAttribute ),
158
+ new LiteralConstantExpression (bool .FalseString ));
137
159
138
160
return existingFilter == null
139
161
? (FilterExpression ) isNotSoftDeleted
140
- : new LogicalExpression (LogicalOperator .And , new [] {isNotSoftDeleted , existingFilter });
162
+ : new LogicalExpression (LogicalOperator .And ,
163
+ new [] {isNotSoftDeleted , existingFilter });
141
164
}
142
165
}
143
166
```
@@ -147,9 +170,15 @@ public class AccountDefinition : JsonApiResourceDefinition<Account>
147
170
``` c#
148
171
public class EmployeeDefinition : JsonApiResourceDefinition <Employee >
149
172
{
150
- public override IReadOnlyCollection <IncludeElementExpression > OnApplyIncludes (IReadOnlyCollection <IncludeElementExpression > existingIncludes )
173
+ public EmployeeDefinition (IResourceGraph resourceGraph ) : base (resourceGraph )
174
+ {
175
+ }
176
+
177
+ public override IReadOnlyCollection <IncludeElementExpression > OnApplyIncludes (
178
+ IReadOnlyCollection <IncludeElementExpression > existingIncludes )
151
179
{
152
- if (existingIncludes .Any (include => include .Relationship .Property .Name == nameof (Employee .Manager )))
180
+ if (existingIncludes .Any (include =>
181
+ include .Relationship .Property .Name == nameof (Employee .Manager )))
153
182
{
154
183
throw new JsonApiException (new Error (HttpStatusCode .BadRequest )
155
184
{
@@ -175,7 +204,12 @@ But it only works on primary resource endpoints (for example: /articles, but not
175
204
``` c#
176
205
public class ItemDefinition : JsonApiResourceDefinition <Item >
177
206
{
178
- protected override QueryStringParameterHandlers OnRegisterQueryableHandlersForQueryStringParameters ()
207
+ public ItemDefinition (IResourceGraph resourceGraph ) : base (resourceGraph )
208
+ {
209
+ }
210
+
211
+ public override QueryStringParameterHandlers<Item>
212
+ OnRegisterQueryableHandlersForQueryStringParameters ()
179
213
{
180
214
return new QueryStringParameterHandlers <Item >
181
215
{
@@ -186,10 +220,14 @@ public class ItemDefinition : JsonApiResourceDefinition<Item>
186
220
};
187
221
}
188
222
189
- private static IQueryable <Item > FilterByHighRisk (IQueryable <Item > source , StringValues parameterValue )
223
+ private static IQueryable <Item > FilterByHighRisk (IQueryable <Item > source ,
224
+ StringValues parameterValue )
190
225
{
191
226
bool isFilterOnHighRisk = bool .Parse (parameterValue );
192
- return isFilterOnHighRisk ? source .Where (item => item .RiskLevel >= 5 ) : source .Where (item => item .RiskLevel < 5 );
227
+
228
+ return isFilterOnHighRisk
229
+ ? source .Where (item => item .RiskLevel >= 5 )
230
+ : source .Where (item => item .RiskLevel < 5 );
193
231
}
194
232
}
195
233
```
0 commit comments