forked from JSONAPIdotNET/JSONAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultSortExpressionExtractor.cs
More file actions
21 lines (19 loc) · 717 Bytes
/
DefaultSortExpressionExtractor.cs
File metadata and controls
21 lines (19 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Linq;
using System.Net.Http;
namespace JSONAPI.Http
{
/// <summary>
/// Default implementation of <see cref="ISortExpressionExtractor" />
/// </summary>
public class DefaultSortExpressionExtractor : ISortExpressionExtractor
{
private const string SortQueryParamKey = "sort";
public string[] ExtractSortExpressions(HttpRequestMessage requestMessage)
{
var queryParams = requestMessage.GetQueryNameValuePairs();
var sortParam = queryParams.FirstOrDefault(kvp => kvp.Key == SortQueryParamKey);
if (sortParam.Key != SortQueryParamKey) return new string[] {};
return sortParam.Value.Split(',');
}
}
}