works on admin page

This commit is contained in:
2019-11-21 15:57:01 +01:00
parent 75968f73c1
commit a81d184af6
8 changed files with 252 additions and 120 deletions

View File

@@ -6,19 +6,16 @@ module Api exposing
, Item
, Loot
, Msg(..)
, Player
, RequestData(..)
, ToChest(..)
, Update(..)
, Wealth
, blankPlayer
, checkList
, confirmAction
, fetchClaimsOf
, fetchLoot
, fetchPlayer
)
import Api.Player exposing (Player, Wealth)
import Http
import Json.Decode as D exposing (Decoder, field, int, string, succeed)
import Json.Encode as E
@@ -57,29 +54,6 @@ type Msg
-- MODELS
---
-- Player
type alias Player =
{ id : Int
, name : String
, debt : Int
, wealth : Wealth
}
blankPlayer =
Player 0 "Loot-a-lot" 0 (Wealth 0 0 0 0)
type alias Wealth =
{ cp : Int
, sp : Int
, gp : Int
, pp : Int
}
-- Loot
@@ -137,37 +111,6 @@ fetchClaimsOf toMsg playerId =
-- PLAYERS
--
fetchPlayer : (Result Http.Error Player -> msg) -> Int -> Cmd msg
fetchPlayer toMsg id =
Http.get
{ url = "http://localhost:8088/api/players/" ++ String.fromInt id ++ "/"
, expect = Http.expectJson toMsg (valueDecoder playerDecoder)
}
playerDecoder : Decoder Player
playerDecoder =
D.map4 Player
(D.field "id" int)
(D.field "name" string)
(D.field "debt" int)
wealthDecoder
wealthDecoder : Decoder Wealth
wealthDecoder =
D.map4 Wealth
(D.field "cp" int)
(D.field "sp" int)
(D.field "gp" int)
(D.field "pp" int)
-- LOOT
-- Location of a loot
@@ -291,7 +234,7 @@ updatesDecoder =
D.oneOf
[ field "ItemRemoved" (itemDecoder |> D.andThen (\i -> succeed <| ItemRemoved i))
, field "ItemAdded" (itemDecoder |> D.andThen (\i -> succeed <| ItemAdded i))
, field "Wealth" (wealthDecoder |> D.andThen (\i -> succeed <| WealthUpdated i))
, field "Wealth" (Api.Player.wealthDecoder |> D.andThen (\i -> succeed <| WealthUpdated i))
, field "ClaimRemoved" (claimDecoder |> D.andThen (\i -> succeed <| ClaimRemoved i))
, field "ClaimAdded" (claimDecoder |> D.andThen (\i -> succeed <| ClaimAdded i))
]