aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/ServerCommunication.elm
diff options
context:
space:
mode:
authorJoris2016-01-02 20:49:24 +0100
committerJoris2016-01-02 20:49:24 +0100
commit35493d8ec353f90a6ca67e2aedb702684e0abafa (patch)
treea1c6eba2cde84b89e7554618479d7eab0ef7c480 /src/client/elm/ServerCommunication.elm
parent302a2e798f10e61c129753a2bd11634420c1f1a1 (diff)
downloadbudget-35493d8ec353f90a6ca67e2aedb702684e0abafa.tar.gz
budget-35493d8ec353f90a6ca67e2aedb702684e0abafa.tar.bz2
budget-35493d8ec353f90a6ca67e2aedb702684e0abafa.zip
Moving initViewAction to serverCommunication module
Diffstat (limited to 'src/client/elm/ServerCommunication.elm')
-rw-r--r--src/client/elm/ServerCommunication.elm25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/client/elm/ServerCommunication.elm b/src/client/elm/ServerCommunication.elm
index ff0937e..bc8d59f 100644
--- a/src/client/elm/ServerCommunication.elm
+++ b/src/client/elm/ServerCommunication.elm
@@ -1,11 +1,12 @@
module ServerCommunication
( sendRequest
+ , initViewAction
) where
import Signal
import Task as Task exposing (Task)
import Http
-import Json.Decode exposing (..)
+import Json.Decode as Json exposing ((:=))
import Date
import Time exposing (Time)
import Debug
@@ -13,24 +14,21 @@ import Debug
import SimpleHTTP exposing (..)
import Model.Communication exposing (..)
-import Model.Action as U
+import Model.Action as U exposing (Action)
import Model.Action.LoggedInAction as UL
import Model.Action.MonthlyAction as UM
import Model.Action.AccountAction as UA
import Model.View.LoggedIn.AddPayment exposing (Frequency(..))
-import Model.Payment exposing (..)
+import Model.Payment exposing (PaymentId, paymentIdDecoder, Payments, paymentsDecoder)
+import Model.Payer exposing (Payers, payersDecoder)
+import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder)
import Update.SignIn exposing (updateSignIn)
-import InitViewAction exposing (initViewAction)
-
sendRequest : Communication -> Task Http.Error U.Action
sendRequest communication =
case communication of
- NoCommunication ->
- Task.succeed U.NoOp
-
SignIn assertion ->
post ("/signIn?assertion=" ++ assertion)
|> flip Task.andThen (always initViewAction)
@@ -68,3 +66,14 @@ addPaymentURL name cost frequency =
deletePaymentURL : PaymentId -> String
deletePaymentURL id =
"payment/delete?id=" ++ (toString id)
+
+initViewAction = Task.onError loggedInView (always <| Task.succeed U.GoSignInView)
+
+loggedInView : Task Http.Error Action
+loggedInView =
+ Task.map U.GoLoggedInView (Http.get usersDecoder "/users")
+ `Task.andMap` (Http.get ("id" := userIdDecoder) "/whoAmI")
+ `Task.andMap` (Http.get paymentsDecoder "/monthlyPayments")
+ `Task.andMap` (Http.get paymentsDecoder "/payments")
+ `Task.andMap` (Http.get ("number" := Json.int) "/payments/count")
+ `Task.andMap` (Http.get payersDecoder "/payers")