aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Server.elm
diff options
context:
space:
mode:
authorJoris2016-06-26 12:31:24 +0200
committerJoris2016-06-26 12:31:24 +0200
commit9ec84e3a20c767f6525639f58cd22715e302b88d (patch)
treea080552859180707472c1a289080857c0a54fc06 /src/client/elm/Server.elm
parent5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff)
downloadbudget-9ec84e3a20c767f6525639f58cd22715e302b88d.tar.gz
budget-9ec84e3a20c767f6525639f58cd22715e302b88d.tar.bz2
budget-9ec84e3a20c767f6525639f58cd22715e302b88d.zip
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r--src/client/elm/Server.elm28
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