adding
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using MongoDB.Driver;
|
||||
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
|
||||
|
||||
namespace LCU.Library.Internal.DocumentModels.Requests.Search;
|
||||
|
||||
public class Sorter<T>
|
||||
{
|
||||
public static SortDefinition<T> GetSorter(List<SortableField> fields)
|
||||
{
|
||||
SortDefinition<T>? sortDefinition = null;
|
||||
|
||||
if(fields == null)
|
||||
{
|
||||
return sortDefinition;
|
||||
}
|
||||
|
||||
fields.Sort((a, b) => a.Position.CompareTo(b.Position));
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (sortDefinition == null)
|
||||
{
|
||||
sortDefinition = field.IsDescending ? Builders<T>.Sort.Descending(field.Field) : Builders<T>.Sort.Ascending(field.Field);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortDefinition = field.IsDescending ? sortDefinition.Descending(field.Field) : sortDefinition.Ascending(field.Field);
|
||||
}
|
||||
}
|
||||
|
||||
return sortDefinition;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user