feat: move prepopulation guards into participant service

This commit is contained in:
Björn Fromme committed 2026-04-11 18:28:32 +02:00
1 parent dbc0b4acee
commit 63e8a068b3
9 files changed
+114 -289

No files matched your search

@@ -5,10 +5,13 @@ declare(strict_types=1);
namespace App\Service;
use App\BusProNet\ApiClient;
use App\BusProNet\Model\Address;
use App\BusProNet\Model\Notification;
use App\Entity\User;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Security\Crypt;
use Carbon\CarbonImmutable;
use Psr\Log\LoggerInterface;
/**
@@ -20,6 +23,8 @@ use Psr\Log\LoggerInterface;
*/
class ParticipantPrepopulationService
{
public const TOKEN = '#KUN#';
public function __construct(
private readonly ApiClient $apiClient,
private readonly Crypt $crypt,
@@ -94,4 +99,50 @@ class ParticipantPrepopulationService
return $applicant;
}
}
/**
* Determines whether the applicant should be prepopulated.
*
* Only prepopulates if the participant is fresh.
*/
public function shouldPrepopulateApplicant(ParticipantDto $applicant): bool
{
return null === $applicant->firstName || '' === $applicant->firstName;
}
/**
* Checks if the participant's last name triggers dummy data fill.
*
* Only matches in create mode to avoid accidental triggering during edits.
*/
public function isDummyDataFillRequested(ParticipantDto $participant, string $mode): bool
{
if (BookingDto::MODE_CREATE !== $mode) {
return false;
}
return self::TOKEN === $participant->lastName;
}
/**
* Fills the participant DTO with generated dummy personal data.
*/
public function fillDummyParticipant(ParticipantDto $participant, int $participantIndex): void
{
$participantNumber = $participantIndex + 1;
$now = CarbonImmutable::now();
$participant->firstName = sprintf('Vorname %d', $participantNumber);
$participant->lastName = sprintf('Muster %d %s', $participantNumber, $now->format('H:i'));
$participant->mobile = '0171/111111';
$participant->email = sprintf('teilnehmer.in%[email protected]', $participantNumber);
$participant->dateOfBirth = $now->subYears(20)->toImmutable();
$address = new Address();
$address->street = 'Musterstr. 123';
$address->postCode = '99999';
$address->city = 'MusterOrt';
$address->country = 'Deutschland';
$participant->address = $address;
}
}