Start the Episode repository.
This commit is contained in:
parent
36522292b0
commit
4f94b80902
@ -65,4 +65,35 @@ class Episode
|
|||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $props The properties of the method
|
||||||
|
*/
|
||||||
|
public static function fromArray(array $props): self
|
||||||
|
{
|
||||||
|
$episode = new self(
|
||||||
|
$props['title'],
|
||||||
|
$props['link'],
|
||||||
|
(int) $props['length'],
|
||||||
|
$props['description'],
|
||||||
|
$props['serialNumber'],
|
||||||
|
(bool) $props['explicit'],
|
||||||
|
$props['publishedDate'],
|
||||||
|
$props['episdoeType']
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($props['id']) {
|
||||||
|
$episode->setId($props['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($props['created_at']) {
|
||||||
|
$episode->setCreatedAt($props['createdAt']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($props['updated_id']) {
|
||||||
|
$episode->setUpdatedAt($props['updatedAt']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $episode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
38
app/src/Domain/Repository/Episode/EpisodeRespository.php
Normal file
38
app/src/Domain/Repository/Episode/EpisodeRespository.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Slovocast\Domain\Repository\Episode;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use DateTime;
|
||||||
|
use Slovocast\Domain\Entity\Episode;
|
||||||
|
use Slovocast\Domain\Repository\Episode\EpisodeRepositoryInterface;
|
||||||
|
use Slovocast\Exception\EntityNotFoundException;
|
||||||
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
|
|
||||||
|
class EpisodeRepository implements EpisodeRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private DatabaseHandlerInterface $db
|
||||||
|
) { }
|
||||||
|
|
||||||
|
protected function getEpisodeFromResults(array $results): Episode
|
||||||
|
{
|
||||||
|
$results['createdAt'] = new DateTimeImmutable($results['created_at']);
|
||||||
|
$results['updatedAt'] = new DateTime($results['updated_at']);
|
||||||
|
|
||||||
|
return Episode::fromArray($results);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(int $id): Episode
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM episodes WHERE id = :id";
|
||||||
|
$statement = $this->db->getConnection()->query($query);
|
||||||
|
$results = $statement->fetch(\PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!is_array($results) || !count($results)) {
|
||||||
|
throw new EntityNotFoundException("Unable to find Episode.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user