aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Server.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r--src/client/elm/Server.elm20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm
index d56bc48..dc47007 100644
--- a/src/client/elm/Server.elm
+++ b/src/client/elm/Server.elm
@@ -9,8 +9,12 @@ module Server exposing
import Task as Task exposing (Task)
import Http
-import Json.Decode as Json exposing ((:=))
-import Date exposing (Date)
+import Date
+import Json.Decode exposing ((:=))
+import Json.Encode as Json
+import Time exposing (Time)
+
+import Date.Extra.Format as DateFormat
import Utils.Http exposing (..)
@@ -34,9 +38,15 @@ deletePayment paymentId =
delete ("/payment?id=" ++ (toString paymentId))
|> Task.map (always ())
-addIncome : Date -> Int -> Task Http.Error IncomeId
-addIncome creation amount =
- post ("/income?creation=" ++ (toString << Date.toTime <| creation) ++ "&amount=" ++ (toString amount))
+addIncome : Time -> Int -> Task Http.Error IncomeId
+addIncome time amount =
+ Json.object
+ [ ("day", Json.string (DateFormat.isoDateString (Date.fromTime time)))
+ , ("amount", Json.int amount)
+ ]
+ |> Json.encode 0
+ |> Http.string
+ |> postWithBody "/income"
|> flip Task.andThen (decodeHttpValue <| "id" := incomeIdDecoder)
deleteIncome : IncomeId -> Task Http.Error ()