From decd40c72ba0aaef29bb7b57c8fe6e21fba76083 Mon Sep 17 00:00:00 2001 From: tpz Date: Tue, 27 Feb 2024 21:45:53 +0100 Subject: [PATCH] fix: correction of bugs found by new documentation tests --- EvitaDB.Client/DataTypes/EvitaDataTypes.cs | 4 ++-- EvitaDB.Client/Models/ExtraResults/Hierarchy.cs | 13 +++++++++++-- EvitaDB.Client/Queries/Filter/AttributeInRange.cs | 6 +++++- EvitaDB.Client/Queries/IQueryConstraints.cs | 3 ++- .../Json/Converters/EntitySerializer.cs | 10 +++++++++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/EvitaDB.Client/DataTypes/EvitaDataTypes.cs b/EvitaDB.Client/DataTypes/EvitaDataTypes.cs index 23b1d47..55faf66 100644 --- a/EvitaDB.Client/DataTypes/EvitaDataTypes.cs +++ b/EvitaDB.Client/DataTypes/EvitaDataTypes.cs @@ -266,7 +266,7 @@ public static string FormatValue(object? value) } if (value is bool boolValue) { - return boolValue.ToString()!; + return boolValue.ToString().ToLower(); } if (value is Range range) { @@ -341,4 +341,4 @@ private static string DateTimeMillisecondFormat(int milliseconds) // Three or more digits in milliseconds, format with three milliseconds return ".fff"; } -} \ No newline at end of file +} diff --git a/EvitaDB.Client/Models/ExtraResults/Hierarchy.cs b/EvitaDB.Client/Models/ExtraResults/Hierarchy.cs index c358adf..34958fd 100644 --- a/EvitaDB.Client/Models/ExtraResults/Hierarchy.cs +++ b/EvitaDB.Client/Models/ExtraResults/Hierarchy.cs @@ -186,7 +186,7 @@ private void AppendLevelInfoTreeString(StringBuilder treeBuilder, LevelInfo leve } } -public record LevelInfo(IEntityClassifier Entity, bool Requested, int? QueriedEntityCount, int? ChildrenCount, List Children) +public record LevelInfo(IEntityClassifier Entity, bool Requested, int? QueriedEntityCount, int? ChildrenCount, List Children) : IComparable { public LevelInfo(LevelInfo levelInfo, List children) : this(levelInfo.Entity, levelInfo.Requested, levelInfo.QueriedEntityCount, levelInfo.ChildrenCount, children) @@ -202,4 +202,13 @@ public override string ToString() return $"[{QueriedEntityCount}:{ChildrenCount} {Entity}]"; } -} \ No newline at end of file + + public int CompareTo(object? other) + { + if (other is not LevelInfo levelInfo) + { + return 1; + } + return Entity.PrimaryKey!.Value.CompareTo(levelInfo.Entity.PrimaryKey!.Value); + } +} diff --git a/EvitaDB.Client/Queries/Filter/AttributeInRange.cs b/EvitaDB.Client/Queries/Filter/AttributeInRange.cs index 7bb6e0d..c73566b 100644 --- a/EvitaDB.Client/Queries/Filter/AttributeInRange.cs +++ b/EvitaDB.Client/Queries/Filter/AttributeInRange.cs @@ -24,9 +24,10 @@ namespace EvitaDB.Client.Queries.Filter; /// inRange("age", 63) /// /// -public class AttributeInRange : AbstractAttributeFilterConstraintLeaf +public class AttributeInRange : AbstractAttributeFilterConstraintLeaf, IConstraintWithSuffix where T : IComparable { + private static readonly string SuffixNow = "now"; private AttributeInRange(params object?[] arguments) : base(arguments) { } @@ -73,4 +74,7 @@ public AttributeInRange(string attributeName, byte value) : base(attributeName, public TNumber? TheValue() where TNumber : struct, IComparable => Arguments is [_, TNumber theValue and (byte or short or int or long or decimal)] ? theValue : null; + + public string? SuffixIfApplied => Arguments.Length == 1 ? SuffixNow : null; + public bool ArgumentImplicitForSuffix(object argument) => false; } diff --git a/EvitaDB.Client/Queries/IQueryConstraints.cs b/EvitaDB.Client/Queries/IQueryConstraints.cs index 9eb62f5..c24539c 100644 --- a/EvitaDB.Client/Queries/IQueryConstraints.cs +++ b/EvitaDB.Client/Queries/IQueryConstraints.cs @@ -184,7 +184,8 @@ dateTimeOffsetValue is null decimalValue is null ? null : new AttributeInRange(attributeName, decimalValue.Value); /// - static AttributeInRange AttributeInRangeNow(string attributeName) => new(attributeName); + static AttributeInRange? AttributeInRangeNow(string? attributeName) => + attributeName is null ? null : new AttributeInRange(attributeName!); /// static AttributeInSet? AttributeInSet(string? attributeName, params T?[]? set) diff --git a/EvitaDB.QueryValidator/Serialization/Json/Converters/EntitySerializer.cs b/EvitaDB.QueryValidator/Serialization/Json/Converters/EntitySerializer.cs index 473a555..21da2de 100644 --- a/EvitaDB.QueryValidator/Serialization/Json/Converters/EntitySerializer.cs +++ b/EvitaDB.QueryValidator/Serialization/Json/Converters/EntitySerializer.cs @@ -2,6 +2,7 @@ using EvitaDB.Client.DataTypes; using EvitaDB.Client.Models.Data; using EvitaDB.Client.Models.Schemas; +using EvitaDB.Client.Utils; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -43,7 +44,14 @@ public override void WriteJson(JsonWriter writer, ISealedEntity? value, JsonSeri if (value.InnerRecordHandling != PriceInnerRecordHandling.Unknown) { writer.WritePropertyName("priceInnerRecordHandling"); - writer.WriteValue(value.InnerRecordHandling?.ToString().ToUpper()); + if (value.InnerRecordHandling != null) + { + writer.WriteValue(StringUtils.ToUpperSnakeCase(value.InnerRecordHandling!.ToString()!)); + } + else + { + writer.WriteNull(); + } } WriteAttributes(writer, value);