Skip to content

Commit 364e641

Browse files
author
Bart Koelman
committed
Review feedback
1 parent b40f3f3 commit 364e641

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

Diff for: JsonApiDotNetCore.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ $left$ = $right$;</s:String>
629629
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/ReplacePattern/@EntryValue">$collection$.IsNullOrEmpty()</s:String>
630630
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/SearchPattern/@EntryValue">$collection$ == null || !$collection$.Any()</s:String>
631631
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=B3D9EE6B4EC62A4F961EB15F9ADEC2C6/Severity/@EntryValue">WARNING</s:String>
632+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Accurize/@EntryIndexedValue">True</s:Boolean>
632633
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
633634
<s:Boolean x:Key="/Default/UserDictionary/Words/=Assignee/@EntryIndexedValue">True</s:Boolean>
634635
<s:Boolean x:Key="/Default/UserDictionary/Words/=Contoso/@EntryIndexedValue">True</s:Boolean>

Diff for: docs/usage/reading/filtering.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Which returns only customers that have at least one unpaid order.
9090
_since v5.0_
9191

9292
Use the `isType` filter function to perform a type check on a derived type. You can pass a nested filter, where the derived fields are accessible.
93-
The first parameter can be used to perform the type check on a to-one relationship path.
9493

9594
Only return men:
9695
```http
@@ -102,6 +101,8 @@ Only return men with beards:
102101
GET /humans?filter=isType(,men,equals(hasBeard,'true')) HTTP/1.1
103102
```
104103

104+
The first parameter of `isType` can be used to perform the type check on a to-one relationship path.
105+
105106
Only return people whose best friend is a man with children:
106107
```http
107108
GET /humans?filter=isType(bestFriend,men,has(children)) HTTP/1.1

Diff for: docs/usage/resources/inheritance.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ public override SortExpression OnApplySort(SortExpression? existingSort)
185185
### Filtering
186186

187187
Use the `isType` filter function to perform a type check on a derived type. You can pass a nested filter, where the derived fields are accessible.
188-
The first parameter can be used to perform the type check on a to-one relationship path.
189188

190189
Only return men:
191190
```http
@@ -197,6 +196,8 @@ Only return men with beards:
197196
GET /humans?filter=isType(,men,equals(hasBeard,'true')) HTTP/1.1
198197
```
199198

199+
The first parameter of `isType` can be used to perform the type check on a to-one relationship path.
200+
200201
Only return people whose best friend is a man with children:
201202
```http
202203
GET /humans?filter=isType(bestFriend,men,has(children)) HTTP/1.1
@@ -287,7 +288,7 @@ Resource definitions provide a better solution, see below.
287288

288289
### Resource definitions
289290

290-
In contract to the request pipeline, JsonApiDotNetCore always executes the resource definition that matches the *stored* type.
291+
In contrast to the request pipeline, JsonApiDotNetCore always executes the resource definition that matches the *stored* type.
291292
This enables to implement business logic in a central place, irrespective of which endpoint was used or whether base types were used in relationships.
292293

