-
Notifications
You must be signed in to change notification settings - Fork 34
/
AddressNullParameter.cs
95 lines (80 loc) 路 2.93 KB
/
AddressNullParameter.cs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
锘縰sing System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Annotations;
namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(AddressNullBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class AddressNullParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=` is the same as `param=`). \
/// Specify an account address to get items where the specified field is equal to the specified value.
///
/// Example: `?address=tz123..`.
/// </summary>
public string Eq { get; set; }
/// <summary>
/// **Not equal** filter mode. \
/// Specify an account address to get items where the specified field is not equal to the specified value.
///
/// Example: `?address.ne=tz123..`.
/// </summary>
public string Ne { get; set; }
/// <summary>
/// **In list** (any of) filter mode. \
/// Specify a comma-separated list of account addresses to get items where the specified field is equal to one of the specified values.
///
/// Example: `?address.in=tz123..,tz345..`.
/// </summary>
public List<string> In { get; set; }
/// <summary>
/// **Not in list** (none of) filter mode. \
/// Specify a comma-separated list of account addresses to get items where the specified field is not equal to all the specified values.
///
/// Example: `?address.ni=tz123..,tz345..`.
/// </summary>
public List<string> Ni { get; set; }
/// <summary>
/// **Is null** filter mode. \
/// Use this mode to get items where the specified field is null or not.
///
/// Example: `?address.null` or `?address.null=false`.
/// </summary>
public bool? Null { get; set; }
[JsonIgnore]
public bool InHasNull { get; set; }
[JsonIgnore]
public bool NiHasNull { get; set; }
public string Normalize(string name)
{
var sb = new StringBuilder();
if (Eq != null)
{
sb.Append($"{name}.eq={Eq}&");
}
if (Ne != null)
{
sb.Append($"{name}.ne={Ne}&");
}
if (In?.Count > 0)
{
sb.Append($"{name}.in={string.Join(",", In.OrderBy(x => x))}&");
}
if (Ni?.Count > 0)
{
sb.Append($"{name}.ni={string.Join(",", Ni.OrderBy(x => x))}&");
}
if (Null != null)
{
sb.Append($"{name}.null={Null}&");
}
sb.Append($"{name}.NiHasNull={NiHasNull}&");
sb.Append($"{name}.InHasNull={InHasNull}&");
return sb.ToString();
}
}
}