-
Notifications
You must be signed in to change notification settings - Fork 6
/
Types.hs
38 lines (30 loc) · 926 Bytes
/
Types.hs
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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Api.Types
( Api
, Author(..)
, Book(..)
, BookId
, BookDB
) where
import Data.Aeson (FromJSON, ToJSON)
import qualified Data.Map.Strict as Map
import Elm (ElmType)
import GHC.Generics (Generic)
import Servant ((:<|>), (:>), ReqBody, Post, Get, JSON)
data Author = Author
{ name :: String
, yearOfBirth :: Int
} deriving (Show, Generic, ElmType, ToJSON, FromJSON)
type BookId = String
data Book = Book
{ bookId :: Maybe BookId
, title :: String
, author :: Author
} deriving (Show, Generic, ElmType, ToJSON, FromJSON)
type BookDB = Map.Map BookId Book
type Api = "books" :> ( Get '[JSON] [Book]
:<|> ReqBody '[JSON] Book :> Post '[JSON] Book
)