aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Server.elm
diff options
context:
space:
mode:
authorJoris2016-01-03 19:41:31 +0100
committerJoris2016-01-03 19:41:31 +0100
commita8309988518af5bddf62d6a326d990fde4069b40 (patch)
tree6ff9c0af27d78f8579b5c3975378a3c82899593c /src/client/elm/Server.elm
parent0cba27cba2b44756389d50bc113f23a2be87e978 (diff)
downloadbudget-a8309988518af5bddf62d6a326d990fde4069b40.tar.gz
budget-a8309988518af5bddf62d6a326d990fde4069b40.tar.bz2
budget-a8309988518af5bddf62d6a326d990fde4069b40.zip
Set focus properties to button elements
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r--src/client/elm/Server.elm65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm
new file mode 100644
index 0000000..cb65868
--- /dev/null
+++ b/src/client/elm/Server.elm
@@ -0,0 +1,65 @@
+module Server
+ ( signIn
+ , addPayment
+ , deletePayment
+ , setIncome
+ , signOut
+ , initViewAction
+ ) where
+
+import Signal
+import Task as Task exposing (Task)
+import Http
+import Json.Decode as Json exposing ((:=))
+import Date
+import Time exposing (Time)
+import Debug
+
+import SimpleHTTP exposing (..)
+
+import Model.Action as U exposing (Action)
+import Model.Action.LoggedInAction as UL exposing (LoggedInAction)
+import Model.Action.MonthlyAction as UM exposing (MonthlyAction)
+import Model.Action.AccountAction as UA exposing (AccountAction)
+import Model.Payment exposing (..)
+import Model.Payer exposing (Payers, payersDecoder)
+import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder)
+
+import Update.SignIn exposing (updateSignIn)
+
+signIn : String -> Task Http.Error Action
+signIn assertion =
+ post ("/signIn?assertion=" ++ assertion)
+ |> flip Task.andThen (always initViewAction)
+
+addPayment : String -> Int -> PaymentFrequency -> Task Http.Error LoggedInAction
+addPayment name cost frequency =
+ post ("/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost) ++ "&frequency=" ++ (toString frequency))
+ |> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder)
+ |> Task.map (\paymentId -> (UL.ValidateAddPayment paymentId name cost frequency))
+
+deletePayment : Payment -> PaymentFrequency -> Task Http.Error LoggedInAction
+deletePayment payment frequency =
+ post ("payment/delete?id=" ++ (toString payment.id))
+ |> Task.map (always (UL.ValidateDeletePayment payment frequency))
+
+setIncome : Time -> Int -> Task Http.Error Action
+setIncome currentTime amount =
+ post ("/income?amount=" ++ (toString amount))
+ |> Task.map (always (U.UpdateLoggedIn (UL.UpdateAccount (UA.UpdateIncome currentTime amount))))
+
+signOut : Task Http.Error Action
+signOut =
+ post "/signOut"
+ |> Task.map (always U.GoSignInView)
+
+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")