diff options
author | Joris Guyonvarch | 2015-08-13 22:55:41 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-08-13 22:55:41 +0200 |
commit | 359f837511597354bc6462cfc4200f54d647d728 (patch) | |
tree | 13d896bd1280a735945609e890faa606abd135fa /src/server/Model/Payment.hs | |
parent | 35557ae09d10aa6388b79e2e19ee7702efb28bc6 (diff) |
Giving the payment id to the client
Diffstat (limited to 'src/server/Model/Payment.hs')
-rw-r--r-- | src/server/Model/Payment.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs index ad1c261..2e191b9 100644 --- a/src/server/Model/Payment.hs +++ b/src/server/Model/Payment.hs @@ -1,9 +1,11 @@ module Model.Payment ( getPayments , createPayment + , paymentKeyToText ) where import Data.Text (Text) +import qualified Data.Text as T import Data.Time.Clock (getCurrentTime) import Control.Monad.IO.Class (liftIO) @@ -27,8 +29,16 @@ getJsonPayment :: (Entity Payment, Entity User) -> P.Payment getJsonPayment (paymentEntity, userEntity) = let payment = entityVal paymentEntity user = entityVal userEntity - in P.Payment (paymentCreation payment) (paymentName payment) (paymentCost payment) (userName user) - + in P.Payment + { P.id = paymentKeyToText . entityKey $ paymentEntity + , P.creation = paymentCreation payment + , P.name = paymentName payment + , P.cost = paymentCost payment + , P.userName = userName user + } + +paymentKeyToText :: Key Payment -> Text +paymentKeyToText = T.pack . show . unSqlBackendKey . unPaymentKey createPayment :: UserId -> Text -> Int -> Persist PaymentId createPayment userId name cost = do |