seed available sets

This commit is contained in:
Yisroel Baum 2026-08-03 20:25:37 +03:00
parent 4dfea4ebb3
commit 41c0e7bebe
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace Database\Seeders;
use App\Set\CreateSetDto;
use App\Set\SetRepository;
use App\Shared\ValueObject\EmailAddress;
use App\User\UserRepository;
use Illuminate\Database\Seeder;
use RuntimeException;
class SetSeeder extends Seeder
{
private const array NAMES = [
'Bible',
'Course',
'Fitness Program',
];
public function run(): void
{
$user = app(UserRepository::class)->findByEmail(
new EmailAddress(UserSeeder::EMAIL),
);
if ($user === null) {
throw new RuntimeException('seeded user not found');
}
$repository = app(SetRepository::class);
$existingNames = array_map(function ($set): string {
return $set->getName();
}, $repository->all());
foreach (self::NAMES as $name) {
if (in_array($name, $existingNames, true)) {
continue;
}
$repository->create(new CreateSetDto(
name: $name,
creator: $user,
));
}
}
}