summaryrefslogtreecommitdiff
path: root/Hero/Keep.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Hero/Keep.hs')
-rw-r--r--Hero/Keep.hs39
1 files changed, 31 insertions, 8 deletions
diff --git a/Hero/Keep.hs b/Hero/Keep.hs
index 9ac46fa..ee625d8 100644
--- a/Hero/Keep.hs
+++ b/Hero/Keep.hs
@@ -6,11 +6,12 @@
module Hero.Keep
( HeroKeep,
- GetComics(..),
+ GetComics (..),
getComics,
- NewComic(..),
+ NewComic (..),
newComic,
- openLocal,
+ open,
+ close,
)
where
@@ -27,9 +28,11 @@ import Hero.App
-- * Keep
-- | Main database.
-newtype HeroKeep
+data HeroKeep
= HeroKeep
- {_comics :: (IxSet Comic)}
+ { _comics :: (IxSet Comic),
+ _users :: (IxSet User)
+ }
deriving (Data, Typeable)
$(deriveSafeCopy 0 'base ''HeroKeep)
@@ -38,6 +41,8 @@ $(deriveSafeCopy 0 'base ''HeroKeep)
$(deriveSafeCopy 0 'base ''Comic)
+$(deriveSafeCopy 0 'base ''User)
+
$(deriveSafeCopy 0 'base ''ComicId)
instance Indexable Comic where
@@ -50,6 +55,14 @@ instance Indexable Comic where
ixFun $ \c -> [comicDescription c]
]
+instance Indexable User where
+ empty =
+ ixSet
+ [ ixFun $ \u -> [userEmail u],
+ ixFun $ \u -> [userName u],
+ ixFun $ \u -> [userLibrary u]
+ ]
+
newComic :: Comic -> Update HeroKeep Comic
newComic c = do
keep <- get
@@ -64,7 +77,14 @@ getComics n = ask /> _comics /> IxSet.toList /> take n
$(makeAcidic ''HeroKeep ['newComic, 'getComics])
initialHeroKeep :: HeroKeep
-initialHeroKeep = HeroKeep {_comics = IxSet.fromList [theRed] }
+initialHeroKeep =
+ HeroKeep
+ { _comics = IxSet.fromList [theRed],
+ _users = IxSet.fromList
+ [ User "a" "micheal" [],
+ User "b" "ben" []
+ ]
+ }
where
theRed =
Comic
@@ -82,5 +102,8 @@ initialHeroKeep = HeroKeep {_comics = IxSet.fromList [theRed] }
]
}
-openLocal :: String -> IO (Acid.AcidState HeroKeep)
-openLocal dir = Acid.openLocalStateFrom dir initialHeroKeep
+open :: String -> IO (Acid.AcidState HeroKeep)
+open dir = Acid.openLocalStateFrom dir initialHeroKeep
+
+close :: Acid.AcidState HeroKeep -> IO ()
+close = Acid.closeAcidState