diff options
Diffstat (limited to 'src/client/ServerCommunication.elm')
-rw-r--r-- | src/client/ServerCommunication.elm | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index 5736f77..47d8c27 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -18,12 +18,14 @@ import Update as U import Update.SignIn exposing (..) import Update.LoggedIn as UL import Update.LoggedIn.Monthly as UM +import Update.LoggedIn.Account as UA type Communication = NoCommunication | SignIn String | AddPayment UserId String Int | AddMonthlyPayment String Int + | SetIncome Int | DeletePayment PaymentId UserId Int Int | DeleteMonthlyPayment PaymentId | UpdatePage Int @@ -48,6 +50,7 @@ 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) DeleteMonthlyPayment paymentId -> Just (deletePaymentRequest paymentId) UpdatePage page -> Just (updatePageRequest page) @@ -88,10 +91,12 @@ serverResult communication response = Task.succeed <| U.UpdateLoggedIn (UL.AddPayment userId name cost payments) )) AddMonthlyPayment name cost -> - decodeOkResponse + decodeResponse ("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 -> Http.send Http.defaultSettings (updatePageRequest currentPage) |> flip Task.andThen (decodeOkResponse paymentsDecoder (\payments -> @@ -100,7 +105,7 @@ serverResult communication response = DeleteMonthlyPayment id -> Task.succeed <| U.UpdateLoggedIn (UL.UpdateMonthly (UM.DeletePayment id)) UpdatePage page -> - decodeOkResponse + decodeResponse paymentsDecoder (\payments -> Task.succeed <| U.UpdateLoggedIn (UL.UpdatePage page payments)) response |