diff --git a/app/src/Domain/Repository/UserRepository.php b/app/src/Domain/Repository/UserRepository.php index a2cd438..704a6bd 100644 --- a/app/src/Domain/Repository/UserRepository.php +++ b/app/src/Domain/Repository/UserRepository.php @@ -3,6 +3,7 @@ namespace Slovocast\Domain\Repository; use Slovocast\Infrastructure\DatabaseConnectionInterface; +use Slovocast\Infrastructure\User\UserAuthorizationInterface; use Slovocast\Exception\EntityNotFoundException; use Slovocast\Domain\Entity\User; use PDO; @@ -10,7 +11,8 @@ use PDO; class UserRepository implements UserRepositoryInterface { public function __construct( - private DatabaseConnectionInterface $database + private DatabaseConnectionInterface $database, + private UserAuthorizationInterface $userAuth ) {} /** @@ -56,11 +58,10 @@ class UserRepository implements UserRepositoryInterface public function get(int $id): User { $query = "SELECT * FROM users WHERE id = :id LIMIT 1"; - $connection = $this->database->getConnection(); $userData = $this->queryForUser( $query, [ 'id' => $id ], - $connection + $this->database->getConnection() ); return $this->userFromQueryResults($userData); } @@ -68,12 +69,30 @@ class UserRepository implements UserRepositoryInterface public function getFromEmail(string $email): User { $query = "SELECT * FROM users WHERE email = :email LIMIT 1"; - $connection = $this->database->getConnection(); $userData = $this->queryForUser( $query, [ 'email' => $email ], - $connection + $this->database->getConnection() ); return $this->userFromQueryResults($userData); } + + public function save(User $user): bool + { + $connection = $this->database->getConnection(); + $query = "INSERT INTO users (email, password, name) + VALUES (:email, :password, :name)"; + + $statement = $connection->prepare($query); + return $statement->execute([ + 'email' => $user->getEmail(), + 'name'=> $user->getName(), + 'password' => $this->userAuth->hash($user->getPassword()) + ]); + } + + public function update(User $user): bool + { + + } }