From 6a0c5087f716ed6c876a666db6573491bfd3e094 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 12 Jun 2016 23:54:17 +0200 Subject: Design income form --- src/client/elm/Server.elm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/client/elm/Server.elm') 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 () -- cgit v1.2.3