Skip to content

Commit 60b0dff

Browse files
committed
removed base36 support
1 parent 2476b18 commit 60b0dff

File tree

5 files changed

+101
-152
lines changed

5 files changed

+101
-152
lines changed

src/GridifyExtensions/Extensions/QueryableExtensions.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using BaseConverter;
2-
using Gridify;
1+
using Gridify;
32
using GridifyExtensions.Enums;
43
using GridifyExtensions.Models;
54
using Microsoft.EntityFrameworkCore;
@@ -83,21 +82,6 @@ public static async Task<PagedResponse<object>> ColumnDistinctValuesAsync<TEntit
8382
.OrderBy(x => x)
8483
.GetPagedAsync(model, cancellationToken);
8584

86-
if (mapper.NeedBase36Conversion(model.PropertyName))
87-
{
88-
if (string.IsNullOrWhiteSpace(PandaBaseConverter.Base36Chars))
89-
{
90-
throw new Exception("Base36Chars should be set before using Base36 conversion.");
91-
}
92-
93-
return result with
94-
{
95-
Data = result.Data
96-
.Select(x => PandaBaseConverter.Base10ToBase36((long)x) as object)
97-
.ToList()
98-
};
99-
}
100-
10185
return result;
10286
}
10387

@@ -134,12 +118,6 @@ public static async Task<CursoredResponse<object>> ColumnDistinctValuesAsync<TEn
134118
.Take(model.PageSize)
135119
.ToListAsync(cancellationToken: cancellationToken);
136120

137-
if (mapper!.NeedBase36Conversion(model.PropertyName))
138-
{
139-
result = result.Select(x => PandaBaseConverter.Base10ToBase36((long)x) as object)
140-
.ToList();
141-
}
142-
143121
return new CursoredResponse<object>(result, model.PageSize);
144122
}
145123

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using BaseConverter;
2-
using Gridify;
1+
using Gridify;
32
using GridifyExtensions.Models;
43
using Microsoft.AspNetCore.Builder;
54
using System.Reflection;
@@ -8,48 +7,34 @@ namespace GridifyExtensions.Extensions;
87

98
public static class WebApplicationBuilderExtensions
109
{
11-
public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builder, string base36Chars,
12-
params Assembly[] assemblies)
13-
{
14-
PandaBaseConverter.Base36Chars = base36Chars;
15-
16-
if (assemblies.Length == 0)
17-
{
18-
assemblies = [Assembly.GetCallingAssembly()];
19-
}
20-
21-
AddGridify(assemblies);
22-
23-
return builder;
24-
}
25-
26-
public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builder, params Assembly[] assemblies)
27-
{
28-
if (assemblies.Length == 0)
29-
{
30-
assemblies = [Assembly.GetCallingAssembly()];
31-
}
32-
33-
AddGridify(assemblies);
34-
35-
return builder;
36-
}
37-
38-
private static void AddGridify(Assembly[] assemblies)
39-
{
40-
GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();
41-
42-
QueryableExtensions.EntityGridifyMapperByType =
43-
assemblies.SelectMany(assembly => assembly
44-
.GetTypes()
45-
.Where(t => t.IsClass
46-
&& !t.IsAbstract
47-
&& t.BaseType != null
48-
&& t.BaseType.IsGenericType
49-
&& t.BaseType.GetGenericTypeDefinition() == typeof(FilterMapper<>))
50-
.Select(x =>
51-
new KeyValuePair<Type, object>(x.BaseType!.GetGenericArguments()[0],
52-
Activator.CreateInstance(x)!)))
53-
.ToDictionary(x => x.Key, x => x.Value);
54-
}
10+
public static WebApplicationBuilder AddGridify(this WebApplicationBuilder builder, params Assembly[] assemblies)
11+
{
12+
if (assemblies.Length == 0)
13+
{
14+
assemblies = [Assembly.GetCallingAssembly()];
15+
}
16+
17+
AddGridify(assemblies);
18+
19+
return builder;
20+
}
21+
22+
private static void AddGridify(Assembly[] assemblies)
23+
{
24+
GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer();
25+
26+
QueryableExtensions.EntityGridifyMapperByType =
27+
assemblies.SelectMany(assembly => assembly
28+
.GetTypes()
29+
.Where(t => t.IsClass
30+
&& !t.IsAbstract
31+
&& t.BaseType != null
32+
&& t.BaseType.IsGenericType
33+
&& t.BaseType.GetGenericTypeDefinition() ==
34+
typeof(FilterMapper<>))
35+
.Select(x =>
36+
new KeyValuePair<Type, object>(x.BaseType!.GetGenericArguments()[0],
37+
Activator.CreateInstance(x)!)))
38+
.ToDictionary(x => x.Key, x => x.Value);
39+
}
5540
}

src/GridifyExtensions/GridifyExtensions.csproj

Lines changed: 2 additions & 3 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.4.2</Version>
11+
<Version>1.5.0</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>Bug fix related assemblies</PackageReleaseNotes>
17+
<PackageReleaseNotes>Removed base 36 support</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
@@ -25,7 +25,6 @@
2525
<ItemGroup>
2626
<PackageReference Include="Gridify.EntityFramework" Version="2.14.2" />
2727
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
28-
<PackageReference Include="PandaTech.BaseConverter" Version="4.0.3" />
2928
</ItemGroup>
3029

3130
</Project>

