package cn.edu.whu.boot.user.services.impl;

import cn.edu.whu.boot.user.entities.RoleToPermission;
import cn.edu.whu.boot.user.mapper.RoleToPermissionMapper;
import cn.edu.whu.boot.user.services.RoleToPermissionService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RoleToPermissionServiceImpl implements RoleToPermissionService {
    private final RoleToPermissionMapper roleToPermissionMapper;

    public RoleToPermissionServiceImpl(RoleToPermissionMapper roleToPermissionMapper) {
        this.roleToPermissionMapper = roleToPermissionMapper;
    }

    @Override
    public List<Integer> findByRole(int roleId) {
        return roleToPermissionMapper
                .findByRole(roleId)
                .stream()
                .map(RoleToPermission::getPermission)
                .collect(Collectors.toList());
    }
}

