package ru.ldeloff.hedgehogcloud.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import ru.ldeloff.hedgehogcloud.entity.RoleEntity;
import ru.ldeloff.hedgehogcloud.entity.UserEntity;
import ru.ldeloff.hedgehogcloud.repository.RoleRepository;

@Service
public class RoleServiceImpl implements RoleService {
    RoleRepository roleRepository;

    public RoleServiceImpl(RoleRepository roleRepository) {
        this.roleRepository = roleRepository;
    }


    public void saveRole(RoleEntity role) {
        RoleEntity roleTemp = getByName(role.getName());
        if (roleTemp == null) {
            roleRepository.save(role);
        }
    }

    @Override
    public RoleEntity getByName(String name) {
        return roleRepository.findByName(name);
    }

}
