new ordering system added

This commit is contained in:
2024-09-29 23:00:32 +02:00
Unverified
parent 69937f13e6
commit 450e4a2f94
19 changed files with 275 additions and 59 deletions

View File

@@ -52,14 +52,18 @@ public abstract class QueryParameters
#region PRIVATE METHODS
protected static bool TestBoolean(bool property, bool? query) =>
protected static bool Test<T>(T? property, T? query) =>
(
query is null
||
property == query
(
property is not null
&&
property.Equals(query)
)
);
protected static bool TestString(string? property, string? regexQuery) =>
protected static bool TestStringWithRegex(string? property, string? regexQuery) =>
(
string.IsNullOrEmpty(regexQuery)
||
@@ -108,7 +112,7 @@ public abstract class QueryParameters
public abstract class QueryParameters<T> : QueryParameters where T : class
public abstract class QueryParameters<T> : QueryParameters where T : IQueryOrderable<T>
{
#region PUBLIC METHODS
@@ -120,22 +124,9 @@ public abstract class QueryParameters<T> : QueryParameters where T : class
if (OrderBy is not null)
{
PropertyInfo[] properties = typeof(T).GetProperties();
foreach (PropertyInfo property in properties)
if (T.OrderableProperties.TryGetValue(OrderBy, out Func<T, IComparable>? orderFunc))
{
JsonPropertyNameAttribute? attribute = property.GetCustomAttributes<JsonPropertyNameAttribute>(true).FirstOrDefault();
if (attribute is not null && attribute.Name == OrderBy)
{
if (Order == "asc")
{
data = data.OrderBy(property.GetValue);
}
else
{
data = data.OrderByDescending(property.GetValue);
}
break;
}
data = Order == "asc" ? data.OrderBy(orderFunc) : data.OrderByDescending(orderFunc);
}
}
if (After is not null)