-
Notifications
You must be signed in to change notification settings - Fork 33
/
TimestampParameter.cs
108 lines (93 loc) 路 4.02 KB
/
TimestampParameter.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
96
97
98
99
100
101
102
103
104
105
106
107
108
锘縰sing System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Annotations;
using Tzkt.Api.Services.Cache;
namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(TimestampBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class TimestampParameter
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
/// Specify a datetime value to get items where the specified field is equal to the specified value.
///
/// Example: `?timestamp=2020-02-20T02:40:57Z`.
/// </summary>
[JsonSchemaType(typeof(DateTime?))]
public int? Eq { get; set; }
/// <summary>
/// **Not equal** filter mode. \
/// Specify a datetime value to get items where the specified field is not equal to the specified value.
///
/// Example: `?timestamp.ne=2020-02-20T02:40:57Z`.
/// </summary>
[JsonSchemaType(typeof(DateTime?))]
public int? Ne { get; set; }
/// <summary>
/// **Greater than** filter mode. \
/// Specify a datetime value to get items where the specified field is greater than the specified value.
///
/// Example: `?timestamp.gt=2020-02-20T02:40:57Z`.
/// </summary>
[JsonSchemaType(typeof(DateTime?))]
public int? Gt { get; set; }
/// <summary>
/// **Greater or equal** filter mode. \
/// Specify a datetime value to get items where the specified field is greater than equal to the specified value.
///
/// Example: `?timestamp.ge=2020-02-20T02:40:57Z`.
/// </summary>
[JsonSchemaType(typeof(DateTime?))]
public int? Ge { get; set; }
/// <summary>
/// **Less than** filter mode. \
/// Specify a datetime value to get items where the specified field is less than the specified value.
///
/// Example: `?timestamp.lt=2020-02-20T02:40:57Z`.
/// </summary>
[JsonSchemaType(typeof(DateTime?))]
public int? Lt { get; set; }
/// <summary>
/// **Less or equal** filter mode. \
/// Specify a datetime value to get items where the specified field is less than or equal to the specified value.
///
/// Example: `?timestamp.le=2020-02-20T02:40:57Z`.
/// </summary>
[JsonSchemaType(typeof(DateTime?))]
public int? Le { get; set; }
/// <summary>
/// **In list** (any of) filter mode. \
/// Specify a comma-separated list of datetimes to get items where the specified field is equal to one of the specified values.
///
/// Example: `?timestamp.in=2020-02-20,2020-02-21`.
/// </summary>
[JsonSchemaType(typeof(List<DateTime>))]
public List<int> In { get; set; }
/// <summary>
/// **Not in list** (none of) filter mode. \
/// Specify a comma-separated list of datetimes to get items where the specified field is not equal to all the specified values.
///
/// Example: `?timestamp.ni=2020-02-20,2020-02-21`.
/// </summary>
[JsonSchemaType(typeof(List<DateTime>))]
public List<int> Ni { get; set; }
#region static
public static Int32Parameter FromDateTimeParameter(DateTimeParameter timestamp, TimeCache time)
{
if (timestamp == null) return null;
var res = new Int32Parameter();
if (timestamp.Eq != null)
res.Eq = time.FindLevel((DateTime)timestamp.Eq, SearchMode.Exact);
if (timestamp.Ne != null)
res.Ne = time.FindLevel((DateTime)timestamp.Ne, SearchMode.Exact);
if (timestamp.Gt != null)
res.Gt = time.FindLevel((DateTime)timestamp.Gt, SearchMode.ExactOrLower);
if (timestamp.Ge != null)
res.Ge = time.FindLevel((DateTime)timestamp.Ge, SearchMode.ExactOrLower);
return res;
}
#endregion
}
}