@@ -13,11 +13,10 @@ namespace JsonApiDotNetCore.Query
13
13
public class PageService : QueryParameterService , IPageService
14
14
{
15
15
private readonly IJsonApiOptions _options ;
16
-
17
16
public PageService ( IJsonApiOptions options , IResourceGraph resourceGraph , ICurrentRequest currentRequest ) : base ( resourceGraph , currentRequest )
18
17
{
19
18
_options = options ;
20
- PageSize = _options . DefaultPageSize ;
19
+ DefaultPageSize = _options . DefaultPageSize ;
21
20
}
22
21
23
22
/// <summary>
@@ -26,14 +25,27 @@ public PageService(IJsonApiOptions options, IResourceGraph resourceGraph, ICurre
26
25
internal PageService ( IJsonApiOptions options )
27
26
{
28
27
_options = options ;
29
- PageSize = _options . DefaultPageSize ;
28
+ DefaultPageSize = _options . DefaultPageSize ;
30
29
}
31
30
32
31
/// <inheritdoc/>
33
- public int ? TotalRecords { get ; set ; }
32
+ public int CurrentPageSize
33
+ {
34
+ get
35
+ {
36
+ if ( RequestedPageSize . HasValue )
37
+ {
38
+ return RequestedPageSize . Value ;
39
+ }
40
+ return DefaultPageSize ;
41
+ }
42
+ }
43
+
44
+ /// <inheritdoc/>
45
+ public int DefaultPageSize { get ; set ; }
34
46
35
47
/// <inheritdoc/>
36
- public int PageSize { get ; set ; }
48
+ public int ? RequestedPageSize { get ; set ; }
37
49
38
50
/// <inheritdoc/>
39
51
public int CurrentPage { get ; set ; } = 1 ;
@@ -42,17 +54,20 @@ internal PageService(IJsonApiOptions options)
42
54
public bool Backwards { get ; set ; }
43
55
44
56
/// <inheritdoc/>
45
- public int TotalPages => ( TotalRecords == null || PageSize == 0 ) ? - 1 : ( int ) Math . Ceiling ( decimal . Divide ( TotalRecords . Value , PageSize ) ) ;
57
+ public int TotalPages => ( TotalRecords == null || CurrentPageSize == 0 ) ? - 1 : ( int ) Math . Ceiling ( decimal . Divide ( TotalRecords . Value , CurrentPageSize ) ) ;
46
58
47
59
/// <inheritdoc/>
48
60
public bool CanPaginate { get { return TotalPages > 1 ; } }
49
61
62
+ /// <inheritdoc/>
63
+ public int ? TotalRecords { get ; set ; }
64
+
50
65
/// <inheritdoc/>
51
66
public virtual void Parse ( KeyValuePair < string , StringValues > queryParameter )
52
67
{
53
68
EnsureNoNestedResourceRoute ( ) ;
54
69
// expected input = page[size]=<integer>
55
- // page[number]=<integer > 0>
70
+ // page[number]=<integer greater than zero>
56
71
var propertyName = queryParameter . Key . Split ( QueryConstants . OPEN_BRACKET , QueryConstants . CLOSE_BRACKET ) [ 1 ] ;
57
72
58
73
const string SIZE = "size" ;
@@ -70,7 +85,7 @@ public virtual void Parse(KeyValuePair<string, StringValues> queryParameter)
70
85
}
71
86
else
72
87
{
73
- PageSize = size ;
88
+ RequestedPageSize = size ;
74
89
}
75
90
}
76
91
else if ( propertyName == NUMBER )
0 commit comments