Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create VideoTitleUpdate Command #309

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Mooc/Courses/Application/Find/CoursesFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Application\Find;

use CodelyTv\Mooc\Courses\Domain\CourseRepository;
use CodelyTv\Mooc\Courses\Domain\CoursesFinder as DomainCoursesFinder;

final class CoursesFinder
{
/** @var DomainCoursesFinder */
private $finder;

public function __construct(CourseRepository $repository)
{
$this->finder = new DomainCoursesFinder($repository);
}

public function __invoke(): array
{
return $this->finder->__invoke();
}
}
26 changes: 26 additions & 0 deletions src/Mooc/Courses/Application/Find/CoursesResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Application\Find;

use CodelyTv\Shared\Domain\Bus\Query\Response;

final class CoursesResponse implements Response
{
/** @var array */
private $courses;

/**
* CoursesResponse constructor
*/
public function __construct(array $courses)
{
$this->courses = $courses;
}

public function courses(): array
{
return $this->courses;
}
}
17 changes: 17 additions & 0 deletions src/Mooc/Courses/Application/Find/CoursesResponseConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Application\Find;

final class CoursesResponseConverter
{
/**
* @param array
* @return CoursesResponse
*/
public function __invoke(array $courses): CoursesResponse
{
return new CoursesResponse($courses);
}
}
12 changes: 12 additions & 0 deletions src/Mooc/Courses/Application/Find/FindCoursesQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Application\Find;

use CodelyTv\Shared\Domain\Bus\Query\Query;

final class FindCoursesQuery implements Query
{

}
29 changes: 29 additions & 0 deletions src/Mooc/Courses/Application/Find/FindCoursesQueryHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Application\Find;

use CodelyTv\Shared\Domain\Bus\Query\QueryHandler;
use function Lambdish\Phunctional\apply;
use function Lambdish\Phunctional\pipe;

final class FindCoursesQueryHandler implements QueryHandler
{

/** @var callable */
private $finder;

/**
* @param CoursesFinder $finder
*/
public function __construct(CoursesFinder $finder)
{
$this->finder = pipe($finder, new CoursesResponseConverter());
}

public function __invoke(FindCoursesQuery $query): CoursesResponse
{
return apply($this->finder);
}
}
2 changes: 2 additions & 0 deletions src/Mooc/Courses/Domain/CourseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface CourseRepository
public function save(Course $course): void;

public function search(CourseId $id): ?Course;

public function all(): ?array;
}
24 changes: 24 additions & 0 deletions src/Mooc/Courses/Domain/CoursesFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Domain;

final class CoursesFinder
{
public function __construct(private CourseRepository $repository)
{
}

public function __invoke(): array
{
/** @var array */
$courses = $this->repository->all();

if (null === $courses) {
throw new CoursesNotFound();
}

return $courses;
}
}
25 changes: 25 additions & 0 deletions src/Mooc/Courses/Domain/CoursesNotFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Courses\Domain;

use CodelyTv\Shared\Domain\DomainError;

final class CoursesNotFound extends DomainError
{
public function __construct()
{
parent::__construct();
}

public function errorCode(): string
{
return 'courses_not_found';
}

protected function errorMessage(): string
{
return sprintf('Oops! Courses not found.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public function search(CourseId $id): ?Course
{
return $this->repository(Course::class)->find($id);
}

public function all(): ?array
{
return $this->repository(Course::class)->findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function search(CourseId $id): ?Course
: null;
}

public function all(): ?array
{
// TODO
return [];
}

private function fileName(string $id): string
{
return sprintf('%s.%s.repo', self::FILE_PATH, $id);
Expand Down
22 changes: 22 additions & 0 deletions src/Mooc/Videos/Application/Update/UpdateVideoTitleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Application\Update;

use CodelyTv\Shared\Domain\Bus\Command\Command;

final class UpdateVideoTitleCommand implements Command
{
public function __construct(private string $id, private string $title) { }

public function id(): string
{
return $this->id;
}

public function title(): string
{
return $this->title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Application\Update;

use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoTitle;
use CodelyTv\Shared\Domain\Bus\Command\CommandHandler;

final class UpdateVideoTitleCommandHandler implements CommandHandler
{
public function __construct(private VideoTitleUpdater $updater) { }

public function __invoke(UpdateVideoTitleCommand $command) {
$id = new VideoId($command->id());
$title = new VideoTitle($command->title());

$this->updater->__invoke($id, $title);
}
}