summaryrefslogtreecommitdiff
path: root/Com/MusicMeetsComics/Database.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Com/MusicMeetsComics/Database.hs')
-rw-r--r--Com/MusicMeetsComics/Database.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/Com/MusicMeetsComics/Database.hs b/Com/MusicMeetsComics/Database.hs
new file mode 100644
index 0000000..8178e9a
--- /dev/null
+++ b/Com/MusicMeetsComics/Database.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE OverloadedStrings #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Com.MusicMeetsComics.Database
+ (
+ ComicDB
+ , getComics
+ , load
+ ) where
+
+import Com.MusicMeetsComics.App
+import Data.Map ( Map )
+import qualified Data.Map as Map
+import Dhall
+import Protolude
+import Servant ( Handler )
+
+type ComicDB = (Map ComicId Comic)
+
+instance Interpret Comic
+
+load :: IO ComicDB
+load = listToComicDB <$> input auto "./comic-database.dhall"
+
+listToComicDB :: [Comic] -> ComicDB
+listToComicDB ls = Map.fromList $ (,) <$> comicId <*> identity <$> ls
+
+getComics :: ComicDB -> Handler [Comic]
+getComics db = return $ Map.elems db