aboutsummaryrefslogtreecommitdiff
path: root/src/server/Json.hs
blob: 408742aa7c70bc699d43068541f93f42eec33408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts           #-}

module Json
  ( jsonObject
  , jsonId
  ) where

import Web.Scotty

import qualified Data.Aeson.Types as Json
import qualified Data.HashMap.Strict as M
import Data.Text (Text)

import Database.Persist
import Database.Persist.Sqlite

import Model.Database

jsonObject :: [(Text, Json.Value)] -> ActionM ()
jsonObject = json . Json.Object . M.fromList

jsonId :: (ToBackendKey SqlBackend a) => Key a -> ActionM ()
jsonId key = json . Json.Object . M.fromList $ [("id", Json.Number . fromIntegral . keyToInt64 $ key)]