feat(employees): introduce presenters and views for employee data

- Added EmployeeShowPresenter and EmployeeShowView for handling employee details.
- Introduced EmployeesIndexPresenter and EmployeesIndexView for paginated employee listings.
This commit is contained in:
Jérémy Munsch 2026-08-12 16:59:50 +02:00
parent 43a568ef5a
commit 38ca7ed069
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
9 changed files with 23 additions and 14 deletions

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Presentation\Api\V1\Dto\Employees;
use Application\Usecase\Employees\Find\EmployeeShowView;
use Presentation\Api\V1\Contracts\ApiResponseDto;
use Presentation\Api\V1\Presenters\Employees\EmployeeShowView;
final readonly class EmployeeDto implements ApiResponseDto
{

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Presentation\Api\V1\Http\Controllers\Employees;
use Application\Usecase\Employees\Find\EmployeeShowPresenter;
use Application\Usecase\Employees\Find\FindEmployee;
use Illuminate\Http\JsonResponse;
use Presentation\Api\V1\Http\Requests\Employees\EmployeeShowRequest;
use Presentation\Api\V1\Http\Responses\Employees\EmployeeShowResponse;
use Presentation\Api\V1\Presenters\Employees\EmployeeShowPresenter;
use Shared\DDD\Usecase\Builder\UsecaseBuilder;
use Shared\DDD\Usecase\Builder\UsecaseExecutor;
@ -24,7 +24,7 @@ final readonly class EmployeeShowController
public function __invoke(EmployeeShowRequest $request): JsonResponse
{
/** @var \Application\Usecase\Employees\Find\EmployeeShowView $response */
/** @var \Presentation\Api\V1\Presenters\Employees\EmployeeShowView $response */
$response = UsecaseBuilder::using($this->executor)
->do($this->usecase)
->from($request->toInput())

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Presentation\Api\V1\Http\Controllers\Employees;
use Application\Usecase\Employees\FindAll\EmployeesIndexPresenter;
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;
@ -24,7 +24,7 @@ final readonly class EmployeesIndexController
public function __invoke(EmployeesIndexRequest $request): JsonResponse
{
/** @var \Application\Usecase\Employees\FindAll\EmployeesIndexView $response */
/** @var \Presentation\Api\V1\Presenters\Employees\EmployeesIndexView $response */
$response = UsecaseBuilder::using($this->executor)
->do($this->usecase)
->from($request->toInput())

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Presentation\Api\V1\Http\Responses\Employees;
use Application\Usecase\Employees\Find\EmployeeShowView;
use Illuminate\Http\JsonResponse;
use Presentation\Api\V1\Contracts\ApiResponse;
use Presentation\Api\V1\Dto\Employees\EmployeeDto;
use Presentation\Api\V1\Presenters\Employees\EmployeeShowView;
final readonly class EmployeeShowResponse implements ApiResponse
{

View file

@ -4,12 +4,12 @@ declare(strict_types=1);
namespace Presentation\Api\V1\Http\Responses\Employees;
use Application\Usecase\Employees\FindAll\EmployeesIndexView;
use Application\Usecase\Employees\FindAll\PaginatedEmployee;
use Illuminate\Http\JsonResponse;
use League\Uri\Http;
use Presentation\Api\V1\Contracts\ApiResponse;
use Presentation\Api\V1\Dto\Employees\PaginatedEmployee as PaginatedEmployeeDto;
use Presentation\Api\V1\Presenters\Employees\EmployeesIndexView;
final readonly class EmployeesIndexResponse implements ApiResponse
{

View file

@ -2,10 +2,12 @@
declare(strict_types=1);
namespace Application\Usecase\Employees\Find;
namespace Presentation\Api\V1\Presenters\Employees;
use Application\Usecase\Employees\Find\Output;
use Shared\DDD\Usecase\Output as UsecaseOutput;
use Shared\DDD\Usecase\Presenter;
use Webmozart\Assert\Assert;
/** @implements Presenter<\Shared\DDD\Usecase\Output, EmployeeShowView> */
final readonly class EmployeeShowPresenter implements Presenter
@ -13,7 +15,7 @@ final readonly class EmployeeShowPresenter implements Presenter
#[\Override]
public function present(UsecaseOutput $output): object
{
assert($output instanceof Output);
Assert::isInstanceOf($output, Output::class);
return EmployeeShowView::fromOutput($output);
}

View file

@ -2,8 +2,9 @@
declare(strict_types=1);
namespace Application\Usecase\Employees\Find;
namespace Presentation\Api\V1\Presenters\Employees;
use Application\Usecase\Employees\Find\Output;
use Domain\Models\ValueObjects\Entities\ArcadiaEmployeeId;
final readonly class EmployeeShowView

View file

@ -2,10 +2,12 @@
declare(strict_types=1);
namespace Application\Usecase\Employees\FindAll;
namespace Presentation\Api\V1\Presenters\Employees;
use Application\Usecase\Employees\FindAll\Output;
use Shared\DDD\Usecase\Output as UsecaseOutput;
use Shared\DDD\Usecase\Presenter;
use Webmozart\Assert\Assert;
/** @implements Presenter<\Shared\DDD\Usecase\Output, EmployeesIndexView> */
final readonly class EmployeesIndexPresenter implements Presenter
@ -13,7 +15,7 @@ final readonly class EmployeesIndexPresenter implements Presenter
#[\Override]
public function present(UsecaseOutput $output): object
{
assert($output instanceof Output);
Assert::isInstanceOf($output, Output::class);
return EmployeesIndexView::fromOutput($output);
}

View file

@ -2,7 +2,11 @@
declare(strict_types=1);
namespace Application\Usecase\Employees\FindAll;
namespace Presentation\Api\V1\Presenters\Employees;
use Application\Usecase\Employees\FindAll\Output;
use Application\Usecase\Employees\FindAll\PaginatedEmployee;
use Webmozart\Assert\Assert;
final readonly class EmployeesIndexView
{
@ -16,7 +20,7 @@ final readonly class EmployeesIndexView
public int $perPage,
) {
foreach ($this->employees as $employee) {
assert($employee instanceof PaginatedEmployee);
Assert::isInstanceOf($employee, PaginatedEmployee::class);
}
}