diff options
author | Joris | 2015-09-05 13:53:36 +0200 |
---|---|---|
committer | Joris | 2015-09-05 13:53:36 +0200 |
commit | 3b738e0d4cc65f314da7389d4542ec826ba0f454 (patch) | |
tree | ee99236117ad698974c5a6e40ab170f617cb06f3 /src/server/Model/Payment.hs | |
parent | 139d4a103a6a48880e5f12a796033956f223563c (diff) |
Using UserId instead of UserName to indentify users
Diffstat (limited to 'src/server/Model/Payment.hs')
-rw-r--r-- | src/server/Model/Payment.hs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs index ce8c5a1..d7632f0 100644 --- a/src/server/Model/Payment.hs +++ b/src/server/Model/Payment.hs @@ -1,14 +1,12 @@ module Model.Payment ( getPayments , createPayment - , paymentKeyToText , deleteOwnPayment , getTotalPayments , getPaymentsCount ) where import Data.Text (Text) -import qualified Data.Text as T import Data.Time.Clock (getCurrentTime) import Data.Maybe (catMaybes) @@ -40,16 +38,13 @@ getJsonPayment (paymentEntity, userEntity) = let payment = entityVal paymentEntity user = entityVal userEntity in P.Payment - { P.id = paymentKeyToText . entityKey $ paymentEntity + { P.id = entityKey paymentEntity , P.creation = paymentCreation payment , P.name = paymentName payment , P.cost = paymentCost payment - , P.userName = userName user + , P.userId = entityKey userEntity } -paymentKeyToText :: Key Payment -> Text -paymentKeyToText = T.pack . show . unSqlBackendKey . unPaymentKey - createPayment :: UserId -> Text -> Int -> Persist PaymentId createPayment userId name cost = do now <- liftIO getCurrentTime @@ -77,11 +72,11 @@ getTotalPayments = do on (payment ^. PaymentUserId E.==. user ^. UserId) where_ (isNothing (payment ^. PaymentDeletedAt)) groupBy (payment ^. PaymentUserId) - return (user ^. UserName, sum_ (payment ^. PaymentCost)) + return (user ^. UserId, sum_ (payment ^. PaymentCost)) return $ catMaybes . map (getTotalPayment . unValueTuple) $ values -getTotalPayment :: (Text, Maybe Int) -> Maybe TP.TotalPayment -getTotalPayment (userName, Just cost) = Just (TP.TotalPayment userName cost) +getTotalPayment :: (UserId, Maybe Int) -> Maybe TP.TotalPayment +getTotalPayment (userId, Just cost) = Just (TP.TotalPayment userId cost) getTotalPayment (_, Nothing) = Nothing unValueTuple :: (Value a, Value b) -> (a, b) |