diff options
author | Ben Sima <ben@bsima.me> | 2019-11-23 16:38:47 -0800 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-11-23 16:45:05 -0800 |
commit | 294c8e19b136f06ca7fa1bb4e4d109e90e2bb033 (patch) | |
tree | d8f56bdfc0451f9ad33e4ae396204bd0ba171d4d /Com/MusicMeetsComics/Database.hs | |
parent | eb7e442d930bda88aac3c6aad0825b5aa4173e5e (diff) |
Add Com.MusicMeetsComics
Diffstat (limited to 'Com/MusicMeetsComics/Database.hs')
-rw-r--r-- | Com/MusicMeetsComics/Database.hs | 30 |
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 |