Skip to content

Commit d1bc2cb

Browse files
committed
finish deprecating old APIs
1 parent 0be3300 commit d1bc2cb

File tree

3 files changed

+17
-60
lines changed

3 files changed

+17
-60
lines changed

Diff for: src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public virtual IQueryable<TEntity> Sort(IQueryable<TEntity> entities, List<SortQ
116116
foreach (var sortProp in defaultSortOrder)
117117
{
118118
// this is dumb...add an overload, don't allocate for no reason
119-
entities.Sort(new SortQuery(sortProp.Item2, sortProp.Item1));
119+
entities.Sort(_jsonApiContext, new SortQuery(sortProp.Item2, sortProp.Item1.PublicAttributeName));
120120
}
121121
}
122122
}

Diff for: src/JsonApiDotNetCore/Extensions/IQueryableExtensions.cs

+6-50
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,14 @@ private static MethodInfo ContainsMethod
2828
}
2929
}
3030

31-
[Obsolete("Use Sort method with IJsonApiContext parameter instead. New Sort method provides nested sorting.")]
32-
public static IQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, List<SortQuery> sortQueries)
33-
{
34-
if (sortQueries == null || sortQueries.Count == 0)
35-
return source;
36-
37-
var orderedEntities = source.Sort(sortQueries[0]);
38-
39-
if (sortQueries.Count <= 1)
40-
return orderedEntities;
41-
42-
for (var i = 1; i < sortQueries.Count; i++)
43-
orderedEntities = orderedEntities.Sort(sortQueries[i]);
44-
45-
return orderedEntities;
46-
}
47-
48-
[Obsolete("Use Sort method with IJsonApiContext parameter instead. New Sort method provides nested sorting.")]
49-
public static IOrderedQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, SortQuery sortQuery)
50-
{
51-
// For clients using SortQuery constructor with string based parameter
52-
if (sortQuery.SortedAttribute == null)
53-
throw new JsonApiException(400, $"It's not possible to provide {nameof(SortQuery)} without {nameof(SortQuery.SortedAttribute)} parameter." +
54-
$" Use Sort method with IJsonApiContext parameter instead.");
31+
[Obsolete("Use overload Sort<T>(IJsonApiContext, List<SortQuery>) instead.", error: true)]
32+
public static IQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, List<SortQuery> sortQueries) => null;
5533

56-
return sortQuery.Direction == SortDirection.Descending
57-
? source.OrderByDescending(sortQuery.SortedAttribute.InternalAttributeName)
58-
: source.OrderBy(sortQuery.SortedAttribute.InternalAttributeName);
59-
}
34+
[Obsolete("Use overload Sort<T>(IJsonApiContext, SortQuery) instead.", error: true)]
35+
public static IOrderedQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, SortQuery sortQuery) => null;
6036

61-
[Obsolete("Use Sort method with IJsonApiContext parameter instead. New Sort method provides nested sorting.")]
62-
public static IOrderedQueryable<TSource> Sort<TSource>(this IOrderedQueryable<TSource> source, SortQuery sortQuery)
63-
{
64-
// For clients using SortQuery constructor with string based parameter
65-
if (sortQuery.SortedAttribute == null)
66-
throw new JsonApiException(400, $"It's not possible to provide {nameof(SortQuery)} without {nameof(SortQuery.SortedAttribute)} parameter." +
67-
$" Use Sort method with IJsonApiContext parameter instead.");
68-
69-
return sortQuery.Direction == SortDirection.Descending
70-
? source.ThenByDescending(sortQuery.SortedAttribute.InternalAttributeName)
71-
: source.ThenBy(sortQuery.SortedAttribute.InternalAttributeName);
72-
}
37+
[Obsolete("Use overload Sort<T>(IJsonApiContext, SortQuery) instead.", error: true)]
38+
public static IOrderedQueryable<TSource> Sort<TSource>(this IOrderedQueryable<TSource> source, SortQuery sortQuery) => null;
7339

7440
public static IQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, IJsonApiContext jsonApiContext, List<SortQuery> sortQueries)
7541
{
@@ -89,11 +55,6 @@ public static IQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source,
8955

9056
public static IOrderedQueryable<TSource> Sort<TSource>(this IQueryable<TSource> source, IJsonApiContext jsonApiContext, SortQuery sortQuery)
9157
{
92-
// For clients using constructor with AttrAttribute parameter
93-
if (sortQuery.SortedAttribute != null)
94-
throw new JsonApiException(400, $"It's not possible to provide {nameof(SortQuery)} with {nameof(SortQuery.SortedAttribute)} parameter." +
95-
$" Use {nameof(SortQuery)} constructor overload based on string attribute.");
96-
9758
BaseAttrQuery attr;
9859
if (sortQuery.IsAttributeOfRelationship)
9960
attr = new RelatedAttrSortQuery(jsonApiContext, sortQuery);
@@ -107,11 +68,6 @@ public static IOrderedQueryable<TSource> Sort<TSource>(this IQueryable<TSource>
10768

10869
public static IOrderedQueryable<TSource> Sort<TSource>(this IOrderedQueryable<TSource> source, IJsonApiContext jsonApiContext, SortQuery sortQuery)
10970
{
110-
// For clients using constructor with AttrAttribute parameter
111-
if (sortQuery.SortedAttribute != null)
112-
throw new JsonApiException(400, $"It's not possible to provide {nameof(SortQuery)} with {nameof(SortQuery.SortedAttribute)} parameter." +
113-
$" Use {nameof(SortQuery)} constructor overload based on string attribute.");
114-
11571
BaseAttrQuery attr;
11672
if (sortQuery.IsAttributeOfRelationship)
11773
attr = new RelatedAttrSortQuery(jsonApiContext, sortQuery);

Diff for: src/JsonApiDotNetCore/Internal/Query/SortQuery.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33

44
namespace JsonApiDotNetCore.Internal.Query
55
{
6+
/// <summary>
7+
/// An internal representation of the raw sort query.
8+
/// </summary>
69
public class SortQuery : BaseQuery
710
{
8-
[Obsolete("Use constructor with string attribute parameter. New constructor provides nested sort feature.")]
11+
[Obsolete("Use constructor overload (SortDirection, string) instead.", error: true)]
912
public SortQuery(SortDirection direction, AttrAttribute sortedAttribute)
10-
:base(sortedAttribute.InternalAttributeName)
11-
{
12-
Direction = direction;
13-
SortedAttribute = sortedAttribute;
14-
if (SortedAttribute.IsSortable == false)
15-
throw new JsonApiException(400, $"Sort is not allowed for attribute '{SortedAttribute.PublicAttributeName}'.");
16-
}
13+
: base(sortedAttribute.PublicAttributeName) { }
1714

1815
public SortQuery(SortDirection direction, string attribute)
1916
: base(attribute)
2017
{
2118
Direction = direction;
2219
}
2320

21+
/// <summary>
22+
/// Direction the sort should be applied
23+
/// </summary>
2424
public SortDirection Direction { get; set; }
25-
[Obsolete("Use string based Attribute instead. This provides nested sort feature (e.g. ?sort=owner.first-name)")]
25+
26+
[Obsolete("Use string based Attribute instead.", error: true)]
2627
public AttrAttribute SortedAttribute { get; set; }
2728
}
2829
}

0 commit comments

Comments
 (0)