Add the update method to the episodes.

This commit is contained in:
Dave Smith-Hayes 2024-12-31 09:20:29 -05:00
parent a3035c8900
commit 7f322080c9

View File

@ -16,6 +16,9 @@ class EpisodeRepository implements EpisodeRepositoryInterface
private DatabaseHandlerInterface $db
) { }
/**
* @param array The query results from the database
*/
protected function getEpisodeFromResults(array $results): Episode
{
$results['createdAt'] = new DateTimeImmutable($results['created_at']);
@ -54,8 +57,8 @@ class EpisodeRepository implements EpisodeRepositoryInterface
public function create(Episode $episode): Episode
{
$query = "INSERT INTO episodes (
title, link, length, description, serialNumber,
explicit, publishedDate, episodeType
title, link, length, description, serial_number,
explicit, published_date, episode_type
) VALUE (
:title, :link, :length, :description, :serialNumber,
:explicit, :publishedDate, :episodeType
@ -76,6 +79,33 @@ class EpisodeRepository implements EpisodeRepositoryInterface
return $episode;
}
public function update(Episode $episode): bool
{
$query = "UPDATE episodes
SET title = :title,
link = :link,
length = :length,
description = :description,
serial_number = :serialNumber,
explicit = :explicit,
published_date = :publishedDate,
episode_type = :episodeType
WHERE id = :id";
$result = $this->db->execute($query, [
':title' => $episode->getTitle(),
':link' => $episode->getLink(),
':length' => $episode->getLength(),
':description' => $episode->getDescription(),
':serialNumber' => $episode->getSerialNumber(),
':explicit' => $episode->isExplicit(),
':publishedDate' => $episode->getPublishedDate(),
':episode_type' => $episode->getEpisodeType(),
]);
return $result;
}
/**
* @TODO Implement a plan for deleting
*/