Add the Channel repository class.
This commit is contained in:
parent
037cf674a8
commit
74b303fb2d
@ -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 ])
|
||||
|
46
app/src/Domain/Repository/Channel/ChannelRepository.php
Normal file
46
app/src/Domain/Repository/Channel/ChannelRepository.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Domain\Repository\Channel;
|
||||
|
||||
use Slovocast\Domain\Repository\ChannelRepositoryInterface;
|
||||
use Slovocast\Domain\Entity\Channel;
|
||||
use Slovocast\Domain\Entity\User;
|
||||
use Slovocast\Exception\EntityNotFoundException;
|
||||
use React\Mysql\MysqlClient;
|
||||
use function React\Async\await;
|
||||
|
||||
class ChannelRepository implements ChannelRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected MysqlClient $db
|
||||
) { }
|
||||
|
||||
protected function createChannelFromResults(array $results): Channel
|
||||
{
|
||||
return Channel::fromArray([
|
||||
'name' => $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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Domain\Repository\Channel;
|
||||
|
||||
use Slovocast\Domain\Entity\Channel;
|
||||
use Slovocast\Domain\Entity\User;
|
||||
|
||||
interface ChannelRepositoryInterface
|
||||
{
|
||||
public function get(int $id): Channel;
|
||||
public function getFromUser(User $user): Channel;
|
||||
public function getFromSlug(string $slug): Channel;
|
||||
public function create(Channel $channel): bool;
|
||||
public function update(Channel $channel): bool;
|
||||
public function delete(Channel $channel): bool;
|
||||
}
|
@ -56,8 +56,8 @@ class UserRepository implements UserRepositoryInterface
|
||||
$query = "SELECT * FROM users WHERE email = ? LIMIT 1";
|
||||
$results = await($this->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 (?, ?, ?)";
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user