Skip to content

Commit 71e437d

Browse files
Remove isIncluded parameter
1 parent fd237a0 commit 71e437d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/JsonApiDotNetCore/Services/NoSqlResourceService.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class NoSqlResourceService<TResource, TId> : IResourceService<TResource,
5656
protected enum ResourceKind
5757
{
5858
Secondary,
59+
Included,
5960
Relationship
6061
}
6162

@@ -174,7 +175,7 @@ public async Task<TResource> GetAsync(TId id, CancellationToken cancellationToke
174175
// Get the primary resource to (1) ensure it exists and (2) retrieve foreign key values as necessary.
175176
IIdentifiable primary = await GetPrimaryResourceByIdAsync(id, cancellationToken);
176177

177-
return await GetSecondaryAsync(primary, relationshipName, ResourceKind.Secondary, false, cancellationToken);
178+
return await GetSecondaryAsync(primary, relationshipName, ResourceKind.Secondary, cancellationToken);
178179
}
179180

180181
/// <inheritdoc />
@@ -191,7 +192,7 @@ public async Task<TResource> GetAsync(TId id, CancellationToken cancellationToke
191192
// Get the primary resource to (1) ensure it exists and (2) retrieve foreign key values as necessary.
192193
IIdentifiable primary = await GetPrimaryResourceByIdAsync(id, cancellationToken);
193194

194-
return await GetSecondaryAsync(primary, relationshipName, ResourceKind.Relationship, false, cancellationToken);
195+
return await GetSecondaryAsync(primary, relationshipName, ResourceKind.Relationship, cancellationToken);
195196
}
196197

197198
/// <inheritdoc />
@@ -433,7 +434,7 @@ protected virtual async Task GetIncludedElementAsync(
433434

434435
foreach (var primaryResource in primaryResources)
435436
{
436-
await GetSecondaryAsync(primaryResource, relationshipName, ResourceKind.Secondary, true, cancellationToken);
437+
await GetSecondaryAsync(primaryResource, relationshipName, ResourceKind.Included, cancellationToken);
437438
}
438439
}
439440

@@ -444,7 +445,6 @@ protected virtual async Task GetIncludedElementAsync(
444445
/// <param name="primaryResource">The primary resource.</param>
445446
/// <param name="relationshipName">The name of the relationship between the primary and secondary resources.</param>
446447
/// <param name="resourceKind"></param>
447-
/// <param name="isIncluded">Indicates whether the relationship was specified by using "include={relationshipName}".</param>
448448
/// <param name="cancellationToken">The <see cref="CancellationToken" />.</param>
449449
/// <exception cref="JsonApiException">
450450
/// If the relationship specified by <paramref name="relationshipName" /> does not exist
@@ -458,7 +458,6 @@ protected virtual async Task GetIncludedElementAsync(
458458
IIdentifiable primaryResource,
459459
string relationshipName,
460460
ResourceKind resourceKind,
461-
bool isIncluded,
462461
CancellationToken cancellationToken)
463462
{
464463
// Get the HasMany or HasOne attribute corresponding to the given relationship name.
@@ -514,10 +513,10 @@ protected virtual async Task GetIncludedElementAsync(
514513

515514
return relationshipAttribute switch
516515
{
517-
HasManyAttribute => await GetManySecondaryResourcesAsync(type, foreignKey, stringId, resourceKind, isIncluded, cancellationToken),
516+
HasManyAttribute => await GetManySecondaryResourcesAsync(type, foreignKey, stringId, resourceKind, cancellationToken),
518517

519518
HasOneAttribute when isDependent => await GetOneSecondaryResourceAsync(type, nameof(IIdentifiable<TId>.Id),
520-
GetStringValue(primaryResource, foreignKey), resourceKind, isIncluded, cancellationToken),
519+
GetStringValue(primaryResource, foreignKey), resourceKind, cancellationToken),
521520

522521
HasOneAttribute when !isDependent => throw new JsonApiException(new ErrorObject(HttpStatusCode.NotImplemented)
523522
{
@@ -541,7 +540,6 @@ protected virtual async Task GetIncludedElementAsync(
541540
/// <param name="propertyName">The name of the property used to filter resources, e.g., "Id".</param>
542541
/// <param name="propertyValue">The value of the property used to filter resources, e.g., "e0bd6fe1-889e-4a06-84f8-5cf2e8d58466".</param>
543542
/// <param name="resourceKind"></param>
544-
/// <param name="isIncluded"></param>
545543
/// <param name="cancellationToken">The <see cref="CancellationToken" />.</param>
546544
/// <returns>
547545
/// The <see cref="IIdentifiable" />, if it exists, or <see langword="null" />.
@@ -551,7 +549,6 @@ protected virtual async Task GetIncludedElementAsync(
551549
string propertyName,
552550
string? propertyValue,
553551
ResourceKind resourceKind,
554-
bool isIncluded,
555552
CancellationToken cancellationToken)
556553
{
557554
if (propertyValue is null)
@@ -560,7 +557,7 @@ protected virtual async Task GetIncludedElementAsync(
560557
}
561558

562559
IReadOnlyCollection<IIdentifiable> items = await GetManySecondaryResourcesAsync(
563-
resourceType, propertyName, propertyValue, resourceKind, isIncluded, cancellationToken);
560+
resourceType, propertyName, propertyValue, resourceKind, cancellationToken);
564561

565562
return items.SingleOrDefault();
566563
}
@@ -573,22 +570,21 @@ protected virtual async Task GetIncludedElementAsync(
573570
/// <param name="propertyName">The name of the property used to filter resources, e.g., "ParentId".</param>
574571
/// <param name="propertyValue">The value of the property used to filter resources, e.g., "e0bd6fe1-889e-4a06-84f8-5cf2e8d58466".</param>
575572
/// <param name="resourceKind"></param>
576-
/// <param name="isIncluded">Indicates whether or not the secondary resource is included by way of an include expression.</param>
577573
/// <param name="cancellationToken">The <see cref="CancellationToken" />.</param>
578574
/// <returns>The potentially empty collection of secondary resources.</returns>
579575
protected async Task<IReadOnlyCollection<IIdentifiable>> GetManySecondaryResourcesAsync(
580576
ResourceType resourceType,
581577
string propertyName,
582578
string propertyValue,
583579
ResourceKind resourceKind,
584-
bool isIncluded,
585580
CancellationToken cancellationToken)
586581
{
582+
bool isIncluded = resourceKind == ResourceKind.Included;
587583
var (queryLayer, include) = _queryLayerComposer.ComposeFromConstraintsForNoSql(resourceType, propertyName, propertyValue, isIncluded);
588584

589585
IReadOnlyCollection<IIdentifiable> items = await _repositoryAccessor.GetAsync(resourceType, queryLayer, cancellationToken);
590586

591-
if (resourceKind != ResourceKind.Relationship && !isIncluded)
587+
if (resourceKind == ResourceKind.Secondary)
592588
{
593589
await GetIncludedElementsAsync(items, include, cancellationToken);
594590
}

0 commit comments

Comments
 (0)