This repository was archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIFilter.cs
More file actions
45 lines (36 loc) · 1.27 KB
/
IFilter.cs
File metadata and controls
45 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using AniAPI.NET.Enums;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AniAPI.NET.Interfaces
{
public abstract class IFilter
{
protected Dictionary<string, string> Parameters = new Dictionary<string, string>();
public long[] Ids { get; set; }
public Dictionary<string, SortDirectionEnum> Sort { get; set; }
protected abstract void FillQueryParameters();
public string ToQueryString()
{
string queryString = string.Empty;
if (Ids != null && Ids.Length > 0)
{
Parameters.Add("ids", String.Join(',', Ids.Select(x => x.ToString())));
}
FillQueryParameters();
if(Sort != null && Sort.Keys.Count > 0)
{
Parameters.Add("sort_fields", String.Join(',', Sort.Keys.Select(x => x)));
Parameters.Add("sort_directions", String.Join(',', Sort.Values.Select(x => ((int)x).ToString())));
}
if(Parameters.Count > 0)
{
queryString = "?" + String.Join('&', Parameters.Select(x => $"{x.Key}={x.Value}"));
}
return queryString;
}
}
}