- Add ImportEmployees Action and ImportEmployeesInput - Add GetEmployeeImportColumnsQuery - Encapsulate toImportEmployeesInput in ImportRequest - Use Executor in Bo\EmployeesController - Add feature tests for Bo\EmployeesController
37 lines
1,014 B
PHP
37 lines
1,014 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Employees;
|
|
|
|
use App\Contracts\Action;
|
|
use App\Contracts\ActionInput;
|
|
use Domain\Services\EmployeeImportService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Action<\App\Actions\Employees\ImportEmployeesInput, \App\Actions\Employees\ImportEmployeesOutput>
|
|
*/
|
|
final class ImportEmployees implements Action
|
|
{
|
|
public function __construct(
|
|
private readonly EmployeeImportService $employeeService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Actions\Employees\ImportEmployeesInput $input
|
|
*/
|
|
public function __invoke(ActionInput $input): ImportEmployeesOutput
|
|
{
|
|
Assert::isInstanceOf($input, ImportEmployeesInput::class);
|
|
|
|
$importResults = $this->employeeService->import($input->file);
|
|
|
|
return new ImportEmployeesOutput(
|
|
insertedCount: $importResults->insertedCount,
|
|
updatedCount: $importResults->updatedCount,
|
|
errors: $importResults->errors,
|
|
);
|
|
}
|
|
}
|