aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Controller/Payment.hs9
-rw-r--r--src/server/Controller/SignIn.hs6
-rw-r--r--src/server/Json.hs12
-rw-r--r--src/server/Model/Json/Message.hs16
4 files changed, 23 insertions, 20 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
diff --git a/src/server/Json.hs b/src/server/Json.hs
new file mode 100644
index 0000000..51287ed
--- /dev/null
+++ b/src/server/Json.hs
@@ -0,0 +1,12 @@
+module Json
+ ( jsonObject
+ ) where
+
+import Web.Scotty (json, ActionM)
+
+import qualified Data.Aeson.Types as Json
+import qualified Data.HashMap.Strict as M
+import Data.Text (Text)
+
+jsonObject :: [(Text, Json.Value)] -> ActionM ()
+jsonObject = json . Json.Object . M.fromList
diff --git a/src/server/Model/Json/Message.hs b/src/server/Model/Json/Message.hs
deleted file mode 100644
index 354dd8f..0000000
--- a/src/server/Model/Json/Message.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-{-# LANGUAGE DeriveGeneric #-}
-
-module Model.Json.Message
- ( Message(..)
- ) where
-
-import Data.Aeson
-import Data.Text (Text)
-import GHC.Generics
-
-data Message = Message
- { message :: Text
- } deriving (Show, Generic)
-
-instance FromJSON Message
-instance ToJSON Message