diff --git a/app/Application/Console/Kernel.php b/app/Application/Console/Kernel.php index d1133a4..c234e31 100755 --- a/app/Application/Console/Kernel.php +++ b/app/Application/Console/Kernel.php @@ -20,8 +20,8 @@ protected function schedule(Schedule $schedule): void */ protected function commands(): void { - $this->load(__DIR__.'/Commands'); + $this->load(__DIR__ . '/Commands'); - require base_path('app/Infrastructure/routes/console.php'); + require base_path('routes/console.php'); } } diff --git a/app/Application/Factories/HasDomainFactory.php b/app/Application/Factories/HasDomainFactory.php deleted file mode 100755 index 9a79d56..0000000 --- a/app/Application/Factories/HasDomainFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -getNamespaceName(); - - $modelNamespace = str_replace('Models', 'Database\Factories', $namespace); - - /** @var Factory $factory */ - $factory = $modelNamespace . '\\' . $class->getShortName() . 'Factory'; - - - return $factory::new(); - } -} diff --git a/app/Application/Infrastructure/Database/Factories/Traits/SupportProjections.php b/app/Application/Infrastructure/Database/Factories/Traits/SupportProjections.php new file mode 100644 index 0000000..ea0c1c1 --- /dev/null +++ b/app/Application/Infrastructure/Database/Factories/Traits/SupportProjections.php @@ -0,0 +1,17 @@ + fake()->uuid(), + ...$attributes, + ])->writeable(); + } +} diff --git a/app/Application/Providers/BroadcastServiceProvider.php b/app/Application/Providers/BroadcastServiceProvider.php index 91c2e67..a9ec367 100755 --- a/app/Application/Providers/BroadcastServiceProvider.php +++ b/app/Application/Providers/BroadcastServiceProvider.php @@ -14,6 +14,6 @@ public function boot(): void { Broadcast::routes(); - require base_path('app/Infrastructure/routes/channels.php'); + require base_path('app/channels.php'); } } diff --git a/app/Application/Providers/DomainServiceProvider.php b/app/Application/Providers/DomainServiceProvider.php deleted file mode 100755 index 6712fc7..0000000 --- a/app/Application/Providers/DomainServiceProvider.php +++ /dev/null @@ -1,25 +0,0 @@ -loadMigrationsFrom([ database_path('migrations/**'), + database_path('migrations/**/**'), + database_path('migrations/**/**/**'), ]); } } diff --git a/app/Application/Providers/RouteServiceProvider.php b/app/Application/Providers/RouteServiceProvider.php index dd7e420..e062292 100755 --- a/app/Application/Providers/RouteServiceProvider.php +++ b/app/Application/Providers/RouteServiceProvider.php @@ -31,10 +31,10 @@ public function boot(): void $this->routes(function () { Route::middleware('api') ->prefix('api') - ->group(base_path('app/Infrastructure/routes/api.php')); + ->group(base_path('routes/api.php')); Route::middleware('web') - ->group(base_path('app/Infrastructure/routes/web.php')); + ->group(base_path('routes/web.php')); }); } } diff --git a/app/Domain/Account/Account.php b/app/Domain/Account/Account.php index 4c2353e..04eaaa2 100755 --- a/app/Domain/Account/Account.php +++ b/app/Domain/Account/Account.php @@ -8,11 +8,16 @@ use App\Domain\Account\Events\AccountCreated; use App\Domain\Account\Events\MoneyAdded; use App\Domain\Account\Events\MoneySubtracted; +use App\Domain\User\User; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Ramsey\Uuid\Uuid; use Spatie\EventSourcing\Projections\Projection; class Account extends Projection { + use HasFactory; + protected $table = 'accounts'; protected $guarded = []; @@ -48,4 +53,12 @@ public static function uuid(string $uuid): Account { return (new Account)->where('uuid', $uuid)->firstOrFail(); } + + /** + * Relationships + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class, 'user_uuid', 'uuid'); + } } diff --git a/app/Domain/User/User.php b/app/Domain/User/User.php index 689cffa..7821850 100755 --- a/app/Domain/User/User.php +++ b/app/Domain/User/User.php @@ -3,20 +3,23 @@ namespace App\Domain\User; // use Illuminate\Contracts\Auth\MustVerifyEmail; -use App\Application\Factories\HasDomainFactory; +use App\Domain\Account\Account; use Illuminate\Database\Eloquent\Factories\Factory; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { - use HasApiTokens, Notifiable, HasDomainFactory; + use HasApiTokens, Notifiable, HasFactory; protected static function newFactory(): Factory { - return \App\Domain\User\Database\Factories\UserFactory::new(); + return \Database\Factories\Domain\User\UserFactory::new(); } + /** * The attributes that are mass assignable. * @@ -47,4 +50,12 @@ protected static function newFactory(): Factory 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; + + /** + * The attributes that should be cast. + */ + public function accounts(): HasMany + { + return $this->hasMany(Account::class, 'user_uuid', 'uuid'); + } } diff --git a/app/Infrastructure/database/seeders/DatabaseSeeder.php b/app/Infrastructure/database/seeders/DatabaseSeeder.php deleted file mode 100755 index 2395fd4..0000000 --- a/app/Infrastructure/database/seeders/DatabaseSeeder.php +++ /dev/null @@ -1,20 +0,0 @@ -call([ - UserSeeder::class, - ]); - } - -} diff --git a/bootstrap/app.php b/bootstrap/app.php index ee6e10a..02a8b61 100755 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -50,8 +50,8 @@ | able to resolve it when needed. The config path is needed to load the | configuration files for the application. */ -$app->useConfigPath(__DIR__ . '/../app/Infrastructure/config'); -$app->useDatabasePath(__DIR__ . '/../app/Infrastructure/database'); +$app->useConfigPath(__DIR__ . '/../config'); +$app->useDatabasePath(__DIR__ . '/../database'); /* |-------------------------------------------------------------------------- | Return The Application diff --git a/composer.json b/composer.json index 398105e..fbf7261 100755 --- a/composer.json +++ b/composer.json @@ -32,10 +32,7 @@ "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - }, - "classmap": [ - "app/Infrastructure/database/seeders" - ] + } }, "autoload-dev": { "psr-4": { diff --git a/app/Infrastructure/config/app.php b/config/app.php similarity index 99% rename from app/Infrastructure/config/app.php rename to config/app.php index 644cb4f..40029e8 100755 --- a/app/Infrastructure/config/app.php +++ b/config/app.php @@ -172,7 +172,6 @@ /* * Self added Service Providers */ - \App\Application\Providers\DomainServiceProvider::class, \App\Application\Providers\InfrastructureServiceProvider::class ])->toArray(), diff --git a/app/Infrastructure/config/auth.php b/config/auth.php similarity index 100% rename from app/Infrastructure/config/auth.php rename to config/auth.php diff --git a/app/Infrastructure/config/broadcasting.php b/config/broadcasting.php similarity index 100% rename from app/Infrastructure/config/broadcasting.php rename to config/broadcasting.php diff --git a/app/Infrastructure/config/cache.php b/config/cache.php similarity index 100% rename from app/Infrastructure/config/cache.php rename to config/cache.php diff --git a/app/Infrastructure/config/cors.php b/config/cors.php similarity index 100% rename from app/Infrastructure/config/cors.php rename to config/cors.php diff --git a/app/Infrastructure/config/database.php b/config/database.php similarity index 96% rename from app/Infrastructure/config/database.php rename to config/database.php index daa2afc..5a08ec5 100755 --- a/app/Infrastructure/config/database.php +++ b/config/database.php @@ -61,6 +61,12 @@ 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], + 'seed' => [ + 'default' => [ + 'path' => 'app/Infrastructure/database/seeders', + 'class' => 'DatabaseSeeder', + ], + ], ], 'pgsql' => [ diff --git a/app/Infrastructure/config/filesystems.php b/config/filesystems.php similarity index 100% rename from app/Infrastructure/config/filesystems.php rename to config/filesystems.php diff --git a/app/Infrastructure/config/hashing.php b/config/hashing.php similarity index 100% rename from app/Infrastructure/config/hashing.php rename to config/hashing.php diff --git a/app/Infrastructure/config/logging.php b/config/logging.php similarity index 100% rename from app/Infrastructure/config/logging.php rename to config/logging.php diff --git a/app/Infrastructure/config/mail.php b/config/mail.php similarity index 100% rename from app/Infrastructure/config/mail.php rename to config/mail.php diff --git a/app/Infrastructure/config/queue.php b/config/queue.php similarity index 100% rename from app/Infrastructure/config/queue.php rename to config/queue.php diff --git a/app/Infrastructure/config/sanctum.php b/config/sanctum.php similarity index 100% rename from app/Infrastructure/config/sanctum.php rename to config/sanctum.php diff --git a/app/Infrastructure/config/services.php b/config/services.php similarity index 100% rename from app/Infrastructure/config/services.php rename to config/services.php diff --git a/app/Infrastructure/config/session.php b/config/session.php similarity index 100% rename from app/Infrastructure/config/session.php rename to config/session.php diff --git a/app/Infrastructure/config/view.php b/config/view.php similarity index 100% rename from app/Infrastructure/config/view.php rename to config/view.php diff --git a/database/factories/Domain/Account/AccountFactory.php b/database/factories/Domain/Account/AccountFactory.php new file mode 100644 index 0000000..9734b72 --- /dev/null +++ b/database/factories/Domain/Account/AccountFactory.php @@ -0,0 +1,25 @@ + $this->faker->uuid(), + 'name' => $this->faker->name(), + 'balance' => $this->faker->randomFloat(2, 0, 1000000), + ]; + } +} diff --git a/app/Domain/User/Database/Factories/UserFactory.php b/database/factories/Domain/User/UserFactory.php similarity index 90% rename from app/Domain/User/Database/Factories/UserFactory.php rename to database/factories/Domain/User/UserFactory.php index a226d0f..c65ae36 100755 --- a/app/Domain/User/Database/Factories/UserFactory.php +++ b/database/factories/Domain/User/UserFactory.php @@ -1,6 +1,6 @@ $this->faker->uuid(), 'name' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), diff --git a/app/Infrastructure/database/migrations/Application/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations/Application/2014_10_12_100000_create_password_reset_tokens_table.php similarity index 100% rename from app/Infrastructure/database/migrations/Application/2014_10_12_100000_create_password_reset_tokens_table.php rename to database/migrations/Application/2014_10_12_100000_create_password_reset_tokens_table.php diff --git a/app/Infrastructure/database/migrations/Application/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/Application/2019_08_19_000000_create_failed_jobs_table.php similarity index 100% rename from app/Infrastructure/database/migrations/Application/2019_08_19_000000_create_failed_jobs_table.php rename to database/migrations/Application/2019_08_19_000000_create_failed_jobs_table.php diff --git a/app/Infrastructure/database/migrations/Application/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/Application/2019_12_14_000001_create_personal_access_tokens_table.php similarity index 100% rename from app/Infrastructure/database/migrations/Application/2019_12_14_000001_create_personal_access_tokens_table.php rename to database/migrations/Application/2019_12_14_000001_create_personal_access_tokens_table.php diff --git a/app/Infrastructure/database/migrations/Application/2023_06_27_095844_create_stored_events_table.php b/database/migrations/Application/2023_06_27_095844_create_stored_events_table.php similarity index 100% rename from app/Infrastructure/database/migrations/Application/2023_06_27_095844_create_stored_events_table.php rename to database/migrations/Application/2023_06_27_095844_create_stored_events_table.php diff --git a/app/Infrastructure/database/migrations/Application/2023_06_27_095845_create_snapshots_table.php b/database/migrations/Application/2023_06_27_095845_create_snapshots_table.php similarity index 100% rename from app/Infrastructure/database/migrations/Application/2023_06_27_095845_create_snapshots_table.php rename to database/migrations/Application/2023_06_27_095845_create_snapshots_table.php diff --git a/app/Domain/Account/Database/Migrations/2023_07_02_142600_create_account_table.php b/database/migrations/Domain/Account/2023_07_02_142600_create_account_table.php similarity index 75% rename from app/Domain/Account/Database/Migrations/2023_07_02_142600_create_account_table.php rename to database/migrations/Domain/Account/2023_07_02_142600_create_account_table.php index 9b295e9..986f230 100755 --- a/app/Domain/Account/Database/Migrations/2023_07_02_142600_create_account_table.php +++ b/database/migrations/Domain/Account/2023_07_02_142600_create_account_table.php @@ -10,10 +10,11 @@ public function up(): void { Schema::create('accounts', function (Blueprint $table) { - $table->increments('id'); - $table->string('uuid'); + $table->id(); + $table->uuid()->index('accounts_uuid'); $table->string('name'); $table->integer('balance')->default(0); + $table->foreignUuid('user_uuid')->nullable()->constrained('users', 'uuid', 'users_uuid'); $table->timestamps(); }); } diff --git a/app/Domain/User/Database/Migrations/2014_10_12_000000_create_users_table.php b/database/migrations/Domain/User/2014_10_12_000000_create_users_table.php similarity index 89% rename from app/Domain/User/Database/Migrations/2014_10_12_000000_create_users_table.php rename to database/migrations/Domain/User/2014_10_12_000000_create_users_table.php index 444fafb..06b1941 100755 --- a/app/Domain/User/Database/Migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/Domain/User/2014_10_12_000000_create_users_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. */ @@ -13,6 +12,7 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); + $table->uuid()->index('users_uuid'); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php new file mode 100755 index 0000000..fdccbff --- /dev/null +++ b/database/seeders/DatabaseSeeder.php @@ -0,0 +1,27 @@ +call([ + UserSeeder::class, + ]); + + Account::factory()->count(50)->make()->each(function ($account) { + $account->user_uuid = User::factory()->create()->uuid; + $account->save(); + }); + } + +} diff --git a/app/Domain/User/Database/Seeders/UserSeeder.php b/database/seeders/Domain/User/UserSeeder.php similarity index 78% rename from app/Domain/User/Database/Seeders/UserSeeder.php rename to database/seeders/Domain/User/UserSeeder.php index 3d57c5c..e68da13 100755 --- a/app/Domain/User/Database/Seeders/UserSeeder.php +++ b/database/seeders/Domain/User/UserSeeder.php @@ -1,6 +1,6 @@ 'admin@admin.com', 'password' => bcrypt('password'), ])->create(); + + User::factory()->count(10)->create(); } } diff --git a/docker-compose.yml b/docker-compose.yml index cefc3dd..860b77b 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,6 +65,20 @@ services: - '/dev/shm:/dev/shm' networks: - sail + + phpmyadmin: + image: phpmyadmin/phpmyadmin + ports: + - 8080:80 + environment: + PMA_HOST: mysql + PMA_PORT: 3306 + PMA_USER: '${DB_USERNAME}' + PMA_PASSWORD: '${DB_PASSWORD}' + depends_on: + - mysql + networks: + - sail networks: sail: driver: bridge diff --git a/app/Infrastructure/routes/api.php b/routes/api.php similarity index 100% rename from app/Infrastructure/routes/api.php rename to routes/api.php diff --git a/app/Infrastructure/routes/auth.php b/routes/auth.php similarity index 100% rename from app/Infrastructure/routes/auth.php rename to routes/auth.php diff --git a/app/Infrastructure/routes/channels.php b/routes/channels.php similarity index 100% rename from app/Infrastructure/routes/channels.php rename to routes/channels.php diff --git a/app/Infrastructure/routes/console.php b/routes/console.php similarity index 100% rename from app/Infrastructure/routes/console.php rename to routes/console.php diff --git a/app/Infrastructure/routes/web.php b/routes/web.php similarity index 100% rename from app/Infrastructure/routes/web.php rename to routes/web.php