From 0777f0da2ff39c6e6a630e0a4210c40702e38042 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 31 Jul 2026 09:49:18 +0300 Subject: [PATCH] add user entity --- backend/app/Models/User.php | 40 ------ backend/app/Providers/AppServiceProvider.php | 7 +- .../app/Shared/ValueObject/EmailAddress.php | 40 ++++++ backend/app/User/CreateUserDto.php | 12 ++ backend/app/User/EloquentUserRepository.php | 35 ++++++ backend/app/User/User.php | 23 ++++ backend/app/User/UserModel.php | 25 ++++ backend/app/User/UserRepository.php | 10 ++ backend/config/auth.php | 117 ------------------ .../0001_01_01_000000_create_users_table.php | 21 ++++ 10 files changed, 172 insertions(+), 158 deletions(-) delete mode 100644 backend/app/Models/User.php create mode 100644 backend/app/Shared/ValueObject/EmailAddress.php create mode 100644 backend/app/User/CreateUserDto.php create mode 100644 backend/app/User/EloquentUserRepository.php create mode 100644 backend/app/User/User.php create mode 100644 backend/app/User/UserModel.php create mode 100644 backend/app/User/UserRepository.php delete mode 100644 backend/config/auth.php create mode 100644 backend/database/migrations/0001_01_01_000000_create_users_table.php diff --git a/backend/app/Models/User.php b/backend/app/Models/User.php deleted file mode 100644 index 4c7c078..0000000 --- a/backend/app/Models/User.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ - protected function casts(): array - { - return [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; - } -} diff --git a/backend/app/Providers/AppServiceProvider.php b/backend/app/Providers/AppServiceProvider.php index f1525e9..fdc3673 100644 --- a/backend/app/Providers/AppServiceProvider.php +++ b/backend/app/Providers/AppServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use App\User\EloquentUserRepository; +use App\User\UserRepository; use Carbon\CarbonImmutable; use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\DB; @@ -15,7 +17,10 @@ class AppServiceProvider extends ServiceProvider */ public function register(): void { - // + $this->app->bind( + UserRepository::class, + EloquentUserRepository::class, + ); } /** diff --git a/backend/app/Shared/ValueObject/EmailAddress.php b/backend/app/Shared/ValueObject/EmailAddress.php new file mode 100644 index 0000000..de15bd9 --- /dev/null +++ b/backend/app/Shared/ValueObject/EmailAddress.php @@ -0,0 +1,40 @@ +normalized = $normalizedEmail; + } + + public function value(): string + { + return $this->normalized; + } +} diff --git a/backend/app/User/CreateUserDto.php b/backend/app/User/CreateUserDto.php new file mode 100644 index 0000000..735320b --- /dev/null +++ b/backend/app/User/CreateUserDto.php @@ -0,0 +1,12 @@ + $dto->email->value(), + ]); + + return $this->toDomain($model); + } + + public function find(int $id): ?User + { + $model = UserModel::find($id); + if ($model === null) { + return null; + } + + return $this->toDomain($model); + } + + private function toDomain(UserModel $model): User + { + return new User( + id: $model->id, + email: new EmailAddress($model->email), + ); + } +} diff --git a/backend/app/User/User.php b/backend/app/User/User.php new file mode 100644 index 0000000..8c9fa9c --- /dev/null +++ b/backend/app/User/User.php @@ -0,0 +1,23 @@ +id; + } + + public function getEmail(): EmailAddress + { + return $this->email; + } +} diff --git a/backend/app/User/UserModel.php b/backend/app/User/UserModel.php new file mode 100644 index 0000000..74f3211 --- /dev/null +++ b/backend/app/User/UserModel.php @@ -0,0 +1,25 @@ +|UserModel newModelQuery() + * @method static Builder|UserModel newQuery() + * @method static Builder|UserModel query() + * + * @mixin \Eloquent + */ +#[Fillable(['email'])] +class UserModel extends Model +{ + protected $table = 'users'; + + public $timestamps = false; +} diff --git a/backend/app/User/UserRepository.php b/backend/app/User/UserRepository.php new file mode 100644 index 0000000..5fcd6eb --- /dev/null +++ b/backend/app/User/UserRepository.php @@ -0,0 +1,10 @@ + [ - 'guard' => env('AUTH_GUARD', 'web'), - 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), - ], - - /* - |-------------------------------------------------------------------------- - | Authentication Guards - |-------------------------------------------------------------------------- - | - | Next, you may define every authentication guard for your application. - | Of course, a great default configuration has been defined for you - | which utilizes session storage plus the Eloquent user provider. - | - | All authentication guards have a user provider, which defines how the - | users are actually retrieved out of your database or other storage - | system used by the application. Typically, Eloquent is utilized. - | - | Supported: "session" - | - */ - - 'guards' => [ - 'web' => [ - 'driver' => 'session', - 'provider' => 'users', - ], - ], - - /* - |-------------------------------------------------------------------------- - | User Providers - |-------------------------------------------------------------------------- - | - | All authentication guards have a user provider, which defines how the - | users are actually retrieved out of your database or other storage - | system used by the application. Typically, Eloquent is utilized. - | - | If you have multiple user tables or models you may configure multiple - | providers to represent the model / table. These providers may then - | be assigned to any extra authentication guards you have defined. - | - | Supported: "database", "eloquent" - | - */ - - 'providers' => [ - 'users' => [ - 'driver' => 'eloquent', - 'model' => env('AUTH_MODEL', User::class), - ], - - // 'users' => [ - // 'driver' => 'database', - // 'table' => 'users', - // ], - ], - - /* - |-------------------------------------------------------------------------- - | Resetting Passwords - |-------------------------------------------------------------------------- - | - | These configuration options specify the behavior of Laravel's password - | reset functionality, including the table utilized for token storage - | and the user provider that is invoked to actually retrieve users. - | - | The expiry time is the number of minutes that each reset token will be - | considered valid. This security feature keeps tokens short-lived so - | they have less time to be guessed. You may change this as needed. - | - | The throttle setting is the number of seconds a user must wait before - | generating more password reset tokens. This prevents the user from - | quickly generating a very large amount of password reset tokens. - | - */ - - 'passwords' => [ - 'users' => [ - 'provider' => 'users', - 'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'), - 'expire' => 60, - 'throttle' => 60, - ], - ], - - /* - |-------------------------------------------------------------------------- - | Password Confirmation Timeout - |-------------------------------------------------------------------------- - | - | Here you may define the number of seconds before a password confirmation - | window expires and users are asked to re-enter their password via the - | confirmation screen. By default, the timeout lasts for three hours. - | - */ - - 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), - -]; diff --git a/backend/database/migrations/0001_01_01_000000_create_users_table.php b/backend/database/migrations/0001_01_01_000000_create_users_table.php new file mode 100644 index 0000000..dafb6c2 --- /dev/null +++ b/backend/database/migrations/0001_01_01_000000_create_users_table.php @@ -0,0 +1,21 @@ +id(); + $table->string('email')->unique(); + }); + } + + public function down(): void + { + Schema::dropIfExists('users'); + } +};