-
Notifications
You must be signed in to change notification settings - Fork 34
/
OffsetParameter.cs
60 lines (51 loc) · 1.75 KB
/
OffsetParameter.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
using System.Text;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Annotations;
namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(OffsetBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class OffsetParameter : INormalizable
{
/// <summary>
/// **Elements** offset mode (optional, i.e. `offset.el=123` is the same as `offset=123`). \
/// Skips specified number of elements.
///
/// Example: `?offset=100`.
/// </summary>
public int? El { get; set; }
/// <summary>
/// **Page** offset mode. \
/// Skips `page * limit` elements. This is a classic pagination.
///
/// Example: `?offset.pg=1`.
/// </summary>
public int? Pg { get; set; }
/// <summary>
/// **Cursor** offset mode. \
/// Skips all elements with the `cursor` before (including) the specified value. Cursor is a field used for sorting, e.g. `id`.
/// Avoid using this offset mode with non-unique or non-sequential cursors such as `amount`, `balance`, etc.
///
/// Example: `?offset.cr=45837`.
/// </summary>
public long? Cr { get; set; }
public static implicit operator OffsetParameter(int offset) => new() { El = offset };
public string Normalize(string name)
{
var sb = new StringBuilder();
if (El != null)
{
sb.Append($"offset.el={El}&");
}
if (Pg != null)
{
sb.Append($"offset.pg={Pg}&");
}
if (Cr != null)
{
sb.Append($"offset.cr={Cr}");
}
return sb.ToString();
}
}
}