Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisVS committed Jul 4, 2023
1 parent 32d81da commit da699b5
Show file tree
Hide file tree
Showing 44 changed files with 136 additions and 95 deletions.
4 changes: 2 additions & 2 deletions app/Application/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
29 changes: 0 additions & 29 deletions app/Application/Factories/HasDomainFactory.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Application\Infrastructure\Database\Factories\Traits;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Model;

trait SupportProjections
{
public function newModel(array $attributes = []): Model
{
return Factory::newModel([
'uuid' => fake()->uuid(),
...$attributes,
])->writeable();
}
}
2 changes: 1 addition & 1 deletion app/Application/Providers/BroadcastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function boot(): void
{
Broadcast::routes();

require base_path('app/Infrastructure/routes/channels.php');
require base_path('app/channels.php');
}
}
25 changes: 0 additions & 25 deletions app/Application/Providers/DomainServiceProvider.php

This file was deleted.

2 changes: 2 additions & 0 deletions app/Application/Providers/InfrastructureServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function boot(): void
{
$this->loadMigrationsFrom([
database_path('migrations/**'),
database_path('migrations/**/**'),
database_path('migrations/**/**/**'),
]);
}
}
4 changes: 2 additions & 2 deletions app/Application/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
}
13 changes: 13 additions & 0 deletions app/Domain/Account/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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');
}
}
17 changes: 14 additions & 3 deletions app/Domain/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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');
}
}
20 changes: 0 additions & 20 deletions app/Infrastructure/database/seeders/DatabaseSeeder.php

This file was deleted.

4 changes: 2 additions & 2 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"classmap": [
"app/Infrastructure/database/seeders"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion app/Infrastructure/config/app.php → config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
/*
* Self added Service Providers
*/
\App\Application\Providers\DomainServiceProvider::class,
\App\Application\Providers\InfrastructureServiceProvider::class
])->toArray(),

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions database/factories/Domain/Account/AccountFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Database\Factories\Domain\Account;

use App\Application\Infrastructure\Database\Factories\Traits\SupportProjections;
use App\Domain\Account\Account;

class AccountFactory extends \Illuminate\Database\Eloquent\Factories\Factory
{
use SupportProjections;

protected $model = Account::class;

/**
* @inheritDoc
*/
public function definition(): array
{
return [
'uuid' => $this->faker->uuid(),
'name' => $this->faker->name(),
'balance' => $this->faker->randomFloat(2, 0, 1000000),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Domain\User\Database\Factories;
namespace Database\Factories\Domain\User;

use App\Domain\User\User;
use Illuminate\Database\Eloquent\Factories\Factory;
Expand All @@ -16,6 +16,7 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'uuid' => $this->faker->uuid(),
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
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();
Expand Down
27 changes: 27 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Database\Seeders;

use App\Domain\Account\Account;
use App\Domain\User\User;
use Database\Seeders\Domain\User\UserSeeder;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
$this->call([
UserSeeder::class,
]);

Account::factory()->count(50)->make()->each(function ($account) {
$account->user_uuid = User::factory()->create()->uuid;
$account->save();
});
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Domain\User\Database\Seeders;
namespace Database\Seeders\Domain\User;

use App\Domain\User\User;
use Illuminate\Database\Seeder;
Expand All @@ -14,5 +14,7 @@ public function run(): void
'email' => '[email protected]',
'password' => bcrypt('password'),
])->create();

User::factory()->count(10)->create();
}
}
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit da699b5

Please sign in to comment.