30 lines
1.1 KiB
Haskell
30 lines
1.1 KiB
Haskell
module Handlers where
|
|
|
|
import Core
|
|
import Database
|
|
|
|
import qualified Data.ByteString.Char8 as C
|
|
import Data.List
|
|
import qualified Data.Text as T
|
|
import Effectful
|
|
import Effectful.Error.Static (Error, throwError)
|
|
import Effectful.FileSystem
|
|
import Effectful.FileSystem.IO.ByteString as EBS
|
|
import Servant hiding ((:>), throwError)
|
|
import qualified Servant as S
|
|
|
|
rootHandler :: (Error ServerError :> es) => Eff es T.Text
|
|
rootHandler = return "Hello, World!"
|
|
|
|
userListHandler :: (Database :> es, Error ServerError :> es, FileSystem :> es) => Eff es [User]
|
|
userListHandler = mapM userGetHandler [1, 2, 3]
|
|
|
|
userGetHandler :: (Database :> es, Error ServerError :> es, FileSystem :> es) => Int -> Eff es User
|
|
userGetHandler userId = databaseRead (queryUser userId) >>= \mUser ->
|
|
case mUser of
|
|
Just a -> pure a
|
|
Nothing -> pure (User 0 "No user found")
|
|
|
|
userPostHandler :: (Database :> es, Error ServerError :> es, FileSystem :> es) => String -> Eff es NoContent
|
|
userPostHandler name = databaseWrite (writeUser name) >>= \_ -> return NoContent
|