29 lines
1.1 KiB
Java
29 lines
1.1 KiB
Java
package com.example.nto.service.impl;
|
|
import com.example.nto.entity.Employee;
|
|
import com.example.nto.excepation.EmployeeNotFoundException;
|
|
import com.example.nto.repository.EmployeeRepository;
|
|
import com.example.nto.service.EmployeeService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
/**
|
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
|
* =================================
|
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
*/
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class EmployeeServiceImpl implements EmployeeService {
|
|
@Autowired
|
|
private EmployeeRepository employeeRepository;
|
|
@Override
|
|
public Employee getEmployeeByCode(String code) {
|
|
if (code == null || code.isEmpty()) {
|
|
throw new IllegalArgumentException("Employee code is required");
|
|
}
|
|
return employeeRepository.findByCode(code).orElseThrow(() -> new EmployeeNotFoundException("Employee not found"));
|
|
}
|
|
} |