diff options
author | Félix Sipma <felix.sipma@no-log.org> | 2018-02-17 11:21:27 +0100 |
---|---|---|
committer | Félix Sipma <felix.sipma@no-log.org> | 2018-02-17 11:21:27 +0100 |
commit | eecc33687d6fda8caa2a3fa2868a54b1d4e4bd44 (patch) | |
tree | d6c4cc255e385c39108c40555053b8f79a442c6b | |
parent | 6540c36d87d26c024fa453576aceb1f755f76ded (diff) |
generate uuid for charge + return email & date
-rw-r--r-- | fournilsipma-server.cabal | 3 | ||||
-rw-r--r-- | package.yaml | 1 | ||||
-rw-r--r-- | src/Shop/Handler.hs | 10 | ||||
-rw-r--r-- | src/Shop/Types.hs | 4 |
4 files changed, 11 insertions, 7 deletions
diff --git a/fournilsipma-server.cabal b/fournilsipma-server.cabal index df9efed..7840289 100644 --- a/fournilsipma-server.cabal +++ b/fournilsipma-server.cabal @@ -2,7 +2,7 @@ -- -- see: https://github.com/sol/hpack -- --- hash: a6bbbc448cc8eb8a25a256d7e60259ba73005db0fc0095baa9fabd94efd1a39d +-- hash: 2f8de900b496f844b545353970a7e39ec571c26efb1443d49690bc42b5ae1199 name: fournilsipma-server version: 0.1.0 @@ -44,6 +44,7 @@ library , servant , servant-server , text + , uuid , wai , wai-extra , warp diff --git a/package.yaml b/package.yaml index 9b164c4..ba98640 100644 --- a/package.yaml +++ b/package.yaml @@ -33,6 +33,7 @@ library: - servant-server - servant - text + - uuid - wai - wai-extra - warp 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) diff --git a/src/Shop/Types.hs b/src/Shop/Types.hs index 81980b5..058317d 100644 --- a/src/Shop/Types.hs +++ b/src/Shop/Types.hs @@ -14,10 +14,10 @@ import Servant.API data ChargeResponse = ChargeResponse { chargeid :: Text - -- ^ TODO: generate id (uuid)? , chargeamount :: Text + , chargeemail :: Text + , chargedate :: Text } - -- ^ TODO: add email, date deriving (Show, Read, Generic, Eq) instance ToJSON ChargeResponse |