initial commit
This commit is contained in:
25
app/Services/Mapper/Api/ContactImportMapper.php
Normal file
25
app/Services/Mapper/Api/ContactImportMapper.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Mapper\Api;
|
||||
|
||||
use App\Data\Api\ContactImport as ContactImportData;
|
||||
use App\Data\ContactImport;
|
||||
|
||||
final class ContactImportMapper
|
||||
{
|
||||
public function fromModel(ContactImport $contactImport): ContactImportData
|
||||
{
|
||||
return new ContactImportData(
|
||||
$contactImport->id,
|
||||
$contactImport->queueAt->toIso8601String(),
|
||||
$contactImport->startedAt?->toIso8601String(),
|
||||
$contactImport->finishedAt?->toIso8601String(),
|
||||
(int) $contactImport->totalProcessed,
|
||||
(int) $contactImport->errors,
|
||||
(int) $contactImport->duplicates,
|
||||
$contactImport->state,
|
||||
);
|
||||
}
|
||||
}
|
||||
44
app/Services/Mapper/ContactImportMapper.php
Normal file
44
app/Services/Mapper/ContactImportMapper.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Mapper;
|
||||
|
||||
use App\Data\ContactImport as ContactImportData;
|
||||
use App\Models\ContactImport;
|
||||
|
||||
final class ContactImportMapper
|
||||
{
|
||||
public function fromModel(ContactImport $contactImport): ContactImportData
|
||||
{
|
||||
return new ContactImportData(
|
||||
$contactImport->id,
|
||||
$contactImport->queue_at,
|
||||
$contactImport->started_at,
|
||||
$contactImport->finished_at,
|
||||
(int) $contactImport->total_processed,
|
||||
(int) $contactImport->errors,
|
||||
(int) $contactImport->duplicates,
|
||||
$contactImport->state->value,
|
||||
$contactImport->file,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toModelAttributes(ContactImportData $contactImport): array
|
||||
{
|
||||
return [
|
||||
'id' => $contactImport->id,
|
||||
'queue_at' => $contactImport->queueAt,
|
||||
'started_at' => $contactImport->startedAt,
|
||||
'finished_at' => $contactImport->finishedAt,
|
||||
'total_processed' => $contactImport->totalProcessed,
|
||||
'errors' => $contactImport->errors,
|
||||
'duplicates' => $contactImport->duplicates,
|
||||
'state' => $contactImport->state,
|
||||
'file' => $contactImport->file,
|
||||
];
|
||||
}
|
||||
}
|
||||
58
app/Services/Mapper/ContactMapper.php
Normal file
58
app/Services/Mapper/ContactMapper.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Mapper;
|
||||
|
||||
use App\Data\Contact as ContactData;
|
||||
use App\Data\Intent\Contact\CreateContactIntent;
|
||||
use App\Data\Intent\Contact\UpdateContactIntent;
|
||||
use App\Models\Contact;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
final class ContactMapper
|
||||
{
|
||||
public function fromModel(Contact $contact): ContactData
|
||||
{
|
||||
return new ContactData(
|
||||
// @phpstan-ignore-next-line argument.type
|
||||
Uuid::fromString((string) $contact->id),
|
||||
// @phpstan-ignore-next-line argument.type
|
||||
$contact->email,
|
||||
// @phpstan-ignore-next-line argument.type
|
||||
$contact->first_name,
|
||||
// @phpstan-ignore-next-line argument.type
|
||||
$contact->last_name,
|
||||
);
|
||||
}
|
||||
|
||||
public function tryToCreateFromIntent(UpdateContactIntent|CreateContactIntent $intent): ContactData
|
||||
{
|
||||
if ($intent instanceof CreateContactIntent) {
|
||||
$uuid = Uuid::uuid7();
|
||||
} else {
|
||||
$uuid = $intent->uuid;
|
||||
}
|
||||
|
||||
return new ContactData(
|
||||
$uuid,
|
||||
$intent->email,
|
||||
$intent->firstName,
|
||||
$intent->lastName,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toModelAttributes(
|
||||
ContactData $contactData,
|
||||
): array {
|
||||
return [
|
||||
'id' => $contactData->uuid->toString(),
|
||||
'first_name' => $contactData->firstName,
|
||||
'last_name' => $contactData->lastName,
|
||||
'email' => $contactData->email,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user