From 8d7bcd0c2a698910a01d57bf447231256ad7062a Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Wed, 29 May 2024 21:44:03 -0400 Subject: [PATCH] Add the Entity trait to the channel. --- app/src/Domain/Entity/Channel.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/Domain/Entity/Channel.php b/app/src/Domain/Entity/Channel.php index f8f6369..e640bbc 100644 --- a/app/src/Domain/Entity/Channel.php +++ b/app/src/Domain/Entity/Channel.php @@ -2,10 +2,13 @@ namespace Slovocast\Domain\Entity; +use Slovocast\Domain\Entity; + class Channel { + use Entity; + public function __construct( - private readonly ?int $id, private string $name, private ?string $description = '', private ?string $link = '', @@ -45,8 +48,7 @@ class Channel */ public static function fromArray(array $props): Channel { - return self( - $props['id'] ?? null, + $channel = new self( $props['name'], $props['description'] ?? '', $props['link'] ?? '', @@ -54,5 +56,19 @@ class Channel $props['copyright'] ?? '', $props['explicit'] ?? false ); + + if ($props['id']) { + $channel->setId($props['id']); + } + + if ($props['createdAt']) { + $channel->setCreatedAt($props['createdAt']); + } + + if ($props['updatedAt']) { + $channel->setUpdatedAt($props['updatedAt']); + } + + return $channel; } }