refactor(presenters): align show presenters on output interface assertions
Replicate EmployeeShowPresenter handling across brand, inco composition and inco sheet presenters by asserting the usecase Output interface and using explicit result matching for found/not-found variants. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
5308320bcb
commit
dc6f8658e6
4 changed files with 76 additions and 52 deletions
|
|
@ -6,29 +6,35 @@ namespace Presentation\Api\V1\Presenters\Brands;
|
|||
|
||||
use Application\Arcadia\Usecase\Brands\Find\NotFoundOutput;
|
||||
use Application\Arcadia\Usecase\Brands\Find\FoundBrandOuput;
|
||||
use Application\Arcadia\Usecase\Brands\Find\Output;
|
||||
use Shared\DDD\Usecase\Output as UsecaseOutput;
|
||||
use Shared\DDD\Usecase\Presenter;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/** @implements Presenter<UsecaseOutput, BrandShowView|BrandNotFoundView> */
|
||||
/** @implements Presenter<\Application\Arcadia\Usecase\Brands\Find\Output, BrandShowView|BrandNotFoundView> */
|
||||
final readonly class BrandShowPresenter implements Presenter
|
||||
{
|
||||
#[\Override]
|
||||
public function present(UsecaseOutput $output): object
|
||||
{
|
||||
if ($output instanceof NotFoundOutput) {
|
||||
return new BrandNotFoundView($output->detail);
|
||||
}
|
||||
|
||||
if (! $output instanceof FoundBrandOuput) {
|
||||
throw new \InvalidArgumentException(sprintf('Unexpected output type "%s".', $output::class));
|
||||
}
|
||||
|
||||
return new BrandShowView(
|
||||
id: $output->id,
|
||||
name: $output->name,
|
||||
code: $output->code,
|
||||
arcadiaId: $output->arcadiaId,
|
||||
createdAt: $output->createdAt,
|
||||
Assert::isAOf(
|
||||
$output,
|
||||
Output::class,
|
||||
);
|
||||
|
||||
return match (true) {
|
||||
$output instanceof NotFoundOutput => new BrandNotFoundView($output->detail),
|
||||
$output instanceof FoundBrandOuput => new BrandShowView(
|
||||
id: $output->id,
|
||||
name: $output->name,
|
||||
code: $output->code,
|
||||
arcadiaId: $output->arcadiaId,
|
||||
createdAt: $output->createdAt,
|
||||
),
|
||||
default => throw new \InvalidArgumentException(sprintf(
|
||||
'Unexpected output type "%s".',
|
||||
$output::class
|
||||
)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,31 +8,37 @@ use Application\Arcadia\Usecase\Employees\Find\NotFoundOutput;
|
|||
use Application\Arcadia\Usecase\Employees\Find\FoundEmployeeOuput;
|
||||
use Shared\DDD\Usecase\Output as UsecaseOutput;
|
||||
use Shared\DDD\Usecase\Presenter;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Application\Arcadia\Usecase\Employees\Find\Output;
|
||||
|
||||
/** @implements Presenter<UsecaseOutput, EmployeeShowView|EmployeeNotFoundView> */
|
||||
/** @implements Presenter<\Application\Arcadia\Usecase\Employees\Find\Output, EmployeeShowView|EmployeeNotFoundView> */
|
||||
final readonly class EmployeeShowPresenter implements Presenter
|
||||
{
|
||||
#[\Override]
|
||||
public function present(UsecaseOutput $output): object
|
||||
{
|
||||
if ($output instanceof NotFoundOutput) {
|
||||
return new EmployeeNotFoundView($output->detail);
|
||||
}
|
||||
|
||||
if (! $output instanceof FoundEmployeeOuput) {
|
||||
throw new \InvalidArgumentException(sprintf('Unexpected output type "%s".', $output::class));
|
||||
}
|
||||
|
||||
return new EmployeeShowView(
|
||||
id: $output->id,
|
||||
firstName: $output->firstName,
|
||||
lastName: $output->lastName,
|
||||
establishment: $output->establishment,
|
||||
site: $output->site,
|
||||
service: $output->service,
|
||||
startDate: $output->startDate,
|
||||
endDate: $output->endDate,
|
||||
plannedEndDate: $output->plannedEndDate,
|
||||
Assert::isAOf(
|
||||
$output,
|
||||
Output::class,
|
||||
);
|
||||
|
||||
return match (true) {
|
||||
$output instanceof NotFoundOutput => new EmployeeNotFoundView($output->detail),
|
||||
$output instanceof FoundEmployeeOuput => new EmployeeShowView(
|
||||
id: $output->id,
|
||||
firstName: $output->firstName,
|
||||
lastName: $output->lastName,
|
||||
establishment: $output->establishment,
|
||||
site: $output->site,
|
||||
service: $output->service,
|
||||
startDate: $output->startDate,
|
||||
endDate: $output->endDate,
|
||||
plannedEndDate: $output->plannedEndDate,
|
||||
),
|
||||
default => throw new \InvalidArgumentException(sprintf(
|
||||
'Unexpected output type "%s".',
|
||||
$output::class
|
||||
)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,23 +6,29 @@ namespace Presentation\Api\V1\Presenters\IncoCompositions;
|
|||
|
||||
use Application\Arcadia\Usecase\IncoCompositions\Find\NotFoundOutput;
|
||||
use Application\Arcadia\Usecase\IncoCompositions\Find\FoundIncoCompositionOuput;
|
||||
use Application\Arcadia\Usecase\IncoCompositions\Find\Output;
|
||||
use Shared\DDD\Usecase\Output as UsecaseOutput;
|
||||
use Shared\DDD\Usecase\Presenter;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/** @implements Presenter<UsecaseOutput, IncoCompositionShowView|IncoCompositionNotFoundView> */
|
||||
/** @implements Presenter<\Application\Arcadia\Usecase\IncoCompositions\Find\Output, IncoCompositionShowView|IncoCompositionNotFoundView> */
|
||||
final readonly class IncoCompositionShowPresenter implements Presenter
|
||||
{
|
||||
#[\Override]
|
||||
public function present(UsecaseOutput $output): object
|
||||
{
|
||||
if ($output instanceof NotFoundOutput) {
|
||||
return new IncoCompositionNotFoundView($output->detail);
|
||||
}
|
||||
Assert::isAOf(
|
||||
$output,
|
||||
Output::class,
|
||||
);
|
||||
|
||||
if (! $output instanceof FoundIncoCompositionOuput) {
|
||||
throw new \InvalidArgumentException(sprintf('Unexpected output type "%s".', $output::class));
|
||||
}
|
||||
|
||||
return new IncoCompositionShowView($output);
|
||||
return match (true) {
|
||||
$output instanceof NotFoundOutput => new IncoCompositionNotFoundView($output->detail),
|
||||
$output instanceof FoundIncoCompositionOuput => new IncoCompositionShowView($output),
|
||||
default => throw new \InvalidArgumentException(sprintf(
|
||||
'Unexpected output type "%s".',
|
||||
$output::class
|
||||
)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,23 +6,29 @@ namespace Presentation\Api\V1\Presenters\IncoSheets;
|
|||
|
||||
use Application\Arcadia\Usecase\IncoSheets\Find\NotFoundOutput;
|
||||
use Application\Arcadia\Usecase\IncoSheets\Find\FoundIncoSheetOuput;
|
||||
use Application\Arcadia\Usecase\IncoSheets\Find\Output;
|
||||
use Shared\DDD\Usecase\Output as UsecaseOutput;
|
||||
use Shared\DDD\Usecase\Presenter;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/** @implements Presenter<UsecaseOutput, IncoSheetsShowView|IncoSheetsNotFoundView> */
|
||||
/** @implements Presenter<\Application\Arcadia\Usecase\IncoSheets\Find\Output, IncoSheetsShowView|IncoSheetsNotFoundView> */
|
||||
final readonly class IncoSheetsShowPresenter implements Presenter
|
||||
{
|
||||
#[\Override]
|
||||
public function present(UsecaseOutput $output): object
|
||||
{
|
||||
if ($output instanceof NotFoundOutput) {
|
||||
return new IncoSheetsNotFoundView($output->detail);
|
||||
}
|
||||
Assert::isAOf(
|
||||
$output,
|
||||
Output::class,
|
||||
);
|
||||
|
||||
if (! $output instanceof FoundIncoSheetOuput) {
|
||||
throw new \InvalidArgumentException(sprintf('Unexpected output type "%s".', $output::class));
|
||||
}
|
||||
|
||||
return new IncoSheetsShowView($output);
|
||||
return match (true) {
|
||||
$output instanceof NotFoundOutput => new IncoSheetsNotFoundView($output->detail),
|
||||
$output instanceof FoundIncoSheetOuput => new IncoSheetsShowView($output),
|
||||
default => throw new \InvalidArgumentException(sprintf(
|
||||
'Unexpected output type "%s".',
|
||||
$output::class
|
||||
)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue