store number of games in database
This commit is contained in:
parent
d491a30ea7
commit
baadb5ae54
|
@ -12,6 +12,7 @@ module Mtlstats.Types (
|
||||||
-- ** Database Lenses
|
-- ** Database Lenses
|
||||||
dbPlayers,
|
dbPlayers,
|
||||||
dbGoalies,
|
dbGoalies,
|
||||||
|
dbGames,
|
||||||
-- ** Player Lenses
|
-- ** Player Lenses
|
||||||
pNumber,
|
pNumber,
|
||||||
pName,
|
pName,
|
||||||
|
@ -69,21 +70,26 @@ data Database = Database
|
||||||
-- ^ The list of players
|
-- ^ The list of players
|
||||||
, _dbGoalies :: [Goalie]
|
, _dbGoalies :: [Goalie]
|
||||||
-- ^ The lidt of goalies
|
-- ^ The lidt of goalies
|
||||||
|
, _dbGames :: Int
|
||||||
|
-- ^ The number of games recorded
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
instance FromJSON Database where
|
instance FromJSON Database where
|
||||||
parseJSON = withObject "Database" $ \v -> Database
|
parseJSON = withObject "Database" $ \v -> Database
|
||||||
<$> v .: "players"
|
<$> v .: "players"
|
||||||
<*> v .: "goalies"
|
<*> v .: "goalies"
|
||||||
|
<*> v .: "games"
|
||||||
|
|
||||||
instance ToJSON Database where
|
instance ToJSON Database where
|
||||||
toJSON (Database ps gs) = object
|
toJSON (Database players goalies games) = object
|
||||||
[ "players" .= ps
|
[ "players" .= players
|
||||||
, "goalies" .= gs
|
, "goalies" .= goalies
|
||||||
|
, "games" .= games
|
||||||
]
|
]
|
||||||
toEncoding (Database ps gs) = pairs $
|
toEncoding (Database players goalies games) = pairs $
|
||||||
"players" .= ps <>
|
"players" .= players <>
|
||||||
"goalies" .= gs
|
"goalies" .= goalies <>
|
||||||
|
"games" .= games
|
||||||
|
|
||||||
-- | Represents a (non-goalie) player
|
-- | Represents a (non-goalie) player
|
||||||
data Player = Player
|
data Player = Player
|
||||||
|
@ -239,6 +245,7 @@ newDatabase :: Database
|
||||||
newDatabase = Database
|
newDatabase = Database
|
||||||
{ _dbPlayers = []
|
{ _dbPlayers = []
|
||||||
, _dbGoalies = []
|
, _dbGoalies = []
|
||||||
|
, _dbGames = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Constructor for a 'Player'
|
-- | Constructor for a 'Player'
|
||||||
|
|
|
@ -97,6 +97,7 @@ db :: Database
|
||||||
db = newDatabase
|
db = newDatabase
|
||||||
& dbPlayers .~ [player]
|
& dbPlayers .~ [player]
|
||||||
& dbGoalies .~ [goalie]
|
& dbGoalies .~ [goalie]
|
||||||
|
& dbGames .~ 1
|
||||||
|
|
||||||
playerJSON :: ByteString
|
playerJSON :: ByteString
|
||||||
playerJSON = [r|
|
playerJSON = [r|
|
||||||
|
@ -145,4 +146,5 @@ dbJSON = [r|
|
||||||
[ |] <> playerJSON <> [r| ]
|
[ |] <> playerJSON <> [r| ]
|
||||||
, "goalies":
|
, "goalies":
|
||||||
[ |] <> goalieJSON <> [r| ]
|
[ |] <> goalieJSON <> [r| ]
|
||||||
|
, "games": 1
|
||||||
}|]
|
}|]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user