aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller/Payment.hs
blob: 141aed07e860cd076f7efa11ab2928996ab095c0 (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
module Controller.Payment
  ( getPaymentsAction
  , createPaymentAction
  ) where

import Web.Scotty

import Database.Persist

import Control.Monad.IO.Class (liftIO)

import Data.Text (Text)

import qualified Secure

import Model.Database
import Model.Payment
import Model.Json.Message

getPaymentsAction :: ActionM ()
getPaymentsAction =
  Secure.loggedAction (\_ -> do
    payments <- liftIO $ runDb getPayments
    json payments
  )

createPaymentAction :: Text -> Int -> ActionM ()
createPaymentAction name cost =
  Secure.loggedAction (\user -> do
    paymentKey <- liftIO . runDb $ createPayment (entityKey user) name cost
    json . Message . paymentKeyToText $ paymentKey
  )