Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
3.2.5
Browse files Browse the repository at this point in the history
Added Comparator
  • Loading branch information
DefGh committed Nov 2, 2023
1 parent cf825e3 commit 91d4eb0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
16 changes: 16 additions & 0 deletions IEnumerableExtenders/Converters/FilterPandaBaseConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using BaseConverter;

namespace PandaTech.IEnumerableFilters.Converters;

public class FilterPandaBaseConverter: IConverter<string, long>
{
public long ConvertTo(string from)
{
return PandaBaseConverter.Base36ToBase10(from)!.Value;
}

public string ConvertFrom(long from)
{
return PandaBaseConverter.Base10ToBase36(from)!;
}
}
2 changes: 1 addition & 1 deletion IEnumerableExtenders/Dto/DistinctColumnValuesResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace PandaTech.IEnumerableFilters;
namespace PandaTech.IEnumerableFilters.Dto;

public class DistinctColumnValuesResult
{
Expand Down
45 changes: 39 additions & 6 deletions IEnumerableExtenders/EnumerableExtendersV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static ComparisonTypesDefault GetComparisonTypesDefault(Type type)
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
type = type.GetGenericArguments()[0];

if (type == typeof(int) || type == typeof(long) || type == typeof(decimal) || type == typeof(double) ||
type == typeof(float))
return ComparisonTypesDefault.Numeric;
Expand Down Expand Up @@ -252,7 +252,7 @@ public static List<object> DistinctColumnValues<TModel, TDto>(this IQueryable<TM
totalCount = result.TotalCount;
return result.Values;
}

public static DistinctColumnValuesResult DistinctColumnValues<T, TDto>(this IQueryable<T> dbSet,
List<FilterDto> filters,
string columnName, int pageSize, int page) where T : class
Expand Down Expand Up @@ -786,11 +786,42 @@ public static List<FilterInfo> GetFilters(Assembly assembly, string tableName)

if (targetProperty.PropertyType == typeof(Guid))
{
throw new NotImplementedException();
var lambda = Lambda<Func<TModel, Guid>>(propertyAccess, parameter);

if (aggregate.AggregateType == AggregateType.UniqueCount)
{
tasks.Add(
new KeyTask<long>()
{
Key = key,
Task = await dbSet.Select(lambda).Distinct()
.LongCountAsync(cancellationToken: cancellationToken)
}
);
}
else
{
tasks.Add(
new KeyTask<Guid?>()
{
Key = key,
Task = await Task.FromResult<Guid?>(null)
}
);
}
}

if (targetProperty.PropertyType.IsClass)
{
//TODO: Sub property

throw new NotImplementedException();
}

if (targetProperty.PropertyType == typeof(byte[]))
{
// TODO: check if is encrypted field.
// if so - build proper lamda
throw new NotImplementedException();
}

Expand All @@ -817,7 +848,9 @@ public static List<FilterInfo> GetFilters(Assembly assembly, string tableName)
});
}

public static async Task<object?> AggregateAsync<TModel, TDto>(this IQueryable<TModel> dbSet, AggregateType aggregateType, string columnName, CancellationToken cancellationToken = default) where TModel : class
public static async Task<object?> AggregateAsync<TModel, TDto>(this IQueryable<TModel> dbSet,
AggregateType aggregateType, string columnName, CancellationToken cancellationToken = default)
where TModel : class
{
var aggregates = new List<AggregateDto>
{
Expand All @@ -830,10 +863,10 @@ public static List<FilterInfo> GetFilters(Assembly assembly, string tableName)

var result = await dbSet.GetAggregatesAsync<TModel, TDto>(aggregates, cancellationToken);

return result.First().Value;
return result.First();
}


private abstract class ImTask
{
public string Key = null!;
Expand Down
2 changes: 1 addition & 1 deletion IEnumerableExtenders/IEnumerableExtenders.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>PandaTech.IEnumerableFilters</RootNamespace>
<Version>3.2.4</Version>
<Version>3.2.5</Version>
<Authors>PandaTech</Authors>
<Description>This NuGet helps with filtering tables.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-ienumerable-extenders-filters.git</RepositoryUrl>
Expand Down

0 comments on commit 91d4eb0

Please sign in to comment.