ldc-arcadia-api/src/Presentation/Api/V1/Http/Controllers/Employees/EmployeesIndexController.php

37 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Presentation\Api\V1\Http\Controllers\Employees;
use Application\Usecase\Employees\FindAll\FindAllEmployees;
use Illuminate\Http\JsonResponse;
use Presentation\Api\V1\Http\Requests\Employees\EmployeesIndexRequest;
use Presentation\Api\V1\Http\Responses\Employees\EmployeesIndexResponse;
use Presentation\Api\V1\Presenters\Employees\EmployeesIndexPresenter;
use Shared\DDD\Usecase\Builder\UsecaseBuilder;
use Shared\DDD\Usecase\Builder\UsecaseExecutor;
final readonly class EmployeesIndexController
{
/** @param UsecaseExecutor<\Shared\DDD\Usecase\Input, \Shared\DDD\Usecase\Output> $executor */
public function __construct(
private FindAllEmployees $usecase,
private UsecaseExecutor $executor,
private EmployeesIndexPresenter $presenter,
) {
}
public function __invoke(EmployeesIndexRequest $request): JsonResponse
{
/** @var \Presentation\Api\V1\Presenters\Employees\EmployeesIndexView $response */
$response = UsecaseBuilder::using($this->executor)
->do($this->usecase)
->from($request->toInput())
->with($this->presenter)
->run();
return (new EmployeesIndexResponse($response, $request->toLeagueUri()))->present();
}
}