diff options
author | Joris | 2015-10-04 20:48:32 +0200 |
---|---|---|
committer | Joris | 2015-10-04 20:48:32 +0200 |
commit | 8c24464a4bd0a486cd0ddf846d3b5a323a7aaa9a (patch) | |
tree | cdd1bb79846b3d8865d833a122152528b03a4746 /src/client/ServerCommunication.elm | |
parent | 303dfd66c6434e19ba226a133a35a74a557b3e93 (diff) |
Using incomes to compute a fair computation to designate the payer
Diffstat (limited to 'src/client/ServerCommunication.elm')
-rw-r--r-- | src/client/ServerCommunication.elm | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index 47d8c27..55bf947 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -9,6 +9,7 @@ import Task as Task exposing (Task) import Http import Json.Decode exposing (..) import Date +import Time exposing (Time) import Model.User exposing (UserId) import Model.Payment exposing (..) @@ -25,8 +26,8 @@ type Communication = | SignIn String | AddPayment UserId String Int | AddMonthlyPayment String Int - | SetIncome Int - | DeletePayment PaymentId UserId Int Int + | SetIncome Time Int + | DeletePayment Payment Int | DeleteMonthlyPayment PaymentId | UpdatePage Int | SignOut @@ -50,8 +51,8 @@ getRequest communication = SignIn login -> Just (simple "post" ("/signIn?login=" ++ login)) AddPayment userId name cost -> Just (addPaymentRequest name cost Punctual) AddMonthlyPayment name cost -> Just (addPaymentRequest name cost Monthly) - SetIncome amount -> Just (simple "post" ("/income?amount=" ++ (toString amount))) - DeletePayment paymentId _ _ _ -> Just (deletePaymentRequest paymentId) + SetIncome _ amount -> Just (simple "post" ("/income?amount=" ++ (toString amount))) + DeletePayment payment _ -> Just (deletePaymentRequest payment.id) DeleteMonthlyPayment paymentId -> Just (deletePaymentRequest paymentId) UpdatePage page -> Just (updatePageRequest page) SignOut -> Just (simple "post" "/signOut") @@ -95,12 +96,12 @@ serverResult communication response = ("id" := paymentIdDecoder) (\id -> Task.succeed <| U.UpdateLoggedIn (UL.AddMonthlyPayment id name cost)) response - SetIncome amount -> - Task.succeed <| U.UpdateLoggedIn (UL.UpdateAccount (UA.UpdateIncome amount)) - DeletePayment id userId cost currentPage -> + SetIncome currentTime amount -> + Task.succeed <| U.UpdateLoggedIn (UL.UpdateAccount (UA.UpdateIncome currentTime amount)) + DeletePayment payment currentPage -> Http.send Http.defaultSettings (updatePageRequest currentPage) |> flip Task.andThen (decodeOkResponse paymentsDecoder (\payments -> - Task.succeed <| U.UpdateLoggedIn (UL.DeletePayment userId cost payments) + Task.succeed <| U.UpdateLoggedIn (UL.DeletePayment payment payments) )) DeleteMonthlyPayment id -> Task.succeed <| U.UpdateLoggedIn (UL.UpdateMonthly (UM.DeletePayment id)) |