aboutsummaryrefslogtreecommitdiff
path: root/server/src/Main.hs
blob: 9882092e9da43eb491d614c92f03ef0fffff4f98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module Main
  ( main
  ) where

import qualified Network.HTTP.Types.Status     as Status
import           Network.Wai.Middleware.Gzip   (GzipFiles (GzipCompress))
import qualified Network.Wai.Middleware.Gzip   as W
import           Network.Wai.Middleware.Static
import qualified Web.Scotty                    as S

import qualified Conf
import qualified Controller.Category           as Category
import qualified Controller.Income             as Income
import qualified Controller.Index              as Index
import qualified Controller.Payment            as Payment
import qualified Controller.User               as User
import           Job.Daemon                    (runDaemons)

main :: IO ()
main = do
  conf <- Conf.get "application.conf"
  _ <- runDaemons conf
  S.scotty (Conf.port conf) $ do

    S.middleware $
      W.gzip $ W.def { W.gzipFiles = GzipCompress }

    S.middleware . staticPolicy $
      noDots >-> addBase "public"

    S.post "/api/askSignIn" $
      S.jsonData >>= Index.askSignIn conf

    S.get "/api/signIn/:signInToken" $ do
      signInToken <- S.param "signInToken"
      Index.trySignIn conf signInToken

    S.post "/api/signOut" $
      Index.signOut conf

    S.get "/api/users"$
      User.list

    S.get "/api/payments" $
      Payment.list

    S.post "/api/payment" $
      S.jsonData >>= Payment.create

    S.put "/api/payment" $
      S.jsonData >>= Payment.edit

    S.delete "/api/payment/:id" $ do
      paymentId <- S.param "id"
      Payment.delete paymentId

    S.get "/api/incomes" $
      Income.list

    S.post "/api/income" $
      S.jsonData >>= Income.create

    S.put "/api/income" $
      S.jsonData >>= Income.edit

    S.delete "/api/income/:id" $ do
      incomeId <- S.param "id"
      Income.delete incomeId

    S.get "/api/paymentCategories" $
      Payment.listPaymentCategories

    S.get "/api/categories" $
      Category.list

    S.post "/api/category" $
      S.jsonData >>= Category.create

    S.put "/api/category" $
      S.jsonData >>= Category.edit

    S.delete "/api/category/:id" $ do
      categoryId <- S.param "id"
      Category.delete categoryId

    S.notFound $ do
      S.status Status.ok200
      Index.get conf