createApi improvements

This commit is contained in:
Flo 2024-02-24 20:31:55 +01:00
parent 3cb5eaa4d9
commit 27be2c79dd
12 changed files with 195 additions and 1 deletions

View File

@ -110,7 +110,7 @@ return [
{$apiHandlerName}::class => AutoWiringFactory::class, {$apiHandlerName}::class => AutoWiringFactory::class,
// Response Formatter // Response Formatter
{$$apiResponseFormatterName}::class => AutoWiringFactory::class, {$apiResponseFormatterName}::class => AutoWiringFactory::class,
], ],
]; ];
"; ";

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use MyTube\API\External\TagList\Handler\ReadListHandler;
return [
[
'name' => 'TODO.TODO',
'path' => '/api/TODO/TODO[/]',
'allowed_methods' => ['POST'],
'middleware' => [
ReadListHandler::class,
],
],
];

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
use MyTube\API\External\TagList\Handler\ReadListHandler;
use MyTube\API\External\TagList\ResponseFormatter\ReadListResponseFormatter;
use Reinfi\DependencyInjection\Factory\AutoWiringFactory;
return [
'factories' => [
// Handler
ReadListHandler::class => AutoWiringFactory::class,
// Response Formatter
::class => AutoWiringFactory::class,
],
];

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace MyTube\API\{External}\{TagList};
class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => require __DIR__ . './../config/service_manager.php',
'routes' => require __DIR__ . '/./../config/routes.php',
];
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace MyTube\API\External\TagList\Handler;
use MyTube\Handling\TagList\Handler\Query\ReadList\ReadListQueryHandler;
use MyTube\Handling\TagList\Handler\Query\ReadList\ReadListQueryBuilder;
use MyTube\API\External\TagList\ResponseFormatter\ReadListResponseFormatter;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use MyTube\Infrastructure\Response\SuccessResponse;
class ReadListHandler implements RequestHandlerInterface
{
public function __construct(
private readonly ReadListQueryHandler $readListQueryHandler,
private readonly ReadListQueryBuilder $readListQueryBuilder,
private readonly ReadListResponseFormatter $responseFormatter,
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$data = json_decode(
$request->getBody()->getContents(),
true
);
$readListQuery = $this->readListQueryBuilder->build(
$data
);
$result = $this->readListQueryHandler->execute($readListQuery);
return new SuccessResponse($this->responseFormatter->format($result));
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace MyTube\API\External\TagList\ResponseFormatter;
use MyTube\Handling\TagList\Handler\Query\ReadList\ReadListQueryResult;
class ReadListResponseFormatter
{
public function format(ReadListQueryResult $readListQueryResult): array
{
return [];
}
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
use MyTube\Handling\TagList\Handler\Query\ReadList\ReadListQueryHandler;
use MyTube\Handling\TagList\Handler\Query\ReadList\ReadListQueryBuilder;
use Reinfi\DependencyInjection\Factory\AutoWiringFactory;
use Reinfi\DependencyInjection\Factory\InjectionFactory;
return [
'factories' => [
/// CQRS
// ReadList
ReadListQueryBuilder::class => AutoWiringFactory::class,
ReadListQueryHandler::class => AutoWiringFactory::class,
],
];

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace MyTube\Handling\{MyTube\Handling\TagList\Handler\Query\ReadList};
class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => require __DIR__ . './../config/service_manager.php',
];
}
}

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace MyTube\Handling\TagList\Handler\Query\ReadList;
class ReadListQuery
{
public function __construct(
#TODO
) {
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace MyTube\Handling\TagList\Handler\Query\ReadList;
class ReadListQueryBuilder
{
public function build(
#TODO
): ReadListQuery {
return new ReadListQuery(
#TODO
);
}
}

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace MyTube\Handling\TagList\Handler\Query\ReadList;
class ReadListQueryHandler
{
public function __construct(
#TODO
) {
}
public function execute(ReadListQuery $readListQuery): ReadListQueryResult
{
return new ReadListQueryResult();
}
}

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace MyTube\Handling\TagList\Handler\Query\ReadList;
class ReadListQueryResult
{
public function __construct(
#TODO
) {
}
}