diff --git a/back/src/Kyoo.Meilisearch/FilterExtensionMethods.cs b/back/src/Kyoo.Meilisearch/FilterExtensionMethods.cs index 56d68a41..fde9a00f 100644 --- a/back/src/Kyoo.Meilisearch/FilterExtensionMethods.cs +++ b/back/src/Kyoo.Meilisearch/FilterExtensionMethods.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.ComponentModel.DataAnnotations; using Kyoo.Abstractions.Models.Utils; using static System.Text.Json.JsonNamingPolicy; @@ -46,22 +45,7 @@ internal static class FilterExtensionMethods }; } - public static object? InMeilisearchFormat(this object? value) - { - return value switch - { - null => null, - string => value, - Enum => value.ToString(), - IEnumerable enumerable - => enumerable.Cast().Select(InMeilisearchFormat).ToArray(), - DateTimeOffset dateTime => dateTime.ToUnixTimeSeconds(), - DateOnly date => date.ToUnixTimeSeconds(), - _ => value - }; - } - - private static long ToUnixTimeSeconds(this DateOnly date) + public static long ToUnixTimeSeconds(this DateOnly date) { return new DateTimeOffset(date.ToDateTime(new TimeOnly())).ToUnixTimeSeconds(); } diff --git a/back/src/Kyoo.Meilisearch/MeiliSync.cs b/back/src/Kyoo.Meilisearch/MeiliSync.cs index 8930c0b8..500fd974 100644 --- a/back/src/Kyoo.Meilisearch/MeiliSync.cs +++ b/back/src/Kyoo.Meilisearch/MeiliSync.cs @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . +using System.Collections; using System.Dynamic; using System.Reflection; using Kyoo.Abstractions.Controllers; @@ -62,7 +63,7 @@ public class MeiliSync foreach (PropertyInfo property in item.GetType().GetProperties()) dictionary.Add( CamelCase.ConvertName(property.Name), - property.GetValue(item).InMeilisearchFormat() + ConvertToMeilisearchFormat(property.GetValue(item)) ); dictionary.Add("ref", $"{kind}-{item.Id}"); expando.kind = kind; @@ -79,4 +80,19 @@ public class MeiliSync } return _client.Index(index).DeleteOneDocumentAsync(id.ToString()); } + + private object? ConvertToMeilisearchFormat(object? value) + { + return value switch + { + null => null, + string => value, + Enum => value.ToString(), + IEnumerable enumerable + => enumerable.Cast().Select(ConvertToMeilisearchFormat).ToArray(), + DateTimeOffset dateTime => dateTime.ToUnixTimeSeconds(), + DateOnly date => date.ToUnixTimeSeconds(), + _ => value + }; + } }