make associations

This commit is contained in:
nek0 2020-07-19 12:58:25 +02:00
parent 8303d8688a
commit 28063cfffe
3 changed files with 25 additions and 5 deletions

View file

@ -27,7 +27,10 @@ roleUpdate _ _ = notImplemented
roleDelete _ _ = notImplemented
roleAssociationList = notImplemented
roleAssociationList
:: MateHandler [RoleAssociation]
roleAssociationList =
selectAllRoleAssociations =<< asks rsConnection
roleAssociationSubmit _ _ = notImplemented

View file

@ -46,8 +46,8 @@ initRole = mconcat
initUserToRole :: PGS.Query
initUserToRole = mconcat
[ "CREATE TABLE IF NOT EXISTS \"user_to_role\" ("
, "user_id INTEGER NOT NULL,"
, "role_id INTEGER NOT NULL,"
, "user_id INTEGER NOT NULL REFERENCES \"user\"(\"user_id\"),"
, "role_id INTEGER NOT NULL REFERENCES \"role\"(\"role_id\"),"
, "PRIMARY KEY (user_id, role_id)"
, ")"
]
@ -261,6 +261,24 @@ queryRoleIdByCapabilities (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) conn =
]
return $ (\(rid, _, _, _, _, _, _, _, _, _, _, _, _) -> rid) (head roles)
selectAllRoleAssociations
:: PGS.Connection
-> MateHandler [RoleAssociation]
selectAllRoleAssociations conn = do
rawRoleAssocs <- liftIO $ runSelect conn (
queryTable userToRoleTable
) :: MateHandler
[
( Int
, Int
)
]
return $ map
(\(uid, rid) -> RoleAssociation uid rid)
rawRoleAssocs
associateUserToRole
:: Int -- ^ User id
-> Int -- ^ Role id

View file

@ -50,8 +50,7 @@ instance ToJSON RoleSubmit where
instance FromJSON RoleSubmit
data RoleAssociation = RoleAssociation
{ roleAssociationId :: Int
, roleAssociationUser :: Int
{ roleAssociationUser :: Int
, roleAssociationRole :: Int
}
deriving (Generic, Show)