{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Com.MusicMeetsComics.Database ( ComicDB , getComics , load , dummy ) 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" dummy :: IO ComicDB dummy = return $ listToComicDB [ Comic { comicId = "ComicId" , comicPages = 10 , comicName = "Dummy comic" , comicIssue = "dummy issue" , comicDescription = "Lorem ipsum" } ] listToComicDB :: [Comic] -> ComicDB listToComicDB ls = Map.fromList $ (,) <$> comicId <*> identity <$> ls getComics :: ComicDB -> Handler [Comic] getComics db = return $ Map.elems db