diff options
author | Joris | 2016-06-12 23:54:17 +0200 |
---|---|---|
committer | Joris | 2016-06-12 23:54:17 +0200 |
commit | 6a0c5087f716ed6c876a666db6573491bfd3e094 (patch) | |
tree | bf439109143c7a1749c2661fc8b805b83a993027 /src/client/elm/Server.elm | |
parent | 38896af4281d2e191cbde15836a23e4c0274fff6 (diff) |
Design income form
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r-- | src/client/elm/Server.elm | 20 |
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 () |