Search in sources :

Example 1 with Role

use of com.plumdo.identity.domain.Role in project plumdo-work by wengwh.

the class RoleResource method saveRoleAndMenu.

private Role saveRoleAndMenu(Role role, ObjectMap roleRequest) {
    if (role == null) {
        role = new Role();
    }
    role.setName(roleRequest.getAsString("name"));
    role.setRemark(roleRequest.getAsString("remark"));
    role.setTenantId(roleRequest.getAsString("tenantId"));
    roleRepository.save(role);
    roleMenuRepository.deleteByRoleId(role.getId());
    List<ObjectMap> menus = roleRequest.getAsList("roleMenus");
    for (ObjectMap menu : menus) {
        RoleMenu roleMenu = new RoleMenu();
        roleMenu.setMenuId(menu.getAsInteger("id"));
        roleMenu.setRoleId(role.getId());
        roleMenuRepository.save(roleMenu);
    }
    return role;
}
Also used : Role(com.plumdo.identity.domain.Role) ObjectMap(com.plumdo.common.model.ObjectMap) RoleMenu(com.plumdo.identity.domain.RoleMenu)

Example 2 with Role

use of com.plumdo.identity.domain.Role in project plumdo-work by wengwh.

the class RoleResource method deleteRole.

@DeleteMapping(value = "/roles/{id}")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@Transactional
public void deleteRole(@PathVariable Integer id) {
    Role role = getRoleFromRequest(id);
    roleRepository.delete(role);
    roleMenuRepository.deleteByRoleId(role.getId());
}
Also used : Role(com.plumdo.identity.domain.Role) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Role (com.plumdo.identity.domain.Role)2 ObjectMap (com.plumdo.common.model.ObjectMap)1 RoleMenu (com.plumdo.identity.domain.RoleMenu)1 Transactional (org.springframework.transaction.annotation.Transactional)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1