(feature): paged request lower case comparison
This commit is contained in:
parent
39d97500e9
commit
85f1d7c89f
@ -2,6 +2,8 @@
|
||||
using Xunit;
|
||||
using MaksIT.Core.Webapi.Models; // Ensure namespace matches the actual namespace of PagedRequest
|
||||
|
||||
namespace MaksIT.Core.Tests.Webapi.Models;
|
||||
|
||||
public class PagedRequestTests {
|
||||
|
||||
public class TestEntity {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
<!-- NuGet package metadata -->
|
||||
<PackageId>MaksIT.Core</PackageId>
|
||||
<Version>1.3.0</Version>
|
||||
<Version>1.3.1</Version>
|
||||
<Authors>Maksym Sadovnychyy</Authors>
|
||||
<Company>MAKS-IT</Company>
|
||||
<Product>MaksIT.Core</Product>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System.Linq.Dynamic.Core;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text.RegularExpressions;
|
||||
using MaksIT.Core.Abstractions.Webapi;
|
||||
|
||||
public class PagedRequest : RequestModelBase {
|
||||
@ -14,12 +15,26 @@ public class PagedRequest : RequestModelBase {
|
||||
if (string.IsNullOrWhiteSpace(Filters))
|
||||
return x => true; // Returns an expression that doesn't filter anything.
|
||||
|
||||
// Parse the filter string into a dynamic lambda expression.
|
||||
// Adjust Filters to make Contains, StartsWith, EndsWith, ==, and != case-insensitive
|
||||
string adjustedFilters = Filters
|
||||
.Replace(".Contains(", ".ToLower().Contains(")
|
||||
.Replace(".StartsWith(", ".ToLower().StartsWith(")
|
||||
.Replace(".EndsWith(", ".ToLower().EndsWith(")
|
||||
.Replace("==", ".ToLower() ==")
|
||||
.Replace("!=", ".ToLower() !=");
|
||||
|
||||
// Ensure values are also transformed to lowercase
|
||||
adjustedFilters = Regex.Replace(adjustedFilters, "\"([^\"]+)\"", m => $"\"{m.Groups[1].Value.ToLower()}\"");
|
||||
|
||||
// Parse the adjusted filter string into a dynamic lambda expression
|
||||
var predicate = DynamicExpressionParser.ParseLambda<T, bool>(
|
||||
new ParsingConfig(), false, Filters);
|
||||
new ParsingConfig(), false, adjustedFilters);
|
||||
|
||||
return predicate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Func<IQueryable<T>, IOrderedQueryable<T>> BuildSortExpression<T>() {
|
||||
if (string.IsNullOrWhiteSpace(SortBy))
|
||||
return q => (IOrderedQueryable<T>)q; // Cast to IOrderedQueryable
|
||||
|
||||
Loading…
Reference in New Issue
Block a user