diff --git a/back/src/Kyoo.Abstractions/Models/Utils/Filter.cs b/back/src/Kyoo.Abstractions/Models/Utils/Filter.cs index eac8c63c..634c5777 100644 --- a/back/src/Kyoo.Abstractions/Models/Utils/Filter.cs +++ b/back/src/Kyoo.Abstractions/Models/Utils/Filter.cs @@ -209,6 +209,17 @@ public abstract record Filter : Filter return property.Then(prop => { Type[] types = typeof(T).GetCustomAttribute()?.Types ?? new[] { typeof(T) }; + + if (string.Equals(prop, "kind", StringComparison.OrdinalIgnoreCase)) + { + return + from eq in op + from val in types + .Select(x => Parse.IgnoreCase(x.Name).Text()) + .Aggregate(null as Parser, (acc, x) => acc == null ? x : Parse.Or(acc, x)) + select apply("kind", val); + } + PropertyInfo? propInfo = types .Select(x => x.GetProperty(prop, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance)) .FirstOrDefault(); diff --git a/back/src/Kyoo.Core/Controllers/Repositories/DapperHelper.cs b/back/src/Kyoo.Core/Controllers/Repositories/DapperHelper.cs index ac59ef00..39a30f11 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/DapperHelper.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/DapperHelper.cs @@ -39,6 +39,8 @@ public static class DapperHelper { private static string _Property(string key, Dictionary config) { + if (key == "kind") + return "kind"; string[] keys = config .Where(x => key == "id" || x.Value.GetProperty(key) != null) .Select(x => $"{x.Key}.{x.Value.GetProperty(key)?.GetCustomAttribute()?.Name ?? key.ToSnakeCase()}") @@ -125,6 +127,20 @@ public static class DapperHelper { FormattableString Format(string key, FormattableString op) { + if (key == "kind") + { + string cases = string.Join('\n', config + .Skip(1) + .Select(x => $"when {x.Key}.id is not null then '{x.Value.Name.ToLowerInvariant()}'") + ); + return $""" + case + {cases:raw} + else '{config.First().Value.Name.ToLowerInvariant():raw}' + end {op} + """; + } + IEnumerable properties = config .Where(x => key == "id" || x.Value.GetProperty(key) != null) .Select(x => $"{x.Key}.{x.Value.GetProperty(key)?.GetCustomAttribute()?.Name ?? key.ToSnakeCase()}");