Skip to content

Commit d97affd

Browse files
MilosMilos
authored andcommitted
Requested changes
1 parent 2e304cc commit d97affd

File tree

8 files changed

+23
-39
lines changed

8 files changed

+23
-39
lines changed
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using JsonApiDotNetCore.Models;
43
using JsonApiDotNetCore.Services;
54

@@ -10,11 +9,7 @@ public class AttrFilterQuery : BaseFilterQuery
109
public AttrFilterQuery(
1110
IJsonApiContext jsonApiContext,
1211
FilterQuery filterQuery)
13-
: base(jsonApiContext,
14-
null,
15-
filterQuery.Attribute,
16-
filterQuery.Value,
17-
filterQuery.OperationType)
12+
: base(jsonApiContext, filterQuery)
1813
{
1914
if (Attribute == null)
2015
throw new JsonApiException(400, $"'{filterQuery.Attribute}' is not a valid attribute.");
@@ -25,7 +20,7 @@ public AttrFilterQuery(
2520
FilteredAttribute = Attribute;
2621
}
2722

28-
[Obsolete("Use " + nameof(Attribute) + " property of " + nameof(BaseAttrQuery) + "class. This property is shared for all AttrQuery and RelatedAttrQuery (filter,sort..) implementations.")]
23+
[Obsolete("Use " + nameof(BaseAttrQuery.Attribute) + " insetad.")]
2924
public AttrAttribute FilteredAttribute { get; set; }
3025
}
3126
}

src/JsonApiDotNetCore/Internal/Query/AttrSortQuery.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.Linq;
3-
using JsonApiDotNetCore.Models;
41
using JsonApiDotNetCore.Services;
52

