Add standard pattern for pagination to the helper function.
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
# Package
 | 
					# Package
 | 
				
			||||||
 | 
					
 | 
				
			||||||
version       = "0.2.0"
 | 
					version       = "0.2.1"
 | 
				
			||||||
author        = "Jonathan Bernard"
 | 
					author        = "Jonathan Bernard"
 | 
				
			||||||
description   = "JDB Software's opinionated extensions and auth layer for Jester."
 | 
					description   = "JDB Software's opinionated extensions and auth layer for Jester."
 | 
				
			||||||
license       = "MIT"
 | 
					license       = "MIT"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
import std/json, std/logging, std/strutils, std/sequtils
 | 
					import std/json, std/logging, std/options, std/strutils, std/sequtils
 | 
				
			||||||
import jester, namespaced_logging
 | 
					import jester, namespaced_logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ./apierror
 | 
					import ./apierror
 | 
				
			||||||
@@ -59,7 +59,20 @@ template sendJsonResp*(
 | 
				
			|||||||
    $body
 | 
					    $body
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
proc makeDataBody*(data: JsonNode): JsonNode = %*{"details":"","data":data}
 | 
					proc makeDataBody*(
 | 
				
			||||||
 | 
					    data: JsonNode,
 | 
				
			||||||
 | 
					    nextOffset = none[int](),
 | 
				
			||||||
 | 
					    totalItems = none[int](),
 | 
				
			||||||
 | 
					    nextLink = none[string](),
 | 
				
			||||||
 | 
					    prevLink = none[string]()): JsonNode =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  result = %*{"details":"","data":data}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if nextOffset.isSome: result["nextOffset"] = %nextOffset.get
 | 
				
			||||||
 | 
					  if totalItems.isSome: result["totalItems"] = %totalItems.get
 | 
				
			||||||
 | 
					  if nextLink.isSome: result["next"] = %nextLink.get
 | 
				
			||||||
 | 
					  if prevLink.isSome: result["prev"] = %prevLink.get
 | 
				
			||||||
 | 
					
 | 
				
			||||||
proc makeStatusBody*(details: string): JsonNode = %*{"details":details}
 | 
					proc makeStatusBody*(details: string): JsonNode = %*{"details":details}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template sendErrorResp*(err: ref ApiError, knownOrigins: seq[string]): void =
 | 
					template sendErrorResp*(err: ref ApiError, knownOrigins: seq[string]): void =
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user