From 74b303fb2d34b8f1c4cb20b08483682e9ac5b232 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 27 Jun 2024 20:05:41 -0400 Subject: [PATCH] Add the Channel repository class. --- .../20240624023258_create_channels_table.php | 3 +- .../Repository/Channel/ChannelRepository.php | 46 +++++++++++++++++++ .../Channel/ChannelRepositoryInterface.php | 16 +++++++ .../Domain/Repository/User/UserRepository.php | 6 +-- .../User/UserRepositoryInterface.php | 2 +- 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 app/src/Domain/Repository/Channel/ChannelRepository.php create mode 100644 app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php diff --git a/app/db/migrations/20240624023258_create_channels_table.php b/app/db/migrations/20240624023258_create_channels_table.php index 41d57a7..8041593 100644 --- a/app/db/migrations/20240624023258_create_channels_table.php +++ b/app/db/migrations/20240624023258_create_channels_table.php @@ -46,8 +46,9 @@ final class CreateChannelsTable extends AbstractMigration $table = $this->table('channels')->addTimestamps(); $table->addColumn('name', 'string') + ->addColumn('slug', 'string') ->addColumn('description', 'string', [ 'null' => false ]) - ->addColumn('links', 'string') + ->addColumn('link', 'string') ->addColumn('language', 'string') ->addColumn('copyright', 'string') ->addColumn('explicit', 'boolean', [ 'default' => false ]) diff --git a/app/src/Domain/Repository/Channel/ChannelRepository.php b/app/src/Domain/Repository/Channel/ChannelRepository.php new file mode 100644 index 0000000..115c622 --- /dev/null +++ b/app/src/Domain/Repository/Channel/ChannelRepository.php @@ -0,0 +1,46 @@ + $results['name'] + ]); + } + + public function get(int $id): Channel + { + $query = "SELECT * FROM channels WHERE id = ?"; + $results = await($this->db->query($query, [ $id ])); + + if (!count($results->resultRows)) { + throw new EntityNotFoundException("Unable to find Channel"); + } + + return $this->createChannelFromResults($results->resultRows[0]); + } + + public function getFromUser(User $user): Channel + { + + } + + public function getFromSlug(string $slug): Channel + { + + } +} diff --git a/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php b/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php new file mode 100644 index 0000000..d024208 --- /dev/null +++ b/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php @@ -0,0 +1,16 @@ +db->query($query, [ $email ])); - if (count($results->resultRows)) { - throw new EntityNotFoundException("Entity does not exist."); + if (!count($results->resultRows)) { + throw new EntityNotFoundException("Unable to find User"); } return $this->userFromQueryResults($results->resultRows[0]); @@ -67,7 +67,7 @@ class UserRepository implements UserRepositoryInterface * @param User $user * @return bool True if the User is saved. */ - public function save(User $user): bool + public function create(User $user): bool { $query = "INSERT INTO users (email, password, name) VALUES (?, ?, ?)"; diff --git a/app/src/Domain/Repository/User/UserRepositoryInterface.php b/app/src/Domain/Repository/User/UserRepositoryInterface.php index 602517d..00b55f6 100644 --- a/app/src/Domain/Repository/User/UserRepositoryInterface.php +++ b/app/src/Domain/Repository/User/UserRepositoryInterface.php @@ -8,7 +8,7 @@ interface UserRepositoryInterface { public function get(int $id): User; public function getFromEmail(string $email): User; - public function save(User $user): bool; + public function create(User $user): bool; public function update(User $user): bool; public function verifyPassword(string $email, string $password): bool; }