63
namespace JsonApiDotNetCore.Internal.Query
@@ -10,7 +7,7 @@ public class AttrSortQuery : BaseAttrQuery
107
public AttrSortQuery(
118
IJsonApiContext jsonApiContext,
129
SortQuery sortQuery)
13-
:base(jsonApiContext, null, sortQuery.Attribute)
10+
:base(jsonApiContext, sortQuery)
1411
{
1512
if (Attribute == null)
1613
throw new JsonApiException(400, $"'{sortQuery.Attribute}' is not a valid attribute.");

src/JsonApiDotNetCore/Internal/Query/BaseAttrQuery.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ public abstract class BaseAttrQuery
1313
{
1414
private readonly IJsonApiContext _jsonApiContext;
1515

16-
public BaseAttrQuery(IJsonApiContext jsonApiContext, string relationship, string attribute)
16+
public BaseAttrQuery(IJsonApiContext jsonApiContext, BaseQuery baseQuery)
1717
{
1818
_jsonApiContext = jsonApiContext;
19-
if (string.IsNullOrEmpty(relationship))
20-
Attribute = GetAttribute(attribute);
19+
if (baseQuery.IsAttributeOfRelationship)
20+
{
21+
Relationship = GetRelationship(baseQuery.Relationship);
22+
Attribute = GetAttribute(Relationship, baseQuery.Attribute);
23+
}
2124
else
2225
{
23-
Relationship = GetRelationship(relationship);
24-
Attribute = GetAttribute(Relationship, attribute);
26+
Attribute = GetAttribute(baseQuery.Attribute);
2527
}
2628

2729
}

src/JsonApiDotNetCore/Internal/Query/BaseFilterQuery.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using JsonApiDotNetCore.Models;
21
using JsonApiDotNetCore.Services;
32
using System;
43

@@ -8,17 +7,14 @@ public class BaseFilterQuery : BaseAttrQuery
87
{
98
public BaseFilterQuery(
109
IJsonApiContext jsonApiContext,
11-
string relationship,
12-
string attribute,
13-
string value,
14-
FilterOperations op)
15-
: base(jsonApiContext, relationship, attribute)
10+
FilterQuery filterQuery)
11+
: base(jsonApiContext, filterQuery)
1612
{
17-
PropertyValue = value;
18-
FilterOperation = op;
13+
PropertyValue = filterQuery.Value;
14+
FilterOperation = filterQuery.OperationType;
1915
}
2016

21-
[Obsolete("To resolve operation use enum typed " + nameof(FilterQuery.OperationType) + " property of "+ nameof(FilterQuery) +" class")]
17+
[Obsolete("Use " + nameof(FilterQuery.OperationType) + " instead.")]
2218
protected FilterOperations GetFilterOperation(string prefix)
2319
{
2420
if (prefix.Length == 0) return FilterOperations.eq;

src/JsonApiDotNetCore/Internal/Query/FilterQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public FilterQuery(string attribute, string value, FilterOperations operationTyp
3131
[Obsolete("Key has been replaced by '" + nameof(Attribute) + "'. Members should be located by their public name, not by coercing the provided value to the internal name.")]
3232
public string Key { get; set; }
3333
public string Value { get; set; }
34-
[Obsolete("Operation has been replaced by '" + nameof(OperationType) + "'. OperationType is typed enum value for Operation property. This should be default property for providing operation type, because of unsustainable string (not typed) value.")]
34+
[Obsolete("Use '" + nameof(OperationType) + "' instead.")]
3535
public string Operation { get; set; }
3636

3737
public FilterOperations OperationType { get; set; }

src/JsonApiDotNetCore/Internal/Query/RelatedAttrFilterQuery.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using JsonApiDotNetCore.Models;
43
using JsonApiDotNetCore.Services;
54

@@ -10,7 +9,7 @@ public class RelatedAttrFilterQuery : BaseFilterQuery
109
public RelatedAttrFilterQuery(
1110
IJsonApiContext jsonApiContext,
1211
FilterQuery filterQuery)
13-
:base(jsonApiContext, filterQuery.Relationship, filterQuery.Attribute, filterQuery.Value, filterQuery.OperationType)
12+
:base(jsonApiContext, filterQuery)
1413
{
1514
if (Relationship == null)
1615
throw new JsonApiException(400, $"{filterQuery.Relationship} is not a valid relationship on {jsonApiContext.RequestEntity.EntityName}.");
@@ -25,10 +24,10 @@ public RelatedAttrFilterQuery(
2524
FilteredAttribute = Attribute;
2625
}
2726

28-
[Obsolete("Use " + nameof(Attribute) + " property. It's shared for all implementations of BaseAttrQuery(better sort, filter) handling")]
27+
[Obsolete("Use " + nameof(Attribute) + " instead.")]
2928
public AttrAttribute FilteredAttribute { get; set; }
3029

31-
[Obsolete("Use " + nameof(Relationship) + " property. It's shared for all implementations of BaseAttrQuery(better sort, filter) handling")]
30+
[Obsolete("Use " + nameof(Relationship) + " instead.")]
3231
public RelationshipAttribute FilteredRelationship { get; set; }
3332
}
3433
}

src/JsonApiDotNetCore/Internal/Query/RelatedAttrSortQuery.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.Linq;
3-
using JsonApiDotNetCore.Models;
41
using JsonApiDotNetCore.Services;
52

63
namespace JsonApiDotNetCore.Internal.Query
@@ -10,7 +7,7 @@ public class RelatedAttrSortQuery : BaseAttrQuery
107
public RelatedAttrSortQuery(
118
IJsonApiContext jsonApiContext,
129
SortQuery sortQuery)
13-
:base(jsonApiContext, sortQuery.Relationship, sortQuery.Attribute)
10+
:base(jsonApiContext, sortQuery)
1411
{
1512
if (Relationship == null)
1613
throw new JsonApiException(400, $"{sortQuery.Relationship} is not a valid relationship on {jsonApiContext.RequestEntity.EntityName}.");

src/JsonApiDotNetCore/Services/QueryParser.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ protected virtual List<FilterQuery> ParseFilterQuery(string key, string value)
101101
return queries;
102102
}
103103

104-
[Obsolete("This method is not used anymore! Use " + nameof(ParseFilterOperationAndValue) + " method with FilterOperations operation return value." +
105-
"Operation as string is not used at all.")]
104+
[Obsolete("Use " + nameof(ParseFilterOperationAndValue) + " method instead.")]
106105
protected virtual (string operation, string value) ParseFilterOperation(string value)
107106
{
108107
if (value.Length < 3)
@@ -129,7 +128,7 @@ protected virtual (string operation, string value) ParseFilterOperation(string v
129128
/// </summary>
130129
/// <param name="input"></param>
131130
/// <returns></returns>
132-
public static (FilterOperations operation, string value) ParseFilterOperationAndValue(string input)
131+
protected virtual (FilterOperations operation, string value) ParseFilterOperationAndValue(string input)
133132
{
134133
// value is empty
135134
if (input.Length == 0)
@@ -170,7 +169,7 @@ public static (FilterOperations operation, string value) ParseFilterOperationAnd
170169
/// </summary>
171170
/// <param name="operation">String represented operation</param>
172171
/// <returns></returns>
173-
public static (FilterOperations operation, bool succeeded) GetFilterOperation(string operation)
172+
private static (FilterOperations operation, bool succeeded) GetFilterOperation(string operation)
174173
{
175174
var success = Enum.TryParse(operation, out FilterOperations opertion);
176175
return (opertion, success);
@@ -256,7 +255,6 @@ protected virtual List<string> ParseFieldsQuery(string key, string value)
256255
return includedFields;
257256
}
258257

259-
[Obsolete("Delete also when " + nameof(ParseFilterOperation) + " deleted.")]
260258
private string GetFilterOperationOld(string value)
261259
{
262260
var values = value.Split(QueryConstants.COLON);

0 commit comments

Comments
 (0)