diff options
author | Joris | 2017-06-05 18:02:13 +0200 |
---|---|---|
committer | Joris | 2017-06-05 18:02:13 +0200 |
commit | 0b191f5c48edffc9da3e38c284e9640fd82e7cb1 (patch) | |
tree | c729e53822e7c41c1a854d82d25636e58ee65c9f /src/server/Controller/Income.hs | |
parent | 5c110716cfda6e616a795edd12f2012b132dca9f (diff) |
Replace persistent by sqlite-simple
Diffstat (limited to 'src/server/Controller/Income.hs')
-rw-r--r-- | src/server/Controller/Income.hs | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/server/Controller/Income.hs b/src/server/Controller/Income.hs index ff3e75d..18394d0 100644 --- a/src/server/Controller/Income.hs +++ b/src/server/Controller/Income.hs @@ -6,46 +6,40 @@ module Controller.Income , deleteOwn ) where -import Web.Scotty - -import Network.HTTP.Types.Status (ok200, badRequest400) - import Control.Monad.IO.Class (liftIO) - -import Database.Persist - -import Data.Text (Text) +import Network.HTTP.Types.Status (ok200, badRequest400) import qualified Data.Text.Lazy as TL - -import qualified Secure +import Web.Scotty import Json (jsonId) - -import Model.Database +import Model.Income (IncomeId) import qualified Model.Income as Income -import qualified Model.Message.Key as Key import qualified Model.Json.CreateIncome as Json import qualified Model.Json.EditIncome as Json +import qualified Model.Message.Key as Key +import qualified Model.Query as Query +import qualified Model.User as User +import qualified Secure create :: Json.CreateIncome -> ActionM () create (Json.CreateIncome date amount) = Secure.loggedAction (\user -> - (liftIO . runDb $ Income.create (entityKey user) date amount) >>= jsonId + (liftIO . Query.run $ Income.create (User.id user) date amount) >>= jsonId ) editOwn :: Json.EditIncome -> ActionM () editOwn (Json.EditIncome incomeId date amount) = Secure.loggedAction (\user -> do - updated <- liftIO . runDb $ Income.editOwn (entityKey user) incomeId date amount + updated <- liftIO . Query.run $ Income.editOwn (User.id user) incomeId date amount if updated then status ok200 else status badRequest400 ) -deleteOwn :: Text -> ActionM () +deleteOwn :: IncomeId -> ActionM () deleteOwn incomeId = Secure.loggedAction (\user -> do - deleted <- liftIO . runDb $ Income.deleteOwn user (textToKey incomeId) + deleted <- liftIO . Query.run $ Income.deleteOwn user incomeId if deleted then status ok200 |