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/Category.hs | |
parent | 5c110716cfda6e616a795edd12f2012b132dca9f (diff) |
Replace persistent by sqlite-simple
Diffstat (limited to 'src/server/Controller/Category.hs')
-rw-r--r-- | src/server/Controller/Category.hs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/server/Controller/Category.hs b/src/server/Controller/Category.hs index 19109a3..3f800da 100644 --- a/src/server/Controller/Category.hs +++ b/src/server/Controller/Category.hs @@ -7,43 +7,42 @@ module Controller.Category ) where import Control.Monad.IO.Class (liftIO) - -import Data.Text (Text) import Network.HTTP.Types.Status (ok200, badRequest400) import qualified Data.Text.Lazy as TL import Web.Scotty hiding (delete) import Json (jsonId) -import Model.Database +import Model.Category (CategoryId) import qualified Model.Category as Category import qualified Model.Json.CreateCategory as Json import qualified Model.Json.EditCategory as Json import qualified Model.Message.Key as Key import qualified Model.PaymentCategory as PaymentCategory +import qualified Model.Query as Query import qualified Secure create :: Json.CreateCategory -> ActionM () create (Json.CreateCategory name color) = Secure.loggedAction (\_ -> - (liftIO . runDb $ Category.create name color) >>= jsonId + (liftIO . Query.run $ Category.create name color) >>= jsonId ) edit :: Json.EditCategory -> ActionM () edit (Json.EditCategory categoryId name color) = Secure.loggedAction (\_ -> do - updated <- liftIO . runDb $ Category.edit categoryId name color + updated <- liftIO . Query.run $ Category.edit categoryId name color if updated then status ok200 else status badRequest400 ) -delete :: Text -> ActionM () +delete :: CategoryId -> ActionM () delete categoryId = Secure.loggedAction (\_ -> do - deleted <- liftIO . runDb $ do - paymentCategories <- PaymentCategory.listByCategory (textToKey categoryId) + deleted <- liftIO . Query.run $ do + paymentCategories <- PaymentCategory.listByCategory categoryId if null paymentCategories - then Category.delete (textToKey categoryId) + then Category.delete categoryId else return False if deleted then |