Skip to content

Commit a6277f5

Browse files
authored
Merge pull request #39 from PandaTechAM/development
GridifyCursoredQueryModel SetMaxPageSize() & refactoring
2 parents 1de9cf8 + 40cc1c2 commit a6277f5

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

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>2.0.0</Version>
11+
<Version>2.0.1</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>Upgraded to .net 9</PackageReleaseNotes>
17+
<PackageReleaseNotes>Add SetMaxPageSize() method into GridifyCursoredQueryModel</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

src/GridifyExtensions/Models/GridifyCursoredQueryModel.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
namespace GridifyExtensions.Models;
44

5-
public class GridifyCursoredQueryModel
5+
public class GridifyCursoredQueryModel(bool validatePageSize)
66
{
77
private int _pageSize = 20;
8+
9+
private bool _validatePageSize = validatePageSize;
10+
11+
public GridifyCursoredQueryModel() : this(true)
12+
{
13+
}
814

915
public required int PageSize
1016
{
@@ -14,7 +20,7 @@ public required int PageSize
1420
value = value switch
1521
{
1622
<= 0 => throw new GridifyException($"{nameof(PageSize)} should be positive number."),
17-
> 500 => 500,
23+
> 500 when _validatePageSize => 500,
1824
_ => value
1925
};
2026

@@ -34,4 +40,10 @@ internal GridifyQueryModel ToGridifyQueryModel()
3440
Filter = Filter
3541
};
3642
}
43+
44+
public void SetMaxPageSize()
45+
{
46+
_validatePageSize = false;
47+
PageSize = int.MaxValue;
48+
}
3749
}

src/GridifyExtensions/Models/GridifyQueryModel.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33

44
namespace GridifyExtensions.Models;
55

6-
public class GridifyQueryModel : GridifyQuery
6+
public class GridifyQueryModel(bool validatePageSize) : GridifyQuery
77
{
8-
private bool _validatePageSize;
8+
private bool _validatePageSize = validatePageSize;
99

10-
public GridifyQueryModel()
10+
public GridifyQueryModel() : this(true)
1111
{
12-
_validatePageSize = true;
13-
}
14-
15-
public GridifyQueryModel(bool validatePageSize)
16-
{
17-
_validatePageSize = validatePageSize;
1812
}
1913

2014
public new required int Page
@@ -36,15 +30,12 @@ public GridifyQueryModel(bool validatePageSize)
3630
get => base.PageSize;
3731
set
3832
{
39-
if (value <= 0)
33+
value = value switch
4034
{
41-
throw new GridifyException($"{nameof(PageSize)} should be positive number.");
42-
}
43-
44-
if (value > 500 && _validatePageSize)
45-
{
46-
value = 500;
47-
}
35+
<= 0 => throw new GridifyException($"{nameof(PageSize)} should be positive number."),
36+
> 500 when _validatePageSize => 500,
37+
_ => value
38+
};
4839

4940
base.PageSize = value;
5041
}

0 commit comments

Comments
 (0)