module Network.JSONApi.Pagination (
Pagination (..)
, PageNum (..)
, PageSize (..)
, ResourceCount (..)
) where
import Control.DeepSeq (NFData)
import Data.Aeson ((.=), ToJSON, object, toJSON)
import qualified GHC.Generics as G
import Network.JSONApi.Meta (MetaObject (..))
data Pagination = Pagination {
getPaginationPageSize :: PageSize
, getPaginationPageNum :: PageNum
, getPaginationResourceCount :: ResourceCount
} deriving (G.Generic)
instance ToJSON Pagination where
toJSON (Pagination (PageSize size) (PageNum num) (ResourceCount count)) =
object [
"pageSize" .= size
, "currentPage" .= num
, "totalDocuments" .= count
]
instance NFData Pagination
instance MetaObject Pagination where
typeName _ = "pagination"
newtype PageSize = PageSize {
getPageSize :: Int
} deriving (G.Generic, Show)
instance NFData PageSize
newtype PageNum = PageNum {
getPageNum :: Int
} deriving (G.Generic, Show)
instance NFData PageNum
newtype ResourceCount = ResourceCount {
getResourceCount :: Int
} deriving (G.Generic, Show)
instance NFData ResourceCount