diff --git a/Tzkt.Api/Parameters/Binders/TimestampBinder.cs b/Tzkt.Api/Parameters/Binders/TimestampBinder.cs index 378aeab8..00cda7e7 100644 --- a/Tzkt.Api/Parameters/Binders/TimestampBinder.cs +++ b/Tzkt.Api/Parameters/Binders/TimestampBinder.cs @@ -53,17 +53,36 @@ public Task BindModelAsync(ModelBindingContext bindingContext) return Task.CompletedTask; } - bindingContext.Result = ModelBindingResult.Success(new TimestampParameter + var param = new TimestampParameter { Eq = (value ?? eq) == null ? null : Time.FindLevel((DateTime)(value ?? eq), SearchMode.Exact), Ne = ne == null ? null : Time.FindLevel((DateTime)ne, SearchMode.Exact), - Gt = gt == null ? null : Time.FindLevel((DateTime)gt, SearchMode.ExactOrLower), - Ge = ge == null ? null : Time.FindLevel((DateTime)ge, SearchMode.ExactOrHigher), - Lt = lt == null ? null : Time.FindLevel((DateTime)lt, SearchMode.ExactOrHigher), - Le = le == null ? null : Time.FindLevel((DateTime)le, SearchMode.ExactOrLower), In = @in?.Select(x => Time.FindLevel(x, SearchMode.Exact)).ToList(), Ni = ni?.Select(x => Time.FindLevel(x, SearchMode.Exact)).ToList(), - }); + }; + + if (gt != null) + { + var level = Time.FindLevel((DateTime)gt, SearchMode.ExactOrLower); + param.Gt = level != -1 ? level : null; + } + if (ge != null) + { + var level = Time.FindLevel((DateTime)ge, SearchMode.ExactOrHigher); + param.Ge = level != -1 ? level : int.MaxValue; + } + if (lt != null) + { + var level = Time.FindLevel((DateTime)lt, SearchMode.ExactOrHigher); + param.Lt = level != -1 ? level : null; + } + if (le != null) + { + var level = Time.FindLevel((DateTime)le, SearchMode.ExactOrLower); + param.Le = level != -1 ? level : int.MinValue; + } + + bindingContext.Result = ModelBindingResult.Success(param); return Task.CompletedTask; } diff --git a/Tzkt.Api/Parameters/TimestampParameter.cs b/Tzkt.Api/Parameters/TimestampParameter.cs index c6299123..4e97b9dd 100644 --- a/Tzkt.Api/Parameters/TimestampParameter.cs +++ b/Tzkt.Api/Parameters/TimestampParameter.cs @@ -84,29 +84,6 @@ public class TimestampParameter : INormalizable [JsonSchemaType(typeof(List))] public List 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 - public string Normalize(string name) { var sb = new StringBuilder(); diff --git a/Tzkt.Api/Repositories/AccountRepository.cs b/Tzkt.Api/Repositories/AccountRepository.cs index 5cb9c967..173631e1 100644 --- a/Tzkt.Api/Repositories/AccountRepository.cs +++ b/Tzkt.Api/Repositories/AccountRepository.cs @@ -2165,13 +2165,30 @@ public async Task> GetOperations( { Eq = timestamp.Eq == null ? null : Time.FindLevel((DateTime)timestamp.Eq, SearchMode.Exact), Ne = timestamp.Ne == null ? null : Time.FindLevel((DateTime)timestamp.Ne, SearchMode.Exact), - Gt = timestamp.Gt == null ? null : Time.FindLevel((DateTime)timestamp.Gt, SearchMode.ExactOrLower), - Ge = timestamp.Ge == null ? null : Time.FindLevel((DateTime)timestamp.Ge, SearchMode.ExactOrHigher), - Lt = timestamp.Lt == null ? null : Time.FindLevel((DateTime)timestamp.Lt, SearchMode.ExactOrHigher), - Le = timestamp.Le == null ? null : Time.FindLevel((DateTime)timestamp.Le, SearchMode.ExactOrLower), In = timestamp.In?.Select(x => Time.FindLevel(x, SearchMode.Exact)).ToList(), - Ni = timestamp.Ni?.Select(x => Time.FindLevel(x, SearchMode.Exact)).ToList(), + Ni = timestamp.Ni?.Select(x => Time.FindLevel(x, SearchMode.Exact)).ToList() }; + + if (timestamp.Gt != null) + { + var lvl = Time.FindLevel((DateTime)timestamp.Gt, SearchMode.ExactOrLower); + _timestamp.Gt = lvl != -1 ? lvl : null; + } + if (timestamp.Ge != null) + { + var lvl = Time.FindLevel((DateTime)timestamp.Ge, SearchMode.ExactOrHigher); + _timestamp.Ge = lvl != -1 ? lvl : int.MaxValue; + } + if (timestamp.Lt != null) + { + var lvl = Time.FindLevel((DateTime)timestamp.Lt, SearchMode.ExactOrHigher); + _timestamp.Lt = lvl != -1 ? lvl : null; + } + if (timestamp.Le != null) + { + var lvl = Time.FindLevel((DateTime)timestamp.Le, SearchMode.ExactOrLower); + _timestamp.Le = lvl != -1 ? lvl : int.MinValue; + } } switch (account)