diff --git a/.gitignore b/.gitignore index 81f30f819..5de5ea533 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ vendor/ .env build/ +.idea +.env.local +apps/*/*/var/ diff --git a/src/Mooc/Steps/Application/Create/CreateStepCommandHandler.php b/src/Mooc/Steps/Application/Create/CreateStepCommandHandler.php deleted file mode 100644 index 3e7275490..000000000 --- a/src/Mooc/Steps/Application/Create/CreateStepCommandHandler.php +++ /dev/null @@ -1,26 +0,0 @@ -creator = $creator; - } - - public function __invoke(CreateVideoCommand $command) - { - $id = new VideoId($command->id()); - - $this->creator->__invoke($id); - } -} diff --git a/src/Mooc/Videos/Application/Create/CreateVideoCommand.php b/src/Mooc/Videos/Application/Create/CreateVideoCommand.php index 63dec1100..9d049b54a 100644 --- a/src/Mooc/Videos/Application/Create/CreateVideoCommand.php +++ b/src/Mooc/Videos/Application/Create/CreateVideoCommand.php @@ -9,28 +9,21 @@ final class CreateVideoCommand extends Command { - private $id; private $type; private $title; private $url; private $courseId; - public function __construct(Uuid $commandId, string $id, string $type, string $title, string $url, string $courseId) + public function __construct(Uuid $commandId, string $type, string $title, string $url, string $courseId) { parent::__construct($commandId); - $this->id = $id; $this->type = $type; $this->title = $title; $this->url = $url; $this->courseId = $courseId; } - public function id(): string - { - return $this->id; - } - public function type(): string { return $this->type; diff --git a/src/Mooc/Videos/Application/Create/CreateVideoCommandHandler.php b/src/Mooc/Videos/Application/Create/CreateVideoCommandHandler.php index d37b24410..553ad694c 100644 --- a/src/Mooc/Videos/Application/Create/CreateVideoCommandHandler.php +++ b/src/Mooc/Videos/Application/Create/CreateVideoCommandHandler.php @@ -22,12 +22,11 @@ public function __construct(VideoCreator $creator) public function __invoke(CreateVideoCommand $command) { - $id = new VideoId($command->id()); $type = new VideoType($command->type()); $title = new VideoTitle($command->title()); $url = new VideoUrl($command->url()); $courseId = new CourseId($command->courseId()); - $this->creator->create($id, $type, $title, $url, $courseId); + $this->creator->create($type, $title, $url, $courseId); } } diff --git a/src/Mooc/Videos/Application/Create/VideoCreator.php b/src/Mooc/Videos/Application/Create/VideoCreator.php index cfdb6d778..c66d88816 100644 --- a/src/Mooc/Videos/Application/Create/VideoCreator.php +++ b/src/Mooc/Videos/Application/Create/VideoCreator.php @@ -24,9 +24,9 @@ public function __construct(VideoRepository $repository, DomainEventPublisher $p $this->publisher = $publisher; } - public function create(VideoId $id, VideoType $type, VideoTitle $title, VideoUrl $url, CourseId $courseId): void + public function create(VideoType $type, VideoTitle $title, VideoUrl $url, CourseId $courseId): void { - $video = Video::create($id, $type, $title, $url, $courseId); + $video = Video::create($type, $title, $url, $courseId); $this->repository->save($video); diff --git a/src/Mooc/Videos/Domain/Video.php b/src/Mooc/Videos/Domain/Video.php index df8751436..cb6f5594d 100644 --- a/src/Mooc/Videos/Domain/Video.php +++ b/src/Mooc/Videos/Domain/Video.php @@ -7,6 +7,8 @@ use CodelyTv\Mooc\Shared\Domain\Courses\CourseId; use CodelyTv\Mooc\Shared\Domain\Videos\VideoUrl; use CodelyTv\Shared\Domain\Aggregate\AggregateRoot; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidFactory; final class Video extends AggregateRoot { @@ -26,17 +28,17 @@ public function __construct(VideoId $id, VideoType $type, VideoTitle $title, Vid } public static function create( - VideoId $id, VideoType $type, VideoTitle $title, VideoUrl $url, CourseId $courseId ): Video { - $video = new self($id, $type, $title, $url, $courseId); + $videoId = new VideoId(Uuid::uuid4()->toString()); + $video = new self($videoId, $type, $title, $url, $courseId); $video->record( new VideoCreatedDomainEvent( - $id->value(), + $videoId->value(), [ 'type' => $type->value(), 'title' => $title->value(), diff --git a/tests/src/Mooc/Videos/Application/Create/CreateVideoTest.php b/tests/src/Mooc/Videos/Application/Create/CreateVideoTest.php index bf093bb8b..39aebb823 100644 --- a/tests/src/Mooc/Videos/Application/Create/CreateVideoTest.php +++ b/tests/src/Mooc/Videos/Application/Create/CreateVideoTest.php @@ -6,6 +6,7 @@ use CodelyTv\Mooc\Videos\Application\Create\CreateVideoCommandHandler; use CodelyTv\Mooc\Videos\Application\Create\VideoCreator; +use CodelyTv\Shared\Domain\ValueObject\Uuid; use CodelyTv\Test\Mooc\Shared\Domain\Courses\CourseIdMother; use CodelyTv\Test\Mooc\Shared\Domain\Videos\VideoUrlMother; use CodelyTv\Test\Mooc\Videos\Domain\VideoCreatedDomainEventMother; @@ -32,21 +33,22 @@ protected function setUp() /** @test */ public function it_should_create_a_video(): void { + // given $command = CreateVideoCommandMother::random(); - $id = VideoIdMother::create($command->id()); + $id = VideoIdMother::create(Uuid::random()->value()); $type = VideoTypeMother::create($command->type()); $title = VideoTitleMother::create($command->title()); $url = VideoUrlMother::create($command->url()); $courseId = CourseIdMother::create($command->courseId()); $video = VideoMother::create($id, $type, $title, $url, $courseId); - $domainEvent = VideoCreatedDomainEventMother::create($id, $type, $title, $url, $courseId); $this->shouldSaveVideo($video); $this->shouldPublishDomainEvents($domainEvent); + // when $this->dispatch($command, $this->handler); } }