diff options
author | Joris | 2015-09-11 10:36:27 +0200 |
---|---|---|
committer | Joris | 2015-09-11 10:36:27 +0200 |
commit | d87dbd1360c14df83552fd757438c23e5d7b9f9c (patch) | |
tree | 8b28def0414205608bd964c9b38a98b9d6828655 /src/server/Controller | |
parent | 73fa92aeffb27a98d8f316be157883ecefb1aed5 (diff) |
Using jsonObject to create on the fly json object responses
Diffstat (limited to 'src/server/Controller')
-rw-r--r-- | src/server/Controller/Payment.hs | 9 | ||||
-rw-r--r-- | src/server/Controller/SignIn.hs | 6 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs index 7cbfb37..85e2a87 100644 --- a/src/server/Controller/Payment.hs +++ b/src/server/Controller/Payment.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE OverloadedStrings #-} + module Controller.Payment ( getPaymentsAction , getMonthlyPaymentsAction @@ -16,18 +18,21 @@ import Database.Persist import Control.Monad.IO.Class (liftIO) import Data.Text (Text) +import qualified Data.Aeson.Types as Json import qualified Secure import Model.Database import Model.Payment import Model.Frequency -import Model.Json.Message import Model.Json.Number import qualified Model.Json.PaymentId as JP import Model.Message import Model.Message.Key (Key(PaymentNotDeleted)) + +import Json (jsonObject) + getPaymentsAction :: Int -> Int -> ActionM () getPaymentsAction page perPage = Secure.loggedAction (\_ -> do @@ -56,7 +61,7 @@ deletePaymentAction paymentId = status ok200 else do status badRequest400 - json . Message . getMessage $ PaymentNotDeleted + jsonObject [("error", Json.String $ getMessage PaymentNotDeleted)] ) getTotalPaymentsAction :: ActionM () diff --git a/src/server/Controller/SignIn.hs b/src/server/Controller/SignIn.hs index 40cf474..4f41c6e 100644 --- a/src/server/Controller/SignIn.hs +++ b/src/server/Controller/SignIn.hs @@ -18,6 +18,7 @@ import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Encoding as TE import Data.Time.Clock (getCurrentTime, diffUTCTime) +import qualified Data.Aeson.Types as Json import qualified LoginSession @@ -30,10 +31,11 @@ import Text.Email.Validate (isValid) import Model.Database import Model.User import Model.SignIn -import Model.Json.Message import Model.Message.Key import Model.Message (getMessage) +import Json (jsonObject) + import qualified View.Mail.SignIn as SignIn signInAction :: Config -> Text -> ActionM () @@ -59,7 +61,7 @@ signInAction config login = errorResponse :: Text -> ActionM () errorResponse msg = do status badRequest400 - json (Message msg) + jsonObject [("error", Json.String msg)] validateSignInAction :: Config -> Text -> ActionM () validateSignInAction config token = do |