From 8cd63a64abafe21378c35c2489d49f24c9ece3c9 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 4 Apr 2016 01:27:36 +0200 Subject: Add income list CRUD in user page --- src/client/elm/Server.elm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/client/elm/Server.elm') diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm index be052bb..36adb33 100644 --- a/src/client/elm/Server.elm +++ b/src/client/elm/Server.elm @@ -2,7 +2,8 @@ module Server ( signIn , addPayment , deletePayment - , setIncome + , addIncome + , deleteIncome , signOut ) where @@ -10,7 +11,7 @@ import Signal import Task as Task exposing (Task) import Http import Json.Decode as Json exposing ((:=)) -import Date +import Date exposing (Date) import Utils.Http exposing (..) @@ -29,16 +30,21 @@ addPayment name cost frequency = post ("/api/payment/add?name=" ++ name ++ "&cost=" ++ cost ++ "&frequency=" ++ (toString frequency)) |> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder) -deletePayment : Payment -> Frequency -> Task Http.Error () -deletePayment payment frequency = - post ("/api/payment/delete?id=" ++ (toString payment.id)) +deletePayment : PaymentId -> Task Http.Error () +deletePayment paymentId = + delete ("/api/payment/delete?id=" ++ (toString paymentId)) |> Task.map (always ()) -setIncome : Int -> Task Http.Error IncomeId -setIncome amount = - post ("/api/income?amount=" ++ (toString amount)) +addIncome : Date -> Int -> Task Http.Error IncomeId +addIncome creation amount = + post ("/api/income?creation=" ++ (toString << Date.toTime <| creation) ++ "&amount=" ++ (toString amount)) |> flip Task.andThen (decodeHttpValue <| "id" := incomeIdDecoder) +deleteIncome : IncomeId -> Task Http.Error () +deleteIncome incomeId = + delete ("/api/income/delete?id=" ++ (toString incomeId)) + |> Task.map (always ()) + signOut : Task Http.Error () signOut = post "/api/signOut" -- cgit v1.2.3