43 lines
1.3 KiB
Java
43 lines
1.3 KiB
Java
package com.example.nto.service.impl;
|
|
|
|
import com.example.nto.entity.Employee;
|
|
import com.example.nto.repository.EmployeeRepository;
|
|
import com.example.nto.service.EmployeeService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
|
* =================================
|
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
*/
|
|
@Component
|
|
@Service
|
|
public class EmployeeServiceImpl implements EmployeeService {
|
|
private final EmployeeRepository employeeRepository;
|
|
|
|
@Autowired
|
|
public EmployeeServiceImpl(EmployeeRepository employeeRepository) {
|
|
this.employeeRepository = employeeRepository;
|
|
}
|
|
|
|
@Override
|
|
public List<Employee> getAll() {
|
|
return employeeRepository.findAll();
|
|
}
|
|
|
|
@Override
|
|
public Optional<Employee> getById(long id) {
|
|
return employeeRepository.findById(id);
|
|
}
|
|
|
|
public boolean isIdValid(long id){
|
|
return employeeRepository.findById(id).isPresent();
|
|
}
|
|
}
|