mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-21 21:12:50 +01:00
Convert parsing from getters to methods
This commit is contained in:
parent
c816cf2f2a
commit
f9c7fb4cb0
@ -20,8 +20,8 @@ namespace Sieve.Models
|
||||
|
||||
int? PageSize { get; set; }
|
||||
|
||||
List<TFilterTerm> FiltersParsed { get; }
|
||||
List<TFilterTerm> GetFiltersParsed();
|
||||
|
||||
List<TSortTerm> SortsParsed { get; }
|
||||
List<TSortTerm> GetSortsParsed();
|
||||
}
|
||||
}
|
||||
|
@ -25,76 +25,70 @@ namespace Sieve.Models
|
||||
[DataMember, Range(1, int.MaxValue)]
|
||||
public int? PageSize { get; set; }
|
||||
|
||||
public List<TFilterTerm> FiltersParsed
|
||||
public List<TFilterTerm> GetFiltersParsed()
|
||||
{
|
||||
get
|
||||
if (Filters != null)
|
||||
{
|
||||
if (Filters != null)
|
||||
var value = new List<TFilterTerm>();
|
||||
foreach (var filter in Filters.Split(','))
|
||||
{
|
||||
var value = new List<TFilterTerm>();
|
||||
foreach (var filter in Filters.Split(','))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(filter)) continue;
|
||||
if (string.IsNullOrWhiteSpace(filter)) continue;
|
||||
|
||||
if (filter.StartsWith("("))
|
||||
if (filter.StartsWith("("))
|
||||
{
|
||||
var filterOpAndVal = filter.Substring(filter.LastIndexOf(")") + 1);
|
||||
var subfilters = filter.Replace(filterOpAndVal, "").Replace("(", "").Replace(")", "");
|
||||
var filterTerm = new TFilterTerm
|
||||
{
|
||||
var filterOpAndVal = filter.Substring(filter.LastIndexOf(")") + 1);
|
||||
var subfilters = filter.Replace(filterOpAndVal, "").Replace("(", "").Replace(")", "");
|
||||
var filterTerm = new TFilterTerm
|
||||
{
|
||||
Filter = subfilters + filterOpAndVal
|
||||
};
|
||||
if (!value.Any(f => f.Names.Any(n => filterTerm.Names.Any(n2 => n2 == n))))
|
||||
{
|
||||
value.Add(filterTerm);
|
||||
}
|
||||
}
|
||||
else
|
||||
Filter = subfilters + filterOpAndVal
|
||||
};
|
||||
if (!value.Any(f => f.Names.Any(n => filterTerm.Names.Any(n2 => n2 == n))))
|
||||
{
|
||||
var filterTerm = new TFilterTerm
|
||||
{
|
||||
Filter = filter
|
||||
};
|
||||
value.Add(filterTerm);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
else
|
||||
{
|
||||
var filterTerm = new TFilterTerm
|
||||
{
|
||||
Filter = filter
|
||||
};
|
||||
value.Add(filterTerm);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TSortTerm> SortsParsed
|
||||
public List<TSortTerm> GetSortsParsed()
|
||||
{
|
||||
get
|
||||
if (Sorts != null)
|
||||
{
|
||||
if (Sorts != null)
|
||||
var value = new List<TSortTerm>();
|
||||
foreach (var sort in Sorts.Split(','))
|
||||
{
|
||||
var value = new List<TSortTerm>();
|
||||
foreach (var sort in Sorts.Split(','))
|
||||
if (string.IsNullOrWhiteSpace(sort)) continue;
|
||||
|
||||
var sortTerm = new TSortTerm()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sort)) continue;
|
||||
|
||||
var sortTerm = new TSortTerm()
|
||||
{
|
||||
Sort = sort
|
||||
};
|
||||
if (!value.Any(s => s.Name == sortTerm.Name))
|
||||
{
|
||||
value.Add(sortTerm);
|
||||
}
|
||||
Sort = sort
|
||||
};
|
||||
if (!value.Any(s => s.Name == sortTerm.Name))
|
||||
{
|
||||
value.Add(sortTerm);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,14 +164,14 @@ namespace Sieve.Services
|
||||
IQueryable<TEntity> result,
|
||||
object[] dataForCustomMethods = null)
|
||||
{
|
||||
if (model?.FiltersParsed == null)
|
||||
if (model?.GetFiltersParsed() == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression outerExpression = null;
|
||||
var parameterExpression = Expression.Parameter(typeof(TEntity), "e");
|
||||
foreach (var filterTerm in model.FiltersParsed)
|
||||
foreach (var filterTerm in model.GetFiltersParsed())
|
||||
{
|
||||
Expression innerExpression = null;
|
||||
foreach (var filterTermName in filterTerm.Names)
|
||||
@ -281,13 +281,13 @@ namespace Sieve.Services
|
||||
IQueryable<TEntity> result,
|
||||
object[] dataForCustomMethods = null)
|
||||
{
|
||||
if (model?.SortsParsed == null)
|
||||
if (model?.GetSortsParsed() == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var useThenBy = false;
|
||||
foreach (var sortTerm in model.SortsParsed)
|
||||
foreach (var sortTerm in model.GetSortsParsed())
|
||||
{
|
||||
var property = GetSieveProperty<TEntity>(true, false, sortTerm.Name);
|
||||
|
||||
|
@ -148,9 +148,9 @@ namespace SieveUnitTests
|
||||
Filters = "LikeCount==50",
|
||||
};
|
||||
|
||||
Console.WriteLine(model.FiltersParsed[0].Value);
|
||||
Console.WriteLine(model.FiltersParsed[0].Operator);
|
||||
Console.WriteLine(model.FiltersParsed[0].OperatorParsed);
|
||||
Console.WriteLine(model.GetFiltersParsed()[0].Value);
|
||||
Console.WriteLine(model.GetFiltersParsed()[0].Operator);
|
||||
Console.WriteLine(model.GetFiltersParsed()[0].OperatorParsed);
|
||||
|
||||
var result = _processor.Apply(model, _posts);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user