53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?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,
|
|
);
|
|
}
|
|
}
|