This commit is contained in:
@@ -4,7 +4,10 @@ import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
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.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@@ -15,19 +18,17 @@ import org.springframework.stereotype.Service;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
@Override
|
||||
public Employee getEmployeeWithBookings(String code) {
|
||||
if (code == null || code.isEmpty()) {
|
||||
throw new IllegalArgumentException("Employee code cannot be null or empty");
|
||||
}
|
||||
Employee employee = employeeRepository.findByCode(code);
|
||||
if (employee == null) {
|
||||
throw new EmployeeNotFoundException("Employee not found with code: " + code);
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user