diff options
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r-- | src/client/elm/Server.elm | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm index f3ed949..9522d17 100644 --- a/src/client/elm/Server.elm +++ b/src/client/elm/Server.elm @@ -1,8 +1,8 @@ module Server exposing ( signIn - , addPayment + , createPayment , deletePayment - , addIncome + , createIncome , deleteIncome , signOut ) @@ -12,7 +12,7 @@ import Http import Date import Json.Decode exposing ((:=)) import Json.Encode as Json -import Time exposing (Time) +import Date exposing (Date) import Date.Extra.Format as DateFormat @@ -28,9 +28,17 @@ signIn email = post ("/signIn?email=" ++ email) |> Task.map (always ()) -addPayment : String -> Int -> Frequency -> Task Http.Error PaymentId -addPayment name cost frequency = - post ("/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost) ++ "&frequency=" ++ (toString frequency)) +createPayment : String -> Int -> Date -> Frequency -> Task Http.Error PaymentId +createPayment name cost date frequency = + Json.object + [ ("name", Json.string name) + , ("cost", Json.int cost) + , ("date", Json.string (DateFormat.isoDateString date)) + , ("frequency", Json.string (toString frequency)) + ] + |> Json.encode 0 + |> Http.string + |> postWithBody "/payment" |> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder) deletePayment : PaymentId -> Task Http.Error () @@ -38,11 +46,11 @@ deletePayment paymentId = delete ("/payment?id=" ++ (toString paymentId)) |> Task.map (always ()) -addIncome : Time -> Int -> Task Http.Error IncomeId -addIncome time amount = +createIncome : Int -> Date -> Task Http.Error IncomeId +createIncome amount date = Json.object - [ ("day", Json.string (DateFormat.isoDateString (Date.fromTime time))) - , ("amount", Json.int amount) + [ ("amount", Json.int amount) + , ("date", Json.string (DateFormat.isoDateString date)) ] |> Json.encode 0 |> Http.string |