From 294c8e19b136f06ca7fa1bb4e4d109e90e2bb033 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 23 Nov 2019 16:38:47 -0800 Subject: Add Com.MusicMeetsComics --- Com/MusicMeetsComics/Database.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Com/MusicMeetsComics/Database.hs (limited to 'Com/MusicMeetsComics/Database.hs') 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 -- cgit v1.2.3