mateamt/src/Control/Role.hs

61 lines
1.3 KiB
Haskell
Raw Normal View History

2020-07-19 06:27:15 +00:00
{-# LANGUAGE OverloadedStrings #-}
module Control.Role where
import Servant
import Control.Monad (void, when)
import Control.Monad.Reader (asks)
import Control.Monad.IO.Class (liftIO)
import qualified Data.Text as T
-- internal imports
import Types
import Model
roleList :: MateHandler [Role]
roleList = do
conn <- asks rsConnection
selectAllRoles conn
2020-07-19 18:48:58 +00:00
roleNew
:: Maybe (Int, AuthMethod)
-> RoleSubmit
-> MateHandler Int
roleNew (Just (_, auth)) (RoleSubmit name c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11) =
insertRole name c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 =<< asks rsConnection
2020-07-23 20:41:22 +00:00
roleNew Nothing _ ->
throwError $ err401
{ errBody = "No Authentication present."
}
2020-07-19 06:27:15 +00:00
2020-07-23 20:41:22 +00:00
roleUpdate
:: Maybe (Int, AuthMethod)
-> Role
-> MateHandler ()
roleUpdate Just (_, auth) role =
updateRole role =<< asks rsConnection
roleUpdate Nothing _ ->
throwError $ err401
{ errBody = "No Authentication present."
}
2020-07-19 06:27:15 +00:00
2020-07-19 10:27:28 +00:00
roleDelete _ _ = notImplemented
2020-07-19 06:27:15 +00:00
2020-07-19 10:58:25 +00:00
roleAssociationList
:: MateHandler [RoleAssociation]
roleAssociationList =
selectAllRoleAssociations =<< asks rsConnection
2020-07-19 06:27:15 +00:00
2020-07-19 10:27:28 +00:00
roleAssociationSubmit _ _ = notImplemented
2020-07-19 06:27:15 +00:00
2020-07-19 10:27:28 +00:00
roleAssociationDelete _ _ = notImplemented
2020-07-19 06:27:15 +00:00
2020-07-19 10:27:28 +00:00
notImplemented :: MateHandler a
2020-07-19 06:27:15 +00:00
notImplemented = throwError $ err501
{ errBody = "Function has not yet been implemented!"
}