-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathVideoRepositoryMySql.php
More file actions
48 lines (38 loc) · 1.42 KB
/
VideoRepositoryMySql.php
File metadata and controls
48 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace CodelyTv\Mooc\Videos\Infrastructure\Persistence;
use CodelyTv\Mooc\Videos\Domain\Video;
use CodelyTv\Mooc\Videos\Domain\VideoId;
use CodelyTv\Mooc\Videos\Domain\VideoRepository;
use CodelyTv\Mooc\Videos\Domain\Videos;
use CodelyTv\Shared\Domain\Criteria\Criteria;
use CodelyTv\Shared\Infrastructure\Persistence\Doctrine\DoctrineCriteriaConverter;
use CodelyTv\Shared\Infrastructure\Persistence\Doctrine\DoctrineRepository;
final class VideoRepositoryMySql extends DoctrineRepository implements VideoRepository
{
private static array $criteriaToDoctrineFields = [
'id' => 'id',
'type' => 'type',
'title' => 'title',
'url' => 'url',
'course_id' => 'courseId',
];
public function save(Video $video): void
{
$this->persist($video);
}
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);
$videos = $this->repository(Video::class)->matching($doctrineCriteria)->toArray();
return new Videos($videos);
}
}