aboutsummaryrefslogtreecommitdiff
path: root/src/server/Main.hs
diff options
context:
space:
mode:
authorJoris2016-11-13 00:49:32 +0100
committerJoris2016-11-13 00:49:32 +0100
commit86a96decdb8892b10c5314eb916ef15a64204450 (patch)
tree6f41742d0466f77948680964188144fbff036902 /src/server/Main.hs
parentbf6a0a0b32a7efb88f75c2e89b84d6907aeb10bc (diff)
downloadbudget-86a96decdb8892b10c5314eb916ef15a64204450.tar.gz
budget-86a96decdb8892b10c5314eb916ef15a64204450.tar.bz2
budget-86a96decdb8892b10c5314eb916ef15a64204450.zip
Send weekly activity at start of week about previous week
Diffstat (limited to 'src/server/Main.hs')
-rw-r--r--src/server/Main.hs71
1 files changed, 30 insertions, 41 deletions
diff --git a/src/server/Main.hs b/src/server/Main.hs
index 4636674..2ce8115 100644
--- a/src/server/Main.hs
+++ b/src/server/Main.hs
@@ -3,14 +3,10 @@
import Web.Scotty
import Network.Wai.Middleware.Static
-import Network.HTTP.Types.Status (ok200)
-import Control.Concurrent (forkIO)
+import Job.Daemon (runDaemons)
-import MonthlyPaymentJob (monthlyPaymentJobListener)
-
-import Data.Text (Text)
-import qualified Data.Text.IO as T
+import qualified Data.Text.Lazy as LT
import Controller.Index
import Controller.SignIn
@@ -24,48 +20,41 @@ import qualified Conf
main :: IO ()
main = do
runMigrations
- _ <- forkIO monthlyPaymentJobListener
- confOrError <- Conf.getConf "application.conf"
- case confOrError of
- Left errorMessage ->
- T.putStrLn errorMessage
- Right conf -> do
- scotty (Conf.port conf) $ do
- middleware $
- staticPolicy (noDots >-> addBase "public")
-
- get "/" $
- ( do
- signInToken <- param "signInToken" :: ActionM Text
- status ok200
- getIndex conf (Just signInToken)
- ) `rescue` (\_ -> do
- status ok200
- getIndex conf Nothing
- )
+ conf <- Conf.get "application.conf"
+ _ <- runDaemons conf
+ scotty (Conf.port conf) $ do
+ middleware . staticPolicy $ noDots >-> addBase "public"
- post "/signIn" $ do
- email <- param "email" :: ActionM Text
- signIn conf email
+ get "/" $ do
+ signInToken <- mbParam "signInToken"
+ getIndex conf signInToken
- post "/signOut" (signOut conf)
+ post "/signIn" $ do
+ email <- param "email"
+ signIn conf email
- -- Payments
+ post "/signOut" $
+ signOut conf
- post "/payment" $ jsonData >>= Payment.create
+ post "/payment" $
+ jsonData >>= Payment.create
- put "/payment" $ jsonData >>= Payment.editOwn
+ put "/payment" $
+ jsonData >>= Payment.editOwn
- delete "/payment" $ do
- paymentId <- param "id" :: ActionM Text
- Payment.deleteOwn paymentId
+ delete "/payment" $ do
+ paymentId <- param "id"
+ Payment.deleteOwn paymentId
- -- Incomes
+ post "/income" $
+ jsonData >>= Income.create
- post "/income" $ jsonData >>= Income.create
+ put "/income" $
+ jsonData >>= Income.editOwn
- put "/income" $ jsonData >>= Income.editOwn
+ delete "/income" $ do
+ incomeId <- param "id"
+ Income.deleteOwn incomeId
- delete "/income" $ do
- incomeId <- param "id" :: ActionM Text
- Income.deleteOwn incomeId
+mbParam :: Parsable a => LT.Text -> ActionM (Maybe a)
+mbParam key = (Just <$> param key) `rescue` (const . return $ Nothing)