add postgres user repository
This commit is contained in:
parent
6fbc1fb4f5
commit
d99d893394
2 changed files with 58 additions and 1 deletions
53
backend/app/User/PostgresUserRepository.php
Normal file
53
backend/app/User/PostgresUserRepository.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\User;
|
||||
|
||||
use App\Database\UserModel;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
|
||||
class PostgresUserRepository implements UserRepository
|
||||
{
|
||||
public function create(CreateUserDto $dto): User
|
||||
{
|
||||
$record = UserModel::create([
|
||||
'email' => $dto->email->value(),
|
||||
'password_hash' => $dto->passwordHash,
|
||||
]);
|
||||
|
||||
return new User(
|
||||
id: $record->id,
|
||||
email: new EmailAddress($record->email),
|
||||
passwordHash: $record->password_hash,
|
||||
);
|
||||
}
|
||||
|
||||
public function findByEmail(EmailAddress $email): ?User
|
||||
{
|
||||
$record = UserModel::where('email', $email->value())->first();
|
||||
|
||||
if ($record === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new User(
|
||||
id: $record->id,
|
||||
email: new EmailAddress($record->email),
|
||||
passwordHash: $record->password_hash,
|
||||
);
|
||||
}
|
||||
|
||||
public function find(int $id): ?User
|
||||
{
|
||||
$record = UserModel::find($id);
|
||||
|
||||
if ($record === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new User(
|
||||
id: $record->id,
|
||||
email: new EmailAddress($record->email),
|
||||
passwordHash: $record->password_hash,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue