Add standard pattern for pagination to the helper function.

This commit is contained in:
Jonathan Bernard 2022-09-08 11:12:45 -05:00
parent 04bd6aa69f
commit daa78f974a
2 changed files with 16 additions and 3 deletions

View File

@ -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"

View File

@ -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 =