From 3b738e0d4cc65f314da7389d4542ec826ba0f454 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 5 Sep 2015 13:53:36 +0200 Subject: Using UserId instead of UserName to indentify users --- src/client/Model/Payers.elm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/client/Model/Payers.elm') diff --git a/src/client/Model/Payers.elm b/src/client/Model/Payers.elm index 6550eaa..983e7b3 100644 --- a/src/client/Model/Payers.elm +++ b/src/client/Model/Payers.elm @@ -11,21 +11,23 @@ import Dict exposing (..) import List import Maybe -type alias Payers = Dict String Int +import Model.User exposing (UserId, userIdDecoder) + +type alias Payers = Dict UserId Int payersDecoder : Decoder Payers payersDecoder = Json.map Dict.fromList (list payerDecoder) -payerDecoder : Decoder (String, Int) +payerDecoder : Decoder (UserId, Int) payerDecoder = object2 (,) - ("userName" := string) + ("userId" := userIdDecoder) ("totalPayment" := int) -updatePayers : Payers -> String -> Int -> Payers -updatePayers payers userName amountDiff = +updatePayers : Payers -> UserId -> Int -> Payers +updatePayers payers userId amountDiff = Dict.update - userName + userId (\mbAmount -> case mbAmount of Just amount -> Just (amount + amountDiff) @@ -34,7 +36,7 @@ updatePayers payers userName amountDiff = payers type alias ExceedingPayer = - { userName : String + { userId : UserId , amount : Int } @@ -42,7 +44,7 @@ getOrderedExceedingPayers : Payers -> List ExceedingPayer getOrderedExceedingPayers payers = let orderedPayers = Dict.toList payers - |> List.map (\(userName, amount) -> ExceedingPayer userName amount) + |> List.map (\(userId, amount) -> ExceedingPayer userId amount) |> List.sortBy .amount maybeMinAmount = List.head orderedPayers -- cgit v1.2.3