From 3b738e0d4cc65f314da7389d4542ec826ba0f454 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 5 Sep 2015 13:53:36 +0200 Subject: Using UserId instead of UserName to indentify users --- src/server/Model/Payment.hs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/server/Model/Payment.hs') 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) -- cgit v1.2.3