summaryrefslogtreecommitdiff
path: root/Hero/Database.hs
blob: 0166c6f02e2def9ef7ea9822827c230657d71082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Hero.Database
  ( ComicDB,
    getComics,
    load,
    dummy,
  )
where

import Data.Map (Map)
import qualified Data.Map as Map
import Dhall
import Hero.App
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