From fa5375e04d55a7c3c58831440f3c554675f4d649 Mon Sep 17 00:00:00 2001 From: Flo Date: Wed, 14 Feb 2024 21:10:43 +0100 Subject: [PATCH] now second commit i guess --- composer.development.json | 26 ++++++------ composer.json | 14 ++----- config/config.php | 2 + .../myTube/Version20230922085011.php | 1 - .../myTube/Version20230922092351.php | 1 - .../myTube/Version20240214194156.php | 38 +++++++++++++++++ .../External/Video/config/routes.php | 18 +++++--- .../External/Video/config/service_manager.php | 8 ++-- .../External/Video/src/ConfigProvider.php | 2 +- .../Video/src/Handler/StreamHandler.php | 41 +++++++++++++++++++ .../VideoList/src/Handler/ReadListHandler.php | 36 ++++++++++++++++ .../Business/src/Entity/Permission.php | 25 ----------- src/DataDomain/Business/src/Entity/Role.php | 22 ---------- src/DataDomain/Business/src/Entity/Video.php | 41 ++++++++++++------- .../src/Repository/VideoRepository.php | 8 +++- .../Video/config/service_manager.php | 25 +++-------- .../Video/src/ConfigProvider.php | 2 +- .../src/Handler/Query/Stream/StreamQuery.php | 15 +++++++ .../Query/Stream/StreamQueryBuilder.php | 16 ++++++++ .../Query/Stream/StreamQueryHandler.php | 17 ++++++++ .../Handler/Query/ReadList/ReadListQuery.php | 15 +++++++ .../Query/ReadList/ReadListQueryBuilder.php | 16 ++++++++ .../Query/ReadList/ReadListQueryHandler.php | 17 ++++++++ 23 files changed, 284 insertions(+), 122 deletions(-) create mode 100644 data/migrations/myTube/Version20240214194156.php create mode 100644 src/ApiDomain/External/Video/src/Handler/StreamHandler.php create mode 100644 src/ApiDomain/External/VideoList/src/Handler/ReadListHandler.php create mode 100644 src/HandlingDomain/Video/src/Handler/Query/Stream/StreamQuery.php create mode 100644 src/HandlingDomain/Video/src/Handler/Query/Stream/StreamQueryBuilder.php create mode 100644 src/HandlingDomain/Video/src/Handler/Query/Stream/StreamQueryHandler.php create mode 100644 src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQuery.php create mode 100644 src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQueryBuilder.php create mode 100644 src/HandlingDomain/VideoList/src/Handler/Query/ReadList/ReadListQueryHandler.php diff --git a/composer.development.json b/composer.development.json index eb2f67f..c5988a6 100644 --- a/composer.development.json +++ b/composer.development.json @@ -20,7 +20,7 @@ "laminas\/laminas-mail": "^2.23", "teewurst\/pipeline": "^3.0", "guzzlehttp\/guzzle": "^7.8", - "micilini\/video-stream": "*" + "micilini\/video-stream": "^1.0" }, "autoload": { "psr-4": { @@ -28,13 +28,16 @@ "MyTube\\API\\External\\Authentication\\": "src\/ApiDomain\/External\/Authentication\/src", "MyTube\\API\\External\\Health\\": "src\/ApiDomain\/External\/Health\/src", "MyTube\\API\\External\\User\\": "src\/ApiDomain\/External\/User\/src", + "MyTube\\API\\External\\Video\\": "src\/ApiDomain\/External\/Video\/src", + "MyTube\\API\\External\\VideoList\\": "src\/ApiDomain\/External\/VideoList\/src", "MyTube\\Data\\Business\\": "src\/DataDomain\/Business\/src", "MyTube\\Data\\Log\\": "src\/DataDomain\/Log\/src", - "MyTube\\Handling\\Product\\": "src\/HandlingDomain\/Product\/src", "MyTube\\Handling\\Registration\\": "src\/HandlingDomain\/Registration\/src", "MyTube\\Handling\\Role\\": "src\/HandlingDomain\/Role\/src", "MyTube\\Handling\\User\\": "src\/HandlingDomain\/User\/src", "MyTube\\Handling\\UserSession\\": "src\/HandlingDomain\/UserSession\/src", + "MyTube\\Handling\\Video\\": "src\/HandlingDomain\/Video\/src", + "MyTube\\Handling\\VideoList\\": "src\/HandlingDomain\/VideoList\/src", "MyTube\\Infrastructure\\Database\\": "src\/Infrastructure\/Database\/src", "MyTube\\Infrastructure\\DependencyInjection\\": "src\/Infrastructure\/DependencyInjection\/src", "MyTube\\Infrastructure\\Encryption\\": "src\/Infrastructure\/Encryption\/src", @@ -68,22 +71,16 @@ } }, "scripts": { - "dmg": "php bin\/doctrine-migrations.php migrations:generate --no-interaction", + "dmg": "php bin\/doctrine-migrations.php migrations:generate", "dmm": "php bin\/doctrine-migrations.php migrations:migrate --no-interaction", - "dmlg": "php bin\/doctrine-migrations-log.php migrations:generate --no-interaction", + "dmlg": "php bin\/doctrine-migrations-log.php migrations:generate", "dmlm": "php bin\/doctrine-migrations-log.php migrations:migrate --no-interaction", "console": "php bin\/console.php", - "serve": "php -S 0.0.0.0:8080 -t public\/", - "unserve": "killall -9 php", + "createApi": "php bin\/createApi.php", + "createPipeline": "php bin\/createPipeline.php", "da": [ "composer dump-autoload", "composer dump-autoload --dev" - ], - "initdb": [ - "@composer dmm", - "@composer dmlm", - "@composer console rbac:update", - "@composer console init:data" ] }, "config": { @@ -99,13 +96,16 @@ "MyTube\\API\\External\\Authentication\\": "src\/ApiDomain\/External\/Authentication\/src", "MyTube\\API\\External\\Health\\": "src\/ApiDomain\/External\/Health\/src", "MyTube\\API\\External\\User\\": "src\/ApiDomain\/External\/User\/src", + "MyTube\\API\\External\\Video\\": "src\/ApiDomain\/External\/Video\/src", + "MyTube\\API\\External\\VideoList\\": "src\/ApiDomain\/External\/VideoList\/src", "MyTube\\Data\\Business\\": "src\/DataDomain\/Business\/src", "MyTube\\Data\\Log\\": "src\/DataDomain\/Log\/src", - "MyTube\\Handling\\Product\\": "src\/HandlingDomain\/Product\/src", "MyTube\\Handling\\Registration\\": "src\/HandlingDomain\/Registration\/src", "MyTube\\Handling\\Role\\": "src\/HandlingDomain\/Role\/src", "MyTube\\Handling\\User\\": "src\/HandlingDomain\/User\/src", "MyTube\\Handling\\UserSession\\": "src\/HandlingDomain\/UserSession\/src", + "MyTube\\Handling\\Video\\": "src\/HandlingDomain\/Video\/src", + "MyTube\\Handling\\VideoList\\": "src\/HandlingDomain\/VideoList\/src", "MyTube\\Infrastructure\\Database\\": "src\/Infrastructure\/Database\/src", "MyTube\\Infrastructure\\DependencyInjection\\": "src\/Infrastructure\/DependencyInjection\/src", "MyTube\\Infrastructure\\Encryption\\": "src\/Infrastructure\/Encryption\/src", diff --git a/composer.json b/composer.json index b97bbf4..b6c9cf7 100644 --- a/composer.json +++ b/composer.json @@ -48,22 +48,16 @@ } }, "scripts": { - "dmg": "php bin/doctrine-migrations.php migrations:generate --no-interaction", + "dmg": "php bin/doctrine-migrations.php migrations:generate", "dmm": "php bin/doctrine-migrations.php migrations:migrate --no-interaction", - "dmlg": "php bin/doctrine-migrations-log.php migrations:generate --no-interaction", + "dmlg": "php bin/doctrine-migrations-log.php migrations:generate", "dmlm": "php bin/doctrine-migrations-log.php migrations:migrate --no-interaction", "console": "php bin/console.php", - "serve": "php -S 0.0.0.0:8080 -t public/", - "unserve": "killall -9 php", + "createApi": "php bin/createApi.php", + "createPipeline": "php bin/createPipeline.php", "da": [ "composer dump-autoload", "composer dump-autoload --dev" - ], - "initdb": [ - "@composer dmm", - "@composer dmlm", - "@composer console rbac:update", - "@composer console init:data" ] }, "config": { diff --git a/config/config.php b/config/config.php index 795729d..e18523a 100644 --- a/config/config.php +++ b/config/config.php @@ -57,6 +57,7 @@ $aggregator = new ConfigAggregator([ \MyTube\Handling\User\ConfigProvider::class, \MyTube\Handling\UserSession\ConfigProvider::class, \MyTube\Handling\Registration\ConfigProvider::class, + \MyTube\Handling\Video\ConfigProvider::class, // API /// Command @@ -66,6 +67,7 @@ $aggregator = new ConfigAggregator([ \MyTube\API\External\Health\ConfigProvider::class, \MyTube\API\External\User\ConfigProvider::class, \MyTube\API\External\Authentication\ConfigProvider::class, + \MyTube\API\External\Video\ConfigProvider::class, /// Internal diff --git a/data/migrations/myTube/Version20230922085011.php b/data/migrations/myTube/Version20230922085011.php index 1b20004..6c124bc 100644 --- a/data/migrations/myTube/Version20230922085011.php +++ b/data/migrations/myTube/Version20230922085011.php @@ -18,7 +18,6 @@ final class Version20230922085011 extends AbstractMigration { $sql = "CREATE TABLE role ( id binary(16) NOT NULL, - product_id binary(16) DEFAULT NULL, identifier varchar(255) UNIQUE NOT NULL, PRIMARY KEY (id) );"; diff --git a/data/migrations/myTube/Version20230922092351.php b/data/migrations/myTube/Version20230922092351.php index 366d65e..c8221d5 100644 --- a/data/migrations/myTube/Version20230922092351.php +++ b/data/migrations/myTube/Version20230922092351.php @@ -21,7 +21,6 @@ final class Version20230922092351 extends AbstractMigration { $sql = "CREATE TABLE permission ( id binary(16) NOT NULL, - product_id binary(16) DEFAULT NULL, identifier varchar(255) UNIQUE NOT NULL, PRIMARY KEY (id) );"; diff --git a/data/migrations/myTube/Version20240214194156.php b/data/migrations/myTube/Version20240214194156.php new file mode 100644 index 0000000..b560699 --- /dev/null +++ b/data/migrations/myTube/Version20240214194156.php @@ -0,0 +1,38 @@ +addSql($sql); + } + + public function down(Schema $schema): void + { + $this->addSql("DROP TABLE video;"); + } +} diff --git a/src/ApiDomain/External/Video/config/routes.php b/src/ApiDomain/External/Video/config/routes.php index 7b3cc22..ce8f2f3 100644 --- a/src/ApiDomain/External/Video/config/routes.php +++ b/src/ApiDomain/External/Video/config/routes.php @@ -1,16 +1,22 @@ 'health', - 'path' => '/api/health', + 'name' => 'video.stream', + 'path' => '/api/video/stream[/]', 'allowed_methods' => ['GET'], 'middleware' => [ - HealthHandler::class + StreamHandler::class + ], + ], + [ + 'name' => 'video.upload', + 'path' => '/api/video/upload[/]', + 'allowed_methods' => ['POST'], + 'middleware' => [ + StreamHandler::class ], ], ]; - -?> \ No newline at end of file diff --git a/src/ApiDomain/External/Video/config/service_manager.php b/src/ApiDomain/External/Video/config/service_manager.php index 6a17420..e0182e0 100644 --- a/src/ApiDomain/External/Video/config/service_manager.php +++ b/src/ApiDomain/External/Video/config/service_manager.php @@ -1,12 +1,10 @@ [ - HealthHandler::class => AutoWiringFactory::class + StreamHandler::class => AutoWiringFactory::class ], -] - -?> \ No newline at end of file +]; diff --git a/src/ApiDomain/External/Video/src/ConfigProvider.php b/src/ApiDomain/External/Video/src/ConfigProvider.php index d4d3beb..be33f4a 100644 --- a/src/ApiDomain/External/Video/src/ConfigProvider.php +++ b/src/ApiDomain/External/Video/src/ConfigProvider.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MyTube\API\External\Health; +namespace MyTube\API\External\Video; class ConfigProvider { diff --git a/src/ApiDomain/External/Video/src/Handler/StreamHandler.php b/src/ApiDomain/External/Video/src/Handler/StreamHandler.php new file mode 100644 index 0000000..bfaaee0 --- /dev/null +++ b/src/ApiDomain/External/Video/src/Handler/StreamHandler.php @@ -0,0 +1,41 @@ +streamVideo( + $videoPath, + [ + 'is_localPath' => true, + 'content_type' => 'video/mp4' + ] + ); + } else { + return new JsonResponse("Video not found", Response::STATUS_CODE_404); + } + } +} diff --git a/src/ApiDomain/External/VideoList/src/Handler/ReadListHandler.php b/src/ApiDomain/External/VideoList/src/Handler/ReadListHandler.php new file mode 100644 index 0000000..0fab5c1 --- /dev/null +++ b/src/ApiDomain/External/VideoList/src/Handler/ReadListHandler.php @@ -0,0 +1,36 @@ +getBody()->getContents(), + true + ); + + $readListQuery = $this->readListQueryBuilder->build( + $data + ); + $result = $this->readListQueryHandler->execute($readListQuery); + + return new SuccessResponse('OK'); + } +} diff --git a/src/DataDomain/Business/src/Entity/Permission.php b/src/DataDomain/Business/src/Entity/Permission.php index d4efa8f..5eb673d 100644 --- a/src/DataDomain/Business/src/Entity/Permission.php +++ b/src/DataDomain/Business/src/Entity/Permission.php @@ -19,15 +19,6 @@ class Permission { */ private UuidInterface $id; - /** @ORM\Column(name="product_id", type="uuid_binary_ordered_time", nullable=true) */ - private ?UuidInterface $productId; - - /** - * @ORM\OneToOne(targetEntity="MyTube\Data\Business\Entity\Product") - * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=true) - */ - private ?Product $product; - /** @ORM\Column(name="identifier", type="string") */ private string $identifier; @@ -52,22 +43,6 @@ class Permission { return $this->id; } - public function getProductId(): ?UuidInterface { - return $this->productId; - } - - public function setProductId(?UuidInterface $productId): void { - $this->productId = $productId; - } - - public function getProduct(): ?Product { - return $this->product; - } - - public function setProduct(?Product $product): void { - $this->product = $product; - } - public function getIdentifier(): string { return $this->identifier; } diff --git a/src/DataDomain/Business/src/Entity/Role.php b/src/DataDomain/Business/src/Entity/Role.php index ab1bd3b..49e0141 100644 --- a/src/DataDomain/Business/src/Entity/Role.php +++ b/src/DataDomain/Business/src/Entity/Role.php @@ -23,12 +23,6 @@ class Role { /** @ORM\Column(name="product_id", type="uuid_binary_ordered_time", nullable=true) */ private ?UuidInterface $productId; - /** - * @ORM\OneToOne(targetEntity="MyTube\Data\Business\Entity\Product") - * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=true) - */ - private ?Product $product; - /** @ORM\Column(name="identifier", type="string") */ private string $identifier; @@ -53,22 +47,6 @@ class Role { return $this->id; } - public function getProductId(): ?UuidInterface { - return $this->productId; - } - - public function setProductId(?UuidInterface $productId): void { - $this->productId = $productId; - } - - public function getProduct(): ?Product { - return $this->product; - } - - public function setProduct(?Product $product): void { - $this->product = $product; - } - public function getIdentifier(): string { return $this->identifier; } diff --git a/src/DataDomain/Business/src/Entity/Video.php b/src/DataDomain/Business/src/Entity/Video.php index 8b759dc..301d1fc 100644 --- a/src/DataDomain/Business/src/Entity/Video.php +++ b/src/DataDomain/Business/src/Entity/Video.php @@ -8,25 +8,28 @@ use MyTube\Infrastructure\UuidGenerator\UuidGenerator; use Ramsey\Uuid\UuidInterface; /** - * @ORM\Entity(repositoryClass="MyTube\Data\Business\Repository\RegistrationRepository") - * @ORM\Table(name="registration") + * @ORM\Entity(repositoryClass="MyTube\Data\Business\Repository\VideoRepository") + * @ORM\Table(name="video") */ -class Registration { +class Video { /** * @ORM\Id * @ORM\Column(name="id", type="uuid_binary_ordered_time") */ private UuidInterface $id; - /** @ORM\Column(name="username", type="string") */ - private string $username; + /** @ORM\Column(name="title", type="string") */ + private string $title; - /** @ORM\Column(name="mail", type="string") */ - private string $mail; + /** @ORM\Column(name="file_path", type="string") */ + private string $filePath; /** @ORM\Column(name="created_at", type="datetime") */ private DateTime $createdAt; + /** @ORM\Column(name="updated_at", type="datetime") */ + private DateTime $updatedAt; + public function __construct() { $this->id = UuidGenerator::generate(); @@ -40,20 +43,20 @@ class Registration { return $this->id; } - public function getUsername(): string { - return $this->username; + public function getTitle(): string { + return $this->title; } - public function setUsername(string $username): void { - $this->username = $username; + public function setTitle(string $title): void { + $this->title = $title; } - public function getMail(): ?string { - return $this->mail; + public function getFilePath(): ?string { + return $this->filePath; } - public function setMail(?string $mail): void { - $this->mail = $mail; + public function setFilePath(?string $filePath): void { + $this->filePath = $filePath; } public function getCreatedAt(): DateTime { @@ -63,4 +66,12 @@ class Registration { public function setCreatedAt(DateTime $createdAt): void { $this->createdAt = $createdAt; } + + public function getUpdatedAt(): DateTime { + return $this->updatedAt; + } + + public function setUpdatedAt(DateTime $updatedAt): void { + $this->updatedAt = $updatedAt; + } } diff --git a/src/DataDomain/Business/src/Repository/VideoRepository.php b/src/DataDomain/Business/src/Repository/VideoRepository.php index 737519a..bcf5a77 100644 --- a/src/DataDomain/Business/src/Repository/VideoRepository.php +++ b/src/DataDomain/Business/src/Repository/VideoRepository.php @@ -2,11 +2,15 @@ namespace MyTube\Data\Business\Repository; +use Doctrine\ORM\Tools\Pagination\Paginator; use MyTube\Data\Business\Entity\Registration; use Doctrine\ORM\EntityRepository; -class RegistrationRepository extends EntityRepository { - public function findByIdentifier(string $identifier) : ?Registration { +class VideoRepository extends EntityRepository { + public function findByFilter( + string $identifier + ): Paginator + { $queryBuilder = $this->createQueryBuilder('r'); $queryBuilder->where( $queryBuilder->expr()->orX( diff --git a/src/HandlingDomain/Video/config/service_manager.php b/src/HandlingDomain/Video/config/service_manager.php index fb94f93..7440492 100644 --- a/src/HandlingDomain/Video/config/service_manager.php +++ b/src/HandlingDomain/Video/config/service_manager.php @@ -1,31 +1,16 @@ [ - - /// Rule - UserPasswordMatchesRule::class => AutoWiringFactory::class, - - /// Builder - UserSessionBuilder::class => AutoWiringFactory::class, - /// CQRS - // Login User - LoginUserCommandHandler::class => InjectionFactory::class, - LoginUserCommandBuilder::class => AutoWiringFactory::class, - - // Logout User - LogoutUserCommandHandler::class => InjectionFactory::class, - LogoutUserCommandBuilder::class => AutoWiringFactory::class, + // Stream Query + StreamQueryHandler::class => InjectionFactory::class, + StreamQueryBuilder::class => AutoWiringFactory::class, ], ]; diff --git a/src/HandlingDomain/Video/src/ConfigProvider.php b/src/HandlingDomain/Video/src/ConfigProvider.php index 92ee2eb..067bcff 100644 --- a/src/HandlingDomain/Video/src/ConfigProvider.php +++ b/src/HandlingDomain/Video/src/ConfigProvider.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace MyTube\Handling\UserSession; +namespace MyTube\Handling\Video; class ConfigProvider { diff --git a/src/HandlingDomain/Video/src/Handler/Query/Stream/StreamQuery.php b/src/HandlingDomain/Video/src/Handler/Query/Stream/StreamQuery.php new file mode 100644 index 0000000..a0b9167 --- /dev/null +++ b/src/HandlingDomain/Video/src/Handler/Query/Stream/StreamQuery.php @@ -0,0 +1,15 @@ +