diff --git a/Kyoo.Common/Utility.cs b/Kyoo.Common/Utility.cs index 19b23564..ee978f43 100644 --- a/Kyoo.Common/Utility.cs +++ b/Kyoo.Common/Utility.cs @@ -78,8 +78,9 @@ namespace Kyoo { Type type = typeof(T); IEnumerable properties = type.GetProperties() - .Where(x => x.CanRead && x.CanWrite - && Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null); + .Where(x => x.CanRead + && x.CanWrite + && Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null); foreach (PropertyInfo property in properties) { @@ -101,8 +102,9 @@ namespace Kyoo Type type = typeof(T); IEnumerable properties = type.GetProperties() - .Where(x => x.CanRead && x.CanWrite - && Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null); + .Where(x => x.CanRead + && x.CanWrite + && Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null); foreach (PropertyInfo property in properties) { @@ -129,8 +131,9 @@ namespace Kyoo Type type = typeof(T); IEnumerable properties = type.GetProperties() - .Where(x => x.CanRead && x.CanWrite - && Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null); + .Where(x => x.CanRead + && x.CanWrite + && Attribute.GetCustomAttribute(x, typeof(NotMergableAttribute)) == null); foreach (PropertyInfo property in properties) { diff --git a/Kyoo.CommonAPI/ApiHelper.cs b/Kyoo.CommonAPI/ApiHelper.cs index 15b8282f..3ffa79d0 100644 --- a/Kyoo.CommonAPI/ApiHelper.cs +++ b/Kyoo.CommonAPI/ApiHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; @@ -51,27 +52,40 @@ namespace Kyoo.CommonApi MemberExpression propertyExpr = Expression.Property(param, property); ConstantExpression valueExpr = null; - if (operand != "ctn" && !typeof(IResource).IsAssignableFrom(propertyExpr.Type)) + bool isList = typeof(IEnumerable).IsAssignableFrom(propertyExpr.Type); + if (operand != "ctn" && !typeof(IResource).IsAssignableFrom(propertyExpr.Type) && !isList) { Type propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType; - object val = string.IsNullOrEmpty(value) || value.Equals("null", StringComparison.OrdinalIgnoreCase) + object val; + try + { + val = string.IsNullOrEmpty(value) || value.Equals("null", StringComparison.OrdinalIgnoreCase) ? null : Convert.ChangeType(value, propertyType); + } + catch (InvalidCastException) + { + throw new ArgumentException("Comparing two differents value's type."); + } + valueExpr = Expression.Constant(val, property.PropertyType); } - + Expression condition = operand switch { + "eq" when isList => ContainsResourceExpression(propertyExpr, value), + "ctn" => ContainsResourceExpression(propertyExpr, value), + "eq" when valueExpr == null => ResourceEqual(propertyExpr, value), "not" when valueExpr == null => ResourceEqual(propertyExpr, value, true), + "eq" => Expression.Equal(propertyExpr, valueExpr), "not" => Expression.NotEqual(propertyExpr, valueExpr!), "lt" => StringCompatibleExpression(Expression.LessThan, propertyExpr, valueExpr), "lte" => StringCompatibleExpression(Expression.LessThanOrEqual, propertyExpr, valueExpr), "gt" => StringCompatibleExpression(Expression.GreaterThan, propertyExpr, valueExpr), "gte" => StringCompatibleExpression(Expression.GreaterThanOrEqual, propertyExpr, valueExpr), - "ctn" => ContainsResourceExpression(propertyExpr, value), - _ => throw new ArgumentException($"Invalid operand: {operand}") + _ => throw new ArgumentException($"Invalid operand: {operand}") }; if (expression != null) diff --git a/Kyoo/Views/API/SeasonApi.cs b/Kyoo/Views/API/SeasonApi.cs index 5cb47acd..67206ca1 100644 --- a/Kyoo/Views/API/SeasonApi.cs +++ b/Kyoo/Views/API/SeasonApi.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Kyoo.CommonApi; using Kyoo.Controllers; using Kyoo.Models; -using Kyoo.Models.Exceptions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Linq; diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 32168468..7a980871 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 3216846879e75fdc1b9ec4efc1da7599ee6e9e2c +Subproject commit 7a9808719933a092e56fc26be8f5c40bf7894e7c