Refactor some of the query strings, update the documentation.
This commit is contained in:
parent
e8a9624ba1
commit
4d25d3039a
@ -11,15 +11,18 @@ use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
|||||||
|
|
||||||
class UserRepository implements UserRepositoryInterface
|
class UserRepository implements UserRepositoryInterface
|
||||||
{
|
{
|
||||||
const CREATE_QUERY = "INSERT INTO users (email, password, name)
|
const QUERY_CREATE = "INSERT INTO users (email, password, name)
|
||||||
VALUES (:email, :password, :name)";
|
VALUES (:email, :password, :name)";
|
||||||
|
|
||||||
const UPDATE_QUERY = "UPDATE users
|
const QUERY_UPDATE = "UPDATE users
|
||||||
SET email = :email,
|
SET email = :email,
|
||||||
name = :name,
|
name = :name,
|
||||||
password = :password
|
password = :password
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
|
const QUERY_SELECT_BY_ID = "";
|
||||||
|
const QUERY_SELECT_BY_EMAIL = "";
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private DatabaseHandlerInterface $db,
|
private DatabaseHandlerInterface $db,
|
||||||
private UserAuthorizationInterface $userAuth
|
private UserAuthorizationInterface $userAuth
|
||||||
@ -76,7 +79,7 @@ class UserRepository implements UserRepositoryInterface
|
|||||||
|
|
||||||
public function create(User $user): bool
|
public function create(User $user): bool
|
||||||
{
|
{
|
||||||
$results = $this->db->execute(self::CREATE_QUERY, [
|
$results = $this->db->execute(self::QUERY_CREATE, [
|
||||||
':email' => $user->getEmail(),
|
':email' => $user->getEmail(),
|
||||||
':password' => $this->userAuth->hash($user->getPassword()),
|
':password' => $this->userAuth->hash($user->getPassword()),
|
||||||
':name' => $user->getName(),
|
':name' => $user->getName(),
|
||||||
@ -94,13 +97,7 @@ class UserRepository implements UserRepositoryInterface
|
|||||||
|
|
||||||
public function update(User $user): bool
|
public function update(User $user): bool
|
||||||
{
|
{
|
||||||
$query = "UPDATE users
|
$results = $this->db->execute(self::QUERY_UPDATE, [
|
||||||
SET email = :email,
|
|
||||||
name = :name,
|
|
||||||
password = :password
|
|
||||||
WHERE id = :id";
|
|
||||||
|
|
||||||
$results = $this->db->execute(self::UPDATE_QUERY, [
|
|
||||||
':email' => $user->getEmail(),
|
':email' => $user->getEmail(),
|
||||||
':name' => $user->getName(),
|
':name' => $user->getName(),
|
||||||
':password' => $this->userAuth->hash($user->getPassword()),
|
':password' => $this->userAuth->hash($user->getPassword()),
|
||||||
|
@ -8,6 +8,12 @@ interface UserRepositoryInterface
|
|||||||
{
|
{
|
||||||
public function get(int $id): User;
|
public function get(int $id): User;
|
||||||
public function getFromEmail(string $email): User;
|
public function getFromEmail(string $email): User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TODO Add methods for getting a User based on other related data, such
|
||||||
|
* as the Channel or Episode.
|
||||||
|
*/
|
||||||
|
|
||||||
public function create(User $user): bool;
|
public function create(User $user): bool;
|
||||||
public function update(User $user): bool;
|
public function update(User $user): bool;
|
||||||
public function delete(User $user): bool;
|
public function delete(User $user): bool;
|
||||||
|
Loading…
Reference in New Issue
Block a user