diff options
Diffstat (limited to 'src/server/Controller/Income.hs')
-rw-r--r-- | src/server/Controller/Income.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/server/Controller/Income.hs b/src/server/Controller/Income.hs new file mode 100644 index 0000000..51861d3 --- /dev/null +++ b/src/server/Controller/Income.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Controller.Income + ( getIncomes + , setIncome + ) where + +import Web.Scotty + +import Control.Monad.IO.Class (liftIO) + +import Database.Persist + +import qualified Secure + +import Json (jsonId) + +import Model.Database +import qualified Model.Income as Income + +getIncomes :: ActionM () +getIncomes = + Secure.loggedAction (\_ -> + (liftIO $ map Income.getJsonIncome <$> runDb Income.getIncomes) >>= json + ) + +setIncome :: Int -> ActionM () +setIncome amount = + Secure.loggedAction (\user -> do + (liftIO . runDb $ Income.setIncome (entityKey user) amount) >>= jsonId + ) |