Skip to content

Commit 05b1163

Browse files
Fix code style-related errors
1 parent 37ac8f2 commit 05b1163

File tree

4 files changed

+55
-94
lines changed

4 files changed

+55
-94
lines changed

src/JsonApiDotNetCore/Configuration/NoSqlServiceCollectionExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public static IServiceCollection AddNoSqlResourceServices(this IServiceCollectio
4646
{
4747
if (TryGetIdType(resourceType, out Type? idType))
4848
{
49-
services.AddScoped(
50-
typeof(IResourceService<,>).MakeGenericType(resourceType, idType),
49+
services.AddScoped(typeof(IResourceService<,>).MakeGenericType(resourceType, idType),
5150
typeof(NoSqlResourceService<,>).MakeGenericType(resourceType, idType));
5251
}
5352
}
@@ -57,8 +56,7 @@ public static IServiceCollection AddNoSqlResourceServices(this IServiceCollectio
5756

5857
private static bool IsNoSqlResource(Type type)
5958
{
60-
return Attribute.GetCustomAttribute(type, typeof(NoSqlResourceAttribute)) is not null &&
61-
type.GetInterfaces().Any(IsGenericIIdentifiable);
59+
return Attribute.GetCustomAttribute(type, typeof(NoSqlResourceAttribute)) is not null && type.GetInterfaces().Any(IsGenericIIdentifiable);
6260
}
6361

6462
private static bool IsGenericIIdentifiable(Type type)

src/JsonApiDotNetCore/Queries/INoSqlQueryLayerComposer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public interface INoSqlQueryLayerComposer
3333
TopFieldSelection fieldSelection)
3434
where TId : notnull;
3535

36-
3736
/// <summary>
3837
/// Composes a <see cref="QueryLayer" /> with a filter expression in the form "equals(id,'{stringId}')".
3938
/// </summary>

src/JsonApiDotNetCore/Queries/NoSqlQueryLayerComposer.cs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public NoSqlQueryLayerComposer(
4343
IPaginationContext paginationContext,
4444
ITargetedFields targetedFields,
4545
IEvaluatedIncludeCache evaluatedIncludeCache,
46-
ISparseFieldSetCache sparseFieldSetCache) : base(constraintProviders, resourceDefinitionAccessor, options, paginationContext, targetedFields, evaluatedIncludeCache, sparseFieldSetCache)
46+
ISparseFieldSetCache sparseFieldSetCache)
47+
: base(constraintProviders, resourceDefinitionAccessor, options, paginationContext, targetedFields, evaluatedIncludeCache, sparseFieldSetCache)
4748
{
4849
_constraintProviders = constraintProviders;
4950
_targetedFields = targetedFields;
@@ -89,12 +90,10 @@ public QueryLayer ComposeForGetByIdForNoSql<TId>(TId id, ResourceType primaryRes
8990
{
9091
return new QueryLayer(primaryResourceType)
9192
{
92-
Filter = new ComparisonExpression(
93-
ComparisonOperator.Equals,
94-
new ResourceFieldChainExpression(
95-
primaryResourceType.Fields.Single(field => field.Property.Name == nameof(IIdentifiable<TId>.Id))),
93+
Filter = new ComparisonExpression(ComparisonOperator.Equals,
94+
new ResourceFieldChainExpression(primaryResourceType.Fields.Single(field => field.Property.Name == nameof(IIdentifiable<TId>.Id))),
9695
new LiteralConstantExpression(id.ToString()!)),
97-
Include = IncludeExpression.Empty,
96+
Include = IncludeExpression.Empty
9897
};
9998
}
10099

@@ -108,37 +107,30 @@ public QueryLayer ComposeForGetByIdForNoSql<TId>(TId id, ResourceType primaryRes
108107
// Compose a secondary resource filter in the form "equals({propertyName},'{propertyValue}')".
109108
FilterExpression[] secondaryResourceFilterExpressions =
110109
{
111-
ComposeSecondaryResourceFilter(requestResourceType, propertyName, propertyValue),
110+
ComposeSecondaryResourceFilter(requestResourceType, propertyName, propertyValue)
112111
};
113112

114113
// Get the query expressions from the request.
115-
ExpressionInScope[] constraints = _constraintProviders
116-
.SelectMany(provider => provider.GetConstraints())
117-
.ToArray();
114+
ExpressionInScope[] constraints = _constraintProviders.SelectMany(provider => provider.GetConstraints()).ToArray();
118115

119116
bool IsQueryLayerConstraint(ExpressionInScope constraint)
120117
{
121-
return constraint.Expression is not IncludeExpression &&
122-
(!isIncluded || (constraint.Scope is not null &&
123-
constraint.Scope.Fields.Any(field => field.PublicName == requestResourceType.PublicName)));
118+
return constraint.Expression is not IncludeExpression && (!isIncluded || (constraint.Scope is not null &&
119+
constraint.Scope.Fields.Any(field => field.PublicName == requestResourceType.PublicName)));
124120
}
125121

126-
IEnumerable<QueryExpression> requestQueryExpressions = constraints
127-
.Where(IsQueryLayerConstraint)
128-
.Select(constraint => constraint.Expression);
122+
IEnumerable<QueryExpression> requestQueryExpressions = constraints.Where(IsQueryLayerConstraint).Select(constraint => constraint.Expression);
129123

130124
// Combine the secondary resource filter and request query expressions and
131125
// create the query layer from the combined query expressions.
132-
QueryExpression[] queryExpressions = secondaryResourceFilterExpressions
133-
.Concat(requestQueryExpressions)
134-
.ToArray();
126+
QueryExpression[] queryExpressions = secondaryResourceFilterExpressions.Concat(requestQueryExpressions).ToArray();
135127

136128
var queryLayer = new QueryLayer(requestResourceType)
137129
{
138130
Include = IncludeExpression.Empty,
139131
Filter = GetFilter(queryExpressions, requestResourceType),
140132
Sort = GetSort(queryExpressions, requestResourceType),
141-
Pagination = GetPagination(queryExpressions, requestResourceType),
133+
Pagination = GetPagination(queryExpressions, requestResourceType)
142134
};
143135

144136
// Retrieve the IncludeExpression from the constraints collection.
@@ -147,46 +139,34 @@ bool IsQueryLayerConstraint(ExpressionInScope constraint)
147139
// into a single expression.
148140
IncludeExpression include = isIncluded
149141
? IncludeExpression.Empty
150-
: constraints
151-
.Select(constraint => constraint.Expression)
152-
.OfType<IncludeExpression>()
153-
.DefaultIfEmpty(IncludeExpression.Empty)
154-
.Single();
142+
: constraints.Select(constraint => constraint.Expression).OfType<IncludeExpression>().DefaultIfEmpty(IncludeExpression.Empty).Single();
155143

156144
return (queryLayer, include);
157145
}
158146

159-
private static FilterExpression ComposeSecondaryResourceFilter(
160-
ResourceType resourceType,
161-
string propertyName,
162-
string properyValue)
147+
private static FilterExpression ComposeSecondaryResourceFilter(ResourceType resourceType, string propertyName, string properyValue)
163148
{
164-
return new ComparisonExpression(
165-
ComparisonOperator.Equals,
149+
return new ComparisonExpression(ComparisonOperator.Equals,
166150
new ResourceFieldChainExpression(resourceType.Fields.Single(field => field.Property.Name == propertyName)),
167151
new LiteralConstantExpression(properyValue));
168152
}
169153

170-
public (QueryLayer QueryLayer, IncludeExpression Include) ComposeForUpdateForNoSql<TId>(
171-
TId id,
172-
ResourceType primaryResourceType)
154+
public (QueryLayer QueryLayer, IncludeExpression Include) ComposeForUpdateForNoSql<TId>(TId id, ResourceType primaryResourceType)
173155
where TId : notnull
174156
{
175157
// Create primary layer without an include expression.
176158
AttrAttribute primaryIdAttribute = GetIdAttribute(primaryResourceType);
159+
177160
QueryLayer primaryLayer = new(primaryResourceType)
178161
{
179162
Include = IncludeExpression.Empty,
180-
Filter = new ComparisonExpression(
181-
ComparisonOperator.Equals,
182-
new ResourceFieldChainExpression(primaryIdAttribute),
183-
new LiteralConstantExpression(id.ToString()!)),
163+
Filter = new ComparisonExpression(ComparisonOperator.Equals, new ResourceFieldChainExpression(primaryIdAttribute),
164+
new LiteralConstantExpression(id.ToString()!))
184165
};
185166

186167
// Create a separate include expression.
187168
ImmutableHashSet<IncludeElementExpression> includeElements = _targetedFields.Relationships
188-
.Select(relationship => new IncludeElementExpression(relationship))
189-
.ToImmutableHashSet();
169+
.Select(relationship => new IncludeElementExpression(relationship)).ToImmutableHashSet();
190170

191171
IncludeExpression include = includeElements.Any() ? new IncludeExpression(includeElements) : IncludeExpression.Empty;
192172

0 commit comments

Comments
 (0)