-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenericPaginate.pas
More file actions
48 lines (37 loc) · 875 Bytes
/
GenericPaginate.pas
File metadata and controls
48 lines (37 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
unit GenericPaginate;
interface
uses
Horse;
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)}TNextProc{$ELSE}TProc{$ENDIF});
function GenericPaginateMiddleware: THorseCallback;
var
LLimit : Integer;
LPage : Integer;
implementation
uses
System.SysUtils;
function GenericPaginateMiddleware: THorseCallback;
begin
Result := Middleware;
end;
procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
aLimit, aPage: string;
begin
if Req.Headers['X-Paginate'] = 'true' then
begin
if not Req.Query.TryGetValue('limit', aLimit) then
aLimit := '25';
if not Req.Query.TryGetValue('page', aPage) then
aPage := '1';
LLimit := aLimit.ToInteger;
LPage := aPage.ToInteger;
end
else
begin
LLimit := 0;
LPage := 0;
end;
Next;
end;
end.