Add standard pattern for pagination to the helper function.
This commit is contained in:
parent
04bd6aa69f
commit
daa78f974a
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
author = "Jonathan Bernard"
|
||||
description = "JDB Software's opinionated extensions and auth layer for Jester."
|
||||
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 ./apierror
|
||||
@ -59,7 +59,20 @@ template sendJsonResp*(
|
||||
$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}
|
||||
|
||||
template sendErrorResp*(err: ref ApiError, knownOrigins: seq[string]): void =
|
||||
|
Loading…
x
Reference in New Issue
Block a user