summaryrefslogtreecommitdiff
path: root/src/Shop/Handler.hs
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2018-02-17 11:21:27 +0100
committerFélix Sipma <felix.sipma@no-log.org>2018-02-17 11:21:27 +0100
commiteecc33687d6fda8caa2a3fa2868a54b1d4e4bd44 (patch)
treed6c4cc255e385c39108c40555053b8f79a442c6b /src/Shop/Handler.hs
parent6540c36d87d26c024fa453576aceb1f755f76ded (diff)
generate uuid for charge + return email & date
Diffstat (limited to 'src/Shop/Handler.hs')
-rw-r--r--src/Shop/Handler.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Shop/Handler.hs b/src/Shop/Handler.hs
index f873535..0d2f7d5 100644
--- a/src/Shop/Handler.hs
+++ b/src/Shop/Handler.hs
@@ -8,6 +8,8 @@ module Shop.Handler where
import Control.Monad.Logger (LoggingT, runStdoutLoggingT,
logInfo, logWarn)
+import qualified Data.UUID as UUID
+import qualified Data.UUID.V4 as UUID
import Formatting (format, (%), fixed)
import Shop.Config
import Shop.Types
@@ -44,13 +46,13 @@ charge :: ChargeForm -> App ChargeResponse
charge chargeform = do
cfg <- ask
-- TODO: send email
- let cid = "TODO"
- -- ^ generate id (uuid)
- a = show total
+ cid <- liftIO $ UUID.toText <$> UUID.nextRandom
$(logInfo) $ "Charge successfully created: \"" <> email chargeform <> "\" (" <> showPrice total <> ")"
return ChargeResponse
{ chargeid = cid
- , chargeamount = a
+ , chargeamount = show total
+ , chargeemail = email chargeform
+ , chargedate = date chargeform
}
where
total = foldl (\n a -> n + quantity a * prix (product a)) 0 (articles chargeform)