diff options
author | Joris | 2016-06-27 14:36:03 +0200 |
---|---|---|
committer | Joris | 2016-06-27 14:36:03 +0200 |
commit | f605541cbaaa3c339eef8f345547bcd653d3f721 (patch) | |
tree | 1e800df7736e482290ca138726595e067e4a5cf9 /src/client/elm/Server.elm | |
parent | 885dfd7708e338a3220c85b7f22a3ac267aad3f7 (diff) |
Add the edit functionnality on payments
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r-- | src/client/elm/Server.elm | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm index 9522d17..fd32cec 100644 --- a/src/client/elm/Server.elm +++ b/src/client/elm/Server.elm @@ -1,6 +1,7 @@ module Server exposing ( signIn , createPayment + , editPayment , deletePayment , createIncome , deleteIncome @@ -16,7 +17,7 @@ import Date exposing (Date) import Date.Extra.Format as DateFormat -import Utils.Http exposing (..) +import Utils.Http as HttpUtils import Model.Payment exposing (..) import Model.Income exposing (incomesDecoder, incomeIdDecoder, IncomeId) @@ -25,7 +26,7 @@ import Model.Init exposing (Init) signIn : String -> Task Http.Error () signIn email = - post ("/signIn?email=" ++ email) + HttpUtils.request "POST" ("/signIn?email=" ++ email) |> Task.map (always ()) createPayment : String -> Int -> Date -> Frequency -> Task Http.Error PaymentId @@ -36,14 +37,24 @@ createPayment name cost date frequency = , ("date", Json.string (DateFormat.isoDateString date)) , ("frequency", Json.string (toString frequency)) ] - |> Json.encode 0 - |> Http.string - |> postWithBody "/payment" - |> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder) + |> HttpUtils.jsonRequest "POST" "/payment" + |> flip Task.andThen (HttpUtils.decodeHttpValue <| "id" := paymentIdDecoder) + +editPayment : PaymentId -> String -> Int -> Date -> Frequency -> Task Http.Error () +editPayment paymentId name cost date frequency = + Json.object + [ ("id", Json.int paymentId) + , ("name", Json.string name) + , ("cost", Json.int cost) + , ("date", Json.string (DateFormat.isoDateString date)) + , ("frequency", Json.string (toString frequency)) + ] + |> HttpUtils.jsonRequest "PUT" "/payment" + |> Task.map (always ()) deletePayment : PaymentId -> Task Http.Error () deletePayment paymentId = - delete ("/payment?id=" ++ (toString paymentId)) + HttpUtils.request "DELETE" ("/payment?id=" ++ (toString paymentId)) |> Task.map (always ()) createIncome : Int -> Date -> Task Http.Error IncomeId @@ -52,17 +63,15 @@ createIncome amount date = [ ("amount", Json.int amount) , ("date", Json.string (DateFormat.isoDateString date)) ] - |> Json.encode 0 - |> Http.string - |> postWithBody "/income" - |> flip Task.andThen (decodeHttpValue <| "id" := incomeIdDecoder) + |> HttpUtils.jsonRequest "POST" "/income" + |> flip Task.andThen (HttpUtils.decodeHttpValue <| "id" := incomeIdDecoder) deleteIncome : IncomeId -> Task Http.Error () deleteIncome incomeId = - delete ("/income?id=" ++ (toString incomeId)) + HttpUtils.request "DELETE" ("/income?id=" ++ (toString incomeId)) |> Task.map (always ()) signOut : Task Http.Error () signOut = - post "/signOut" + HttpUtils.request "POST" "/signOut" |> Task.map (always ()) |