Skip to content

Commit 4a70ab0

Browse files
authored
Merge pull request #66 from marcominerva/develop
New overload for PaginatedList management
2 parents fb6152c + fb60bdf commit 4a70ab0

File tree

7 files changed

+591
-16
lines changed

7 files changed

+591
-16
lines changed

OperationResults.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
3+
# 17
44
VisualStudioVersion = 17.3.32825.248
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OperationResults", "src\OperationResults\OperationResults.csproj", "{A7A08C14-9A87-43CD-9D9F-4313C63E75DB}"
@@ -31,6 +31,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Minimal APIs", "Minimal API
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OperationResults.Sample", "samples\MinimalApis\OperationResults.Sample\OperationResults.Sample.csproj", "{15965E02-9802-42B1-9CA5-7E5A84395477}"
3333
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OperationResultsTests", "tests\OperationResultsTests\OperationResultsTests.csproj", "{6DE9AD05-7F2A-415D-A622-B643DC1CE8BC}"
35+
EndProject
36+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E6331B55-69A2-4A27-B38C-422728D2EF13}"
37+
EndProject
3438
Global
3539
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3640
Debug|Any CPU = Debug|Any CPU
@@ -69,6 +73,10 @@ Global
6973
{15965E02-9802-42B1-9CA5-7E5A84395477}.Debug|Any CPU.Build.0 = Debug|Any CPU
7074
{15965E02-9802-42B1-9CA5-7E5A84395477}.Release|Any CPU.ActiveCfg = Release|Any CPU
7175
{15965E02-9802-42B1-9CA5-7E5A84395477}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{6DE9AD05-7F2A-415D-A622-B643DC1CE8BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{6DE9AD05-7F2A-415D-A622-B643DC1CE8BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{6DE9AD05-7F2A-415D-A622-B643DC1CE8BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{6DE9AD05-7F2A-415D-A622-B643DC1CE8BC}.Release|Any CPU.Build.0 = Release|Any CPU
7280
EndGlobalSection
7381
GlobalSection(SolutionProperties) = preSolution
7482
HideSolutionNode = FALSE
@@ -81,6 +89,7 @@ Global
8189
{6A120E62-C0F2-487F-BC61-D29FCD42F8ED} = {40EA0531-BCD9-4D33-9114-D1BB9EA7DDBA}
8290
{085A97A4-3BFB-458C-868F-8B9437260664} = {40EA0531-BCD9-4D33-9114-D1BB9EA7DDBA}
8391
{15965E02-9802-42B1-9CA5-7E5A84395477} = {085A97A4-3BFB-458C-868F-8B9437260664}
92+
{6DE9AD05-7F2A-415D-A622-B643DC1CE8BC} = {E6331B55-69A2-4A27-B38C-422728D2EF13}
8493
EndGlobalSection
8594
GlobalSection(ExtensibilityGlobals) = postSolution
8695
SolutionGuid = {50A270E1-9794-4558-BAE7-8E7BFDF45AD1}

samples/Controllers/OperationResults.Sample/OperationResults.Sample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
10-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
11-
<PackageReference Include="TinyHelpers.AspNetCore" Version="3.1.17" />
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
11+
<PackageReference Include="TinyHelpers.AspNetCore" Version="3.1.19" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/MinimalApis/OperationResults.Sample/OperationResults.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ItemGroup>
99
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
1010
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
11-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.143" PrivateAssets="All" />
12+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.146" PrivateAssets="All" />
1313
</ItemGroup>
1414

1515
</Project>

src/OperationResults/PaginatedList{ofT}.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,37 @@ public PaginatedList()
1616
{
1717
}
1818

19-
public PaginatedList(IEnumerable<T>? items, int totalCount, int pageIndex, int pageSize)
19+
public PaginatedList(IEnumerable<T>? items, bool hasNextPage = false)
20+
: this(items, items?.Count() ?? 0, hasNextPage)
2021
{
21-
Items = items;
22-
TotalCount = totalCount;
23-
PageIndex = pageIndex;
24-
PageSize = pageSize;
25-
HasNextPage = totalCount > (pageIndex * pageSize) + (items?.Count() ?? 0);
2622
}
2723

28-
public PaginatedList(IEnumerable<T>? items, bool hasNextPage = false) : this(items, items?.Count() ?? 0, hasNextPage)
24+
public PaginatedList(IEnumerable<T>? items, int totalCount)
25+
: this(items, totalCount, totalCount > items?.Count())
2926
{
3027
}
3128

32-
public PaginatedList(IEnumerable<T>? items, int totalCount, bool hasNextPage = false)
29+
public PaginatedList(IEnumerable<T>? items, int totalCount, bool hasNextPage)
30+
: this(items, totalCount, 0, items?.Count() ?? 0, hasNextPage)
31+
{
32+
}
33+
34+
public PaginatedList(IEnumerable<T>? items, int totalCount, int pageIndex)
35+
: this(items, totalCount, pageIndex, items?.Count() ?? 0)
36+
{
37+
}
38+
39+
public PaginatedList(IEnumerable<T>? items, int totalCount, int pageIndex, int pageSize)
40+
: this(items, totalCount, pageIndex, pageSize, totalCount > (pageIndex * pageSize) + (items?.Count() ?? 0))
41+
{
42+
}
43+
44+
public PaginatedList(IEnumerable<T>? items, int totalCount, int pageIndex, int pageSize, bool hasNextPage)
3345
{
3446
Items = items;
3547
TotalCount = totalCount;
36-
PageIndex = 0;
37-
PageSize = items?.Count() ?? 0;
38-
HasNextPage = items?.Count() != totalCount && hasNextPage;
48+
PageIndex = pageIndex;
49+
PageSize = pageSize;
50+
HasNextPage = hasNextPage;
3951
}
4052
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15+
<PackageReference Include="xunit" Version="2.5.3" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\src\OperationResults\OperationResults.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Using Include="Xunit" />
25+
</ItemGroup>
26+
27+
</Project>

0 commit comments

Comments
 (0)