From 86a96decdb8892b10c5314eb916ef15a64204450 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Nov 2016 00:49:32 +0100 Subject: Send weekly activity at start of week about previous week --- src/server/Main.hs | 71 +++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 41 deletions(-) (limited to 'src/server/Main.hs') 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) -- cgit v1.2.3