diff options
author | Joris | 2015-08-23 10:54:45 +0200 |
---|---|---|
committer | Joris | 2015-08-23 10:54:45 +0200 |
commit | a2527c34e6b0e719a948cfd36bfee5ffad095a30 (patch) | |
tree | 6431510e87db2bd972952d266ba087793ad263c0 /src/client/Model | |
parent | a4c90e0f66f0db16a0c50c55a4b5cd93d4e8a7fe (diff) |
UI payment delete, not done on server side yet
Diffstat (limited to 'src/client/Model')
-rw-r--r-- | src/client/Model/Payment.elm | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/client/Model/Payment.elm b/src/client/Model/Payment.elm index fa59943..e773be3 100644 --- a/src/client/Model/Payment.elm +++ b/src/client/Model/Payment.elm @@ -2,17 +2,22 @@ module Model.Payment ( Payments , Payment , PaymentId + , PaymentWithId , paymentsDecoder + , addPayment + , removePayment ) where import Date exposing (..) import Json.Decode as Json exposing ((:=)) +import Dict exposing (..) -type alias Payments = List Payment +type alias Payments = Dict PaymentId Payment + +type alias PaymentWithId = (PaymentId, Payment) type alias Payment = - { id : PaymentId - , creation : Date + { creation : Date , name : String , cost : Int , userName : String @@ -21,12 +26,15 @@ type alias Payment = type alias PaymentId = String paymentsDecoder : Json.Decoder Payments -paymentsDecoder = Json.list paymentDecoder +paymentsDecoder = Json.map Dict.fromList (Json.list paymentWithIdDecoder) + +paymentWithIdDecoder : Json.Decoder (PaymentId, Payment) +paymentWithIdDecoder = + paymentDecoder `Json.andThen` (\payment -> Json.map (\id -> (id, payment)) ("id" := Json.string)) paymentDecoder : Json.Decoder Payment paymentDecoder = - Json.object5 Payment - ("id" := paymentIdDecoder) + Json.object4 Payment ("creation" := dateDecoder) ("name" := Json.string) ("cost" := Json.int) @@ -37,3 +45,9 @@ paymentIdDecoder = Json.string dateDecoder : Json.Decoder Date dateDecoder = Json.customDecoder Json.string Date.fromString + +addPayment : Payments -> (PaymentId, Payment) -> Payments +addPayment payments (paymentId, payment) = Dict.insert paymentId payment payments + +removePayment : Payments -> PaymentId -> Payments +removePayment payments paymentId = Dict.remove paymentId payments |