293294
To delegate logic for base types to their matching resource type, you can build a chain of resource definitions. And because you'll always get the

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ private async Task RetrieveResourceCountForNonPrimaryEndpointAsync(TId id, HasMa
202202
TResource resourceFromRequest = resource;
203203
_resourceChangeTracker.SetRequestAttributeValues(resourceFromRequest);
204204

205-
await RefreshResourceTypesInHierarchyToAssignInRelationshipsAsync(resourceFromRequest, cancellationToken);
205+
await AccurizeResourceTypesInHierarchyToAssignInRelationshipsAsync(resourceFromRequest, cancellationToken);
206206

207207
Type resourceClrType = resourceFromRequest.GetClrType();
208208
TResource resourceForDatabase = await _repositoryAccessor.GetForCreateAsync<TResource, TId>(resourceClrType, resourceFromRequest.Id, cancellationToken);
209-
PromoteJsonApiRequest(resourceForDatabase);
209+
AccurizeJsonApiRequest(resourceForDatabase);
210210

211211
_resourceChangeTracker.SetInitiallyStoredAttributeValues(resourceForDatabase);
212212

@@ -249,7 +249,7 @@ protected virtual async Task InitializeResourceAsync(TResource resourceForDataba
249249
await _resourceDefinitionAccessor.OnPrepareWriteAsync(resourceForDatabase, WriteOperationKind.CreateResource, cancellationToken);
250250
}
251251

252-
private async Task RefreshResourceTypesInHierarchyToAssignInRelationshipsAsync(TResource primaryResource, CancellationToken cancellationToken)
252+
private async Task AccurizeResourceTypesInHierarchyToAssignInRelationshipsAsync(TResource primaryResource, CancellationToken cancellationToken)
253253
{
254254
await ValidateResourcesToAssignInRelationshipsExistWithRefreshAsync(primaryResource, true, cancellationToken);
255255
}
@@ -360,7 +360,7 @@ public virtual async Task AddToToManyRelationshipAsync(TId leftId, string relati
360360
// The left resource may be stored as a derived type. We fetch it, so we'll know the stored type, which
361361
// enables to invoke IResourceDefinition<TResource> with TResource being the stored resource type.
362362
resourceFromDatabase ??= await GetPrimaryResourceForUpdateAsync(leftId, cancellationToken);
363-
PromoteJsonApiRequest(resourceFromDatabase);
363+
AccurizeJsonApiRequest(resourceFromDatabase);
364364
}
365365

366366
ISet<IIdentifiable> effectiveRightResourceIds = rightResourceIds;
@@ -453,10 +453,10 @@ private async Task<TResource> GetForHasManyUpdateAsync(HasManyAttribute hasManyR
453453
TResource resourceFromRequest = resource;
454454
_resourceChangeTracker.SetRequestAttributeValues(resourceFromRequest);
455455

456-
await RefreshResourceTypesInHierarchyToAssignInRelationshipsAsync(resourceFromRequest, cancellationToken);
456+
await AccurizeResourceTypesInHierarchyToAssignInRelationshipsAsync(resourceFromRequest, cancellationToken);
457457

458458
TResource resourceFromDatabase = await GetPrimaryResourceForUpdateAsync(id, cancellationToken);
459-
PromoteJsonApiRequest(resourceFromDatabase);
459+
AccurizeJsonApiRequest(resourceFromDatabase);
460460

461461
_resourceChangeTracker.SetInitiallyStoredAttributeValues(resourceFromDatabase);
462462

@@ -503,7 +503,7 @@ public virtual async Task SetRelationshipAsync(TId leftId, string relationshipNa
503503
: rightValue;
504504

505505
TResource resourceFromDatabase = await GetPrimaryResourceForUpdateAsync(leftId, cancellationToken);
506-
PromoteJsonApiRequest(resourceFromDatabase);
506+
AccurizeJsonApiRequest(resourceFromDatabase);
507507

508508
await _resourceDefinitionAccessor.OnPrepareWriteAsync(resourceFromDatabase, WriteOperationKind.SetRelationship, cancellationToken);
509509

@@ -537,7 +537,7 @@ public virtual async Task DeleteAsync(TId id, CancellationToken cancellationToke
537537
// The resource to delete may be stored as a derived type. We fetch it, so we'll know the stored type, which
538538
// enables to invoke IResourceDefinition<TResource> with TResource being the stored resource type.
539539
resourceFromDatabase = await GetPrimaryResourceForUpdateAsync(id, cancellationToken);
540-
PromoteJsonApiRequest(resourceFromDatabase);
540+
AccurizeJsonApiRequest(resourceFromDatabase);
541541
}
542542

543543
try
@@ -571,7 +571,7 @@ public virtual async Task RemoveFromToManyRelationshipAsync(TId leftId, string r
571571
var hasManyRelationship = (HasManyAttribute)_request.Relationship;
572572

573573
TResource resourceFromDatabase = await GetForHasManyUpdateAsync(hasManyRelationship, leftId, rightResourceIds, cancellationToken);
574-
PromoteJsonApiRequest(resourceFromDatabase);
574+
AccurizeJsonApiRequest(resourceFromDatabase);
575575

576576
object? rightValue = await AssertRightResourcesExistAsync(rightResourceIds, cancellationToken);
577577
ISet<IIdentifiable> effectiveRightResourceIds = ((IEnumerable<IIdentifiable>)rightValue!).ToHashSet(IdentifiableComparer.Instance);
@@ -610,7 +610,7 @@ protected async Task<TResource> GetPrimaryResourceForUpdateAsync(TId id, Cancell
610610
return resource;
611611
}
612612

613-
private void PromoteJsonApiRequest(TResource resourceFromDatabase)
613+
private void AccurizeJsonApiRequest(TResource resourceFromDatabase)
614614
{
615615
// When using resource inheritance, the stored left-side resource may be more derived than what this endpoint assumes.
616616
// In that case, we promote data in IJsonApiRequest to better represent what is going on.

0 commit comments

Comments
 (0)