mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Allow kind to be used as a filter
This commit is contained in:
parent
9609fb150a
commit
29d846a944
@ -209,6 +209,17 @@ public abstract record Filter<T> : Filter
|
||||
return property.Then(prop =>
|
||||
{
|
||||
Type[] types = typeof(T).GetCustomAttribute<OneOfAttribute>()?.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<string>, (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();
|
||||
|
@ -39,6 +39,8 @@ public static class DapperHelper
|
||||
{
|
||||
private static string _Property(string key, Dictionary<string, Type> 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<ColumnAttribute>()?.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<string> properties = config
|
||||
.Where(x => key == "id" || x.Value.GetProperty(key) != null)
|
||||
.Select(x => $"{x.Key}.{x.Value.GetProperty(key)?.GetCustomAttribute<ColumnAttribute>()?.Name ?? key.ToSnakeCase()}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user