aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/elm/LoggedIn/Home/Model.elm6
-rw-r--r--src/client/elm/LoggedIn/Home/Update.elm2
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm2
-rw-r--r--src/client/elm/Model/Init.elm1
-rw-r--r--src/client/elm/Server.elm1
-rw-r--r--src/server/Controller/Payment.hs8
-rw-r--r--src/server/Main.hs2
-rw-r--r--src/server/Model/Json/Payer.hs22
-rw-r--r--src/server/Model/Payer/Payment.hs40
-rw-r--r--src/server/Model/Payment.hs8
10 files changed, 3 insertions, 89 deletions
diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm
index 14ab86c..f8d24f5 100644
--- a/src/client/elm/LoggedIn/Home/Model.elm
+++ b/src/client/elm/LoggedIn/Home/Model.elm
@@ -14,12 +14,11 @@ import LoggedIn.Home.AddPayment.Model as AddPaymentModel
import LoggedIn.Home.Monthly.Model as MonthlyModel
type alias Model =
- { users : Users
- , add : AddPaymentModel.Model
+ { add : AddPaymentModel.Model
, monthly : MonthlyModel.Model
, account : AccountModel.Model
+ , users : Users
, payments : Payments
- , paymentsCount : Int
, paymentEdition : Maybe PaymentId
, currentPage : Int
}
@@ -31,7 +30,6 @@ init initData =
, monthly = MonthlyModel.init initData.monthlyPayments
, account = AccountModel.init initData.me initData.incomes
, payments = initData.payments
- , paymentsCount = initData.paymentsCount
, paymentEdition = Nothing
, currentPage = 1
}
diff --git a/src/client/elm/LoggedIn/Home/Update.elm b/src/client/elm/LoggedIn/Home/Update.elm
index 352c76b..ee0a7c3 100644
--- a/src/client/elm/LoggedIn/Home/Update.elm
+++ b/src/client/elm/LoggedIn/Home/Update.elm
@@ -80,7 +80,6 @@ update model action loggedInModel =
, add = newAdd
, account = loggedInModel.account
, payments = newPayment :: loggedInModel.payments
- , paymentsCount = loggedInModel.paymentsCount + 1
}
, Effects.none
)
@@ -117,7 +116,6 @@ update model action loggedInModel =
( { loggedInModel
| account = loggedInModel.account
, payments = deletePayment payment.id loggedInModel.payments
- , paymentsCount = loggedInModel.paymentsCount - 1
}
, Effects.none
)
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm
index 31aa032..9942aa8 100644
--- a/src/client/elm/LoggedIn/Home/View/Paging.elm
+++ b/src/client/elm/LoggedIn/Home/View/Paging.elm
@@ -23,7 +23,7 @@ showedPages = 5
paymentsPaging : Address Action -> HomeModel.Model -> Html
paymentsPaging address homeModel =
- let maxPage = ceiling (toFloat homeModel.paymentsCount / toFloat perPage)
+ let maxPage = ceiling (toFloat (List.length homeModel.payments) / toFloat perPage)
pages = truncatePages homeModel.currentPage [1..maxPage]
in if maxPage == 1
then
diff --git a/src/client/elm/Model/Init.elm b/src/client/elm/Model/Init.elm
index d9dbc36..7028427 100644
--- a/src/client/elm/Model/Init.elm
+++ b/src/client/elm/Model/Init.elm
@@ -11,6 +11,5 @@ type alias Init =
, me : UserId
, payments : Payments
, monthlyPayments : Payments
- , paymentsCount : Int
, incomes : Incomes
}
diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm
index b6928de..b4afe20 100644
--- a/src/client/elm/Server.elm
+++ b/src/client/elm/Server.elm
@@ -27,7 +27,6 @@ init =
`Task.andMap` (Http.get ("id" := userIdDecoder) "/api/whoAmI")
`Task.andMap` (Http.get paymentsDecoder "/api/payments")
`Task.andMap` (Http.get paymentsDecoder "/api/monthlyPayments")
- `Task.andMap` (Http.get ("number" := Json.int) "/api/payments/count")
`Task.andMap` (Http.get incomesDecoder "/api/incomes")
signIn : String -> Task Http.Error ()
diff --git a/src/server/Controller/Payment.hs b/src/server/Controller/Payment.hs
index ec241f7..a9d1acb 100644
--- a/src/server/Controller/Payment.hs
+++ b/src/server/Controller/Payment.hs
@@ -5,7 +5,6 @@ module Controller.Payment
, getMonthlyPayments
, createPayment
, deletePayment
- , getPaymentsCount
) where
import Web.Scotty
@@ -28,7 +27,6 @@ import Json (jsonObject)
import Model.Database
import qualified Model.Payment as P
import Model.Frequency
-import Model.Json.Number
import Model.Message.Key (Key(PaymentNotDeleted))
getPayments :: ActionM ()
@@ -66,9 +64,3 @@ deletePayment paymentId =
status badRequest400
text . TL.pack . show $ PaymentNotDeleted
)
-
-getPaymentsCount :: ActionM ()
-getPaymentsCount =
- Secure.loggedAction (\_ -> do
- Number <$> (liftIO . runDb $ P.getPaymentsCount) >>= json
- )
diff --git a/src/server/Main.hs b/src/server/Main.hs
index e4ad9f6..1cb324e 100644
--- a/src/server/Main.hs
+++ b/src/server/Main.hs
@@ -87,5 +87,3 @@ api conf = do
post "/api/payment/delete" $ do
paymentId <- param "id" :: ActionM Text
deletePayment paymentId
-
- get "/api/payments/count" getPaymentsCount
diff --git a/src/server/Model/Json/Payer.hs b/src/server/Model/Json/Payer.hs
deleted file mode 100644
index 2101e40..0000000
--- a/src/server/Model/Json/Payer.hs
+++ /dev/null
@@ -1,22 +0,0 @@
-{-# LANGUAGE DeriveGeneric #-}
-
-module Model.Json.Payer
- ( Payer(..)
- ) where
-
-import GHC.Generics
-
-import Data.Aeson
-
-import Model.Database (UserId)
-import Model.Json.Income
-
-data Payer = Payer
- { userId :: UserId
- , preIncomePaymentSum :: Int
- , postIncomePaymentSum :: Int
- , incomes :: [Income]
- } deriving (Show, Generic)
-
-instance FromJSON Payer
-instance ToJSON Payer
diff --git a/src/server/Model/Payer/Payment.hs b/src/server/Model/Payer/Payment.hs
deleted file mode 100644
index 6efc38d..0000000
--- a/src/server/Model/Payer/Payment.hs
+++ /dev/null
@@ -1,40 +0,0 @@
-module Model.Payer.Payment
- ( getTotalPaymentsBefore
- , getTotalPaymentsAfter
- ) where
-
-import Data.Time.Clock (UTCTime)
-import Data.Maybe (catMaybes)
-
-import Database.Persist
-import Database.Esqueleto
-import qualified Database.Esqueleto as E
-
-import Model.Database
-import Model.Frequency
-
-getTotalPaymentsBefore :: UTCTime -> Persist [(UserId, Int)]
-getTotalPaymentsBefore time =
- getTotalPayments (\p -> p ^. PaymentCreation E.<. val time)
-
-getTotalPaymentsAfter :: UTCTime -> Persist [(UserId, Int)]
-getTotalPaymentsAfter time =
- getTotalPayments (\p -> p ^. PaymentCreation E.>=. val time)
-
-getTotalPayments :: (SqlExpr (Entity Payment) -> SqlExpr (Value Bool)) -> Persist [(UserId, Int)]
-getTotalPayments paymentWhere = do
- values <- select $
- from $ \payment -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Punctual)
- where_ (paymentWhere payment)
- groupBy (payment ^. PaymentUserId)
- return (payment ^. PaymentUserId, sum_ (payment ^. PaymentCost))
- return $ catMaybes . map (unMaybe . unValueTuple) $ values
-
-unValueTuple :: (Value a, Value b) -> (a, b)
-unValueTuple (Value a, Value b) = (a, b)
-
-unMaybe :: (a, Maybe b) -> Maybe (a, b)
-unMaybe (a, Just b) = Just (a, b)
-unMaybe _ = Nothing
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs
index 9b32fea..5c7d940 100644
--- a/src/server/Model/Payment.hs
+++ b/src/server/Model/Payment.hs
@@ -6,7 +6,6 @@ module Model.Payment
, getMonthlyPayments
, createPayment
, deleteOwnPayment
- , getPaymentsCount
) where
import Data.Text (Text)
@@ -91,10 +90,3 @@ deleteOwnPayment user paymentId = do
return False
Nothing ->
return False
-
-getPaymentsCount :: Persist Int
-getPaymentsCount =
- count
- [ PaymentDeletedAt P.==. Nothing
- , PaymentFrequency P.==. Punctual
- ]