src/GridifyExtensions/Models/FilterMapper.cs

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,69 @@ namespace GridifyExtensions.Models;
66

77
public class FilterMapper<T> : GridifyMapper<T>, IOrderThenBy
88
{
9-
internal const string Desc = " desc";
10-
internal const string Separator = ", ";
11-
12-
private string _defaultOrderExpression = string.Empty;
13-
private readonly HashSet<string> _encryptedColumns = [];
14-
private readonly HashSet<string> _needBase36ConversionColumns = [];
15-
16-
internal bool NeedBase36Conversion(string column) => _needBase36ConversionColumns.Contains(column);
17-
internal bool IsEncrypted(string column) => _encryptedColumns.Contains(column);
18-
19-
internal string GetDefaultOrderExpression() => _defaultOrderExpression;
20-
21-
public IOrderThenBy AddDefaultOrderBy(string column)
22-
{
23-
_defaultOrderExpression = column;
24-
return this;
25-
}
26-
27-
public IOrderThenBy AddDefaultOrderByDescending(string column)
28-
{
29-
_defaultOrderExpression = column + Desc;
30-
return this;
31-
}
32-
33-
IOrderThenBy IOrderThenBy.ThenBy(string column)
34-
{
35-
_defaultOrderExpression += Separator + column;
36-
37-
return this;
38-
}
39-
40-
IOrderThenBy IOrderThenBy.ThenByDescending(string column)
41-
{
42-
_defaultOrderExpression += Separator + column + Desc;
43-
44-
return this;
45-
}
46-
47-
public IGridifyMapper<T> AddMap(string from,
48-
Expression<Func<T, object?>> to,
49-
Func<string, object>? convertor = null,
50-
bool overrideIfExists = true,
51-
bool isEncrypted = false,
52-
bool needBase36Conversion = false)
53-
{
54-
if (isEncrypted)
55-
{
56-
_encryptedColumns.Add(from);
57-
}
58-
59-
if (needBase36Conversion)
60-
{
61-
_needBase36ConversionColumns.Add(from);
62-
}
63-
64-
return base.AddMap(from, to, convertor, overrideIfExists);
65-
}
66-
67-
public IGridifyMapper<T> AddMap(string from,
68-
Expression<Func<T, int, object?>> to,
69-
Func<string, object>? convertor = null,
70-
bool overrideIfExists = true,
71-
bool isEncrypted = false,
72-
bool needBase36Conversion = false)
73-
{
74-
if (isEncrypted)
75-
{
76-
_encryptedColumns.Add(from);
77-
}
78-
79-
if (needBase36Conversion)
80-
{
81-
_needBase36ConversionColumns.Add(from);
82-
}
83-
84-
return base.AddMap(from, to, convertor, overrideIfExists);
85-
}
86-
}
9+
internal const string Desc = " desc";
10+
internal const string Separator = ", ";
11+
12+
private string _defaultOrderExpression = string.Empty;
13+
private readonly HashSet<string> _encryptedColumns = [];
14+
15+
internal bool IsEncrypted(string column) => _encryptedColumns.Contains(column);
16+
17+
internal string GetDefaultOrderExpression() => _defaultOrderExpression;
18+
19+
public IOrderThenBy AddDefaultOrderBy(string column)
20+
{
21+
_defaultOrderExpression = column;
22+
return this;
23+
}
24+
25+
public IOrderThenBy AddDefaultOrderByDescending(string column)
26+
{
27+
_defaultOrderExpression = column + Desc;
28+
return this;
29+
}
30+
31+
IOrderThenBy IOrderThenBy.ThenBy(string column)
32+
{
33+
_defaultOrderExpression += Separator + column;
34+
35+
return this;
36+
}
37+
38+
IOrderThenBy IOrderThenBy.ThenByDescending(string column)
39+
{
40+
_defaultOrderExpression += Separator + column + Desc;
41+
42+
return this;
43+
}
44+
45+
public IGridifyMapper<T> AddMap(string from,
46+
Expression<Func<T, object?>> to,
47+
Func<string, object>? convertor = null,
48+
bool overrideIfExists = true,
49+
bool isEncrypted = false)
50+
{
51+
if (isEncrypted)
52+
{
53+
_encryptedColumns.Add(from);
54+
}
55+
56+
57+
return base.AddMap(from, to, convertor, overrideIfExists);
58+
}
59+
60+
public IGridifyMapper<T> AddMap(string from,
61+
Expression<Func<T, int, object?>> to,
62+
Func<string, object>? convertor = null,
63+
bool overrideIfExists = true,
64+
bool isEncrypted = false)
65+
{
66+
if (isEncrypted)
67+
{
68+
_encryptedColumns.Add(from);
69+
}
70+
71+
72+
return base.AddMap(from, to, convertor, overrideIfExists);
73+
}
74+
}

test/GridifyExtensions.Demo/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Reflection;
33
using GridifyExtensions.Models;
44
using Microsoft.AspNetCore.Mvc;
5-
using BaseConverter;
65

76
var builder = WebApplication.CreateBuilder(args);
87

@@ -11,7 +10,7 @@
1110
builder.Services.AddSwaggerGen();
1211
builder.Services.AddControllers();
1312

14-
builder.AddGridify(PandaBaseConverter.Base36Chars, Assembly.GetExecutingAssembly());
13+
builder.AddGridify(Assembly.GetExecutingAssembly());
1514

1615
var app = builder.Build();
1716

0 commit comments

Comments
 (0)