Skip to content

Find last #257

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

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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Repositories and handler
  • Loading branch information
Didweb committed May 22, 2021
commit 8e08803a3c83ff98f075955eb4cce6c5ecb54d80
11 changes: 11 additions & 0 deletions src/Mooc/Videos/Application/Find/FindLastVideoQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Application\Find;


final class FindLastVideoQuery
{

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

declare(strict_types=1);

namespace CodelyTv\Mooc\Videos\Application\Find;


use CodelyTv\Mooc\Videos\Domain\Video;
use CodelyTv\Mooc\Videos\Domain\VideoRepository;

final class FindLastVideoQueryHandler
{
public function __construct(private VideoRepository $videoRepository)
{
}

public function __invoke(FindLastVideoQuery $findLastVideoQuery): ?Video
{
return $this->videoRepository->findLastVideo();
}
}
2 changes: 2 additions & 0 deletions src/Mooc/Videos/Domain/VideoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public function save(Video $video): void;

public function search(VideoId $id): ?Video;

public function findLastVideo(): ?Video;

public function searchByCriteria(Criteria $criteria): Videos;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function search(VideoId $id): ?Video
return $this->repository(Video::class)->find($id);
}

public function findLastVideo(): ?Video
{
return $this->repository(Video::class)->findOneBy([], ['id' => 'DESC']);
}


public function searchByCriteria(Criteria $criteria): Videos
{
$doctrineCriteria = DoctrineCriteriaConverter::convert($criteria, self::$criteriaToDoctrineFields);
Expand Down