Skip to content

Commit 16dc9af

Browse files
committed
Base 36 not required
1 parent b7df27a commit 16dc9af

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
namespace GridifyExtensions.Exceptions;
22

3-
public class GridifyException : Exception
4-
{
5-
public GridifyException(string message)
6-
: base(message)
7-
{
8-
9-
}
10-
}
3+
public class GridifyException(string message) : Exception(message);

src/GridifyExtensions/Extensions/QueryableExtensions.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public static async Task<PagedResponse<TEntity>> GetPagedAsync<TEntity>(this IQu
6767
totalCount);
6868
}
6969

70+
[Obsolete("Use ColumnDistinctValueCursoredQueryModel instead.")]
7071
public static async Task<PagedResponse<object>> ColumnDistinctValuesAsync<TEntity>(this IQueryable<TEntity> query,
7172
ColumnDistinctValueQueryModel model, Func<byte[], string>? decryptor = default,
7273
CancellationToken cancellationToken = default)
@@ -82,13 +83,18 @@ public static async Task<PagedResponse<object>> ColumnDistinctValuesAsync<TEntit
8283
.OrderBy(x => x)
8384
.GetPagedAsync(model, cancellationToken);
8485

85-
if (mapper!.NeedBase36Conversion(model.PropertyName))
86+
if (mapper.NeedBase36Conversion(model.PropertyName))
8687
{
88+
if (string.IsNullOrWhiteSpace(PandaBaseConverter.Base36Chars))
89+
{
90+
throw new Exception("Base36Chars should be set before using Base36 conversion.");
91+
}
92+
8793
return result with
8894
{
8995
Data = result.Data
90-
.Select(x => PandaBaseConverter.Base10ToBase36((long)x) as object)
91-
.ToList()
96+
.Select(x => PandaBaseConverter.Base10ToBase36((long)x) as object)
97+
.ToList()
9298
};
9399
}
94100

@@ -109,7 +115,8 @@ public static async Task<PagedResponse<object>> ColumnDistinctValuesAsync<TEntit
109115
return new PagedResponse<object>([decryptedItem], 1, 1, 1);
110116
}
111117

112-
public static async Task<CursoredResponse<object>> ColumnDistinctValuesAsync<TEntity>(this IQueryable<TEntity> query,
118+
public static async Task<CursoredResponse<object>> ColumnDistinctValuesAsync<TEntity>(
119+
this IQueryable<TEntity> query,
113120
ColumnDistinctValueCursoredQueryModel model, Func<byte[], string>? decryptor = default,
114121
CancellationToken cancellationToken = default)
115122
{
@@ -130,7 +137,7 @@ public static async Task<CursoredResponse<object>> ColumnDistinctValuesAsync<TEn
130137
if (mapper!.NeedBase36Conversion(model.PropertyName))
131138
{
132139
result = result.Select(x => PandaBaseConverter.Base10ToBase36((long)x) as object)
133-
.ToList();
140+
.ToList();
134141
}
135142

136143
return new CursoredResponse<object>(result, model.PageSize);
@@ -151,9 +158,9 @@ public static async Task<CursoredResponse<object>> ColumnDistinctValuesAsync<TEn
151158
}
152159

153160
public static async Task<object> AggregateAsync<TEntity>(this IQueryable<TEntity> query,
154-
AggregateQueryModel model,
155-
CancellationToken cancellationToken = default)
156-
where TEntity : class
161+
AggregateQueryModel model,
162+
CancellationToken cancellationToken = default)
163+
where TEntity : class
157164
{
158165
var aggregateProperty = model.PropertyName;
159166

src/GridifyExtensions/Extensions/WebApplicationBuilderExtensions.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ namespace GridifyExtensions.Extensions;
88

99
public static class WebApplicationBuilderExtensions
1010
{
11-
public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builder, string base36Chars, params Assembly[] assemblies)
11+
public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builder, string base36Chars,
12+
params Assembly[] assemblies)
1213
{
1314
PandaBaseConverter.Base36Chars = base36Chars;
1415

16+
AddGridify(assemblies);
17+
18+
return builder;
19+
}
20+
21+
public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builder, params Assembly[] assemblies)
22+
{
23+
AddGridify(assemblies);
24+
25+
return builder;
26+
}
27+
28+
private static void AddGridify(Assembly[] assemblies)
29+
{
1530
if (assemblies.Length == 0)
1631
{
1732
assemblies = [Assembly.GetCallingAssembly()];
@@ -20,16 +35,16 @@ public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builde
2035
GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();
2136

2237
QueryableExtensions.EntityGridifyMapperByType =
23-
assemblies.SelectMany(assembly => assembly
24-
.GetTypes()
25-
.Where(t => t.IsClass
26-
&& !t.IsAbstract
27-
&& t.BaseType != null
28-
&& t.BaseType.IsGenericType
29-
&& t.BaseType.GetGenericTypeDefinition() == typeof(FilterMapper<>))
30-
.Select(x => new KeyValuePair<Type, object>(x.BaseType!.GetGenericArguments()[0], Activator.CreateInstance(x)!)))
31-
.ToDictionary(x => x.Key, x => x.Value);
32-
33-
return builder;
38+
assemblies.SelectMany(assembly => assembly
39+
.GetTypes()
40+
.Where(t => t.IsClass
41+
&& !t.IsAbstract
42+
&& t.BaseType != null
43+
&& t.BaseType.IsGenericType
44+
&& t.BaseType.GetGenericTypeDefinition() == typeof(FilterMapper<>))
45+
.Select(x =>
46+
new KeyValuePair<Type, object>(x.BaseType!.GetGenericArguments()[0],
47+
Activator.CreateInstance(x)!)))
48+
.ToDictionary(x => x.Key, x => x.Value);
3449
}
35-
}
50+
}

src/GridifyExtensions/GridifyExtensions.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.3.7</Version>
11+
<Version>1.3.8</Version>
1212
<PackageId>Pandatech.GridifyExtensions</PackageId>
1313
<Title>Pandatech.Gridify.Extensions</Title>
1414
<PackageTags>Pandatech, library, Gridify, Pagination, Filters</PackageTags>
1515
<Description>Pandatech.Gridify.Extensions simplifies and extends the functionality of the Gridify NuGet package. It provides additional extension methods and functionality to streamline data filtering and pagination, making it more intuitive and powerful to use in .NET applications. Our enhancements ensure more flexibility, reduce boilerplate code, and improve overall developer productivity when working with Gridify.</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-gridify-extensions</RepositoryUrl>
17-
<PackageReleaseNotes>Readme updated</PackageReleaseNotes>
17+
<PackageReleaseNotes>Base 36 not required</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)