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

import cn.edu.whu.boot.user.entities.Role;
import cn.edu.whu.boot.user.mapper.RoleMapper;
import cn.edu.whu.boot.user.services.RoleService;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class RoleServiceImpl implements RoleService {


    private final RoleMapper roleMapper;

    public RoleServiceImpl(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }


    @Override
    public Optional<Role> findRoleByName(String name) {
        return Optional.ofNullable(roleMapper.findByName(name));
    }

    @Override
    public Optional<Role> findById(int id) {
        return Optional.ofNullable(roleMapper.findById(id));
    }

    @Override
    public Optional<Role> findByCode(int code) {
        return Optional.ofNullable(roleMapper.findByCode(code));
    }
}
