module Snap.App.Types
(Controller(..)
,Model(..)
,ControllerState(..)
,ModelState(..)
,AppConfig(..)
,AppLiftModel(..))
where
import Control.Applicative (Applicative,Alternative)
import Control.Monad (MonadPlus)
import Control.Monad.Catch (MonadCatchIO)
import Control.Monad.Reader (ReaderT,MonadReader)
import Control.Monad.Trans (MonadIO)
import Database.PostgreSQL.Simple (Connection)
import Snap.Core (Snap,MonadSnap)
data ControllerState config state = ControllerState {
controllerStateConfig :: config
, controllerStateConn :: Connection
, controllerState :: state
}
newtype Controller config state a = Controller {
runController :: ReaderT (ControllerState config state) Snap a
} deriving (Monad
,Functor
,Applicative
,Alternative
,MonadReader (ControllerState config state)
,MonadSnap
,MonadIO
,MonadPlus
,MonadCatchIO)
data ModelState config state = ModelState {
modelStateConn :: Connection
, modelStateAnns :: state
, modelStateConfig :: config
}
newtype Model config state a = Model {
runModel :: ReaderT (ModelState config state) IO a
} deriving (Monad,Functor,Applicative,MonadReader (ModelState config state),MonadIO)
class AppConfig config where
getConfigDomain :: config -> String
class AppLiftModel c s where
liftModel :: Model c s a -> Controller c s a