initial commit

This commit is contained in:
2026-02-11 23:37:50 +01:00
commit 908cf42ad9
128 changed files with 17831 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ImportContactsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$fileSize = config('imports.max_file_size');
if (!is_numeric($fileSize)) {
throw new \InvalidArgumentException("imports.max_file_size config value must be number");
}
return [
'file' => ['required', 'file', 'mimes:xml', 'max:' . $fileSize],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'file.required' => 'File is required.',
'file.file' => 'File must be a valid upload.',
'file.mimes' => 'File must be an XML file.',
'file.max' => 'File may not be greater than 100 MB.',
];
}
}

View File

@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use App\Data\Intent\Contact\CreateContactIntent;
use App\Services\Validators\ContactValidator;
use Illuminate\Foundation\Http\FormRequest;
class StoreContactRequest extends FormRequest
{
protected function prepareForValidation(): void
{
$email = $this->input('email');
if (is_string($email)) {
$this->merge([
'email' => strtolower(trim($email)),
]);
}
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return app(ContactValidator::class)->rulesForStore();
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return app(ContactValidator::class)->messages();
}
public function toIntent(): CreateContactIntent
{
$data = $this->validated();
/** @var array{email: string, first_name?: string|null, last_name?: string|null} $data */
return new CreateContactIntent(
$data['email'],
$data['first_name'] ?? null,
$data['last_name'] ?? null,
);
}
}

View File

@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use App\Data\Contact as ContactData;
use App\Data\Intent\Contact\UpdateContactIntent;
use App\Services\Validators\ContactValidator;
use Illuminate\Foundation\Http\FormRequest;
class UpdateContactRequest extends FormRequest
{
protected function prepareForValidation(): void
{
$email = $this->input('email');
if (is_string($email)) {
$this->merge([
'email' => strtolower(trim($email)),
]);
}
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$contact = $this->resolveContact();
return app(ContactValidator::class)->rulesForUpdate($contact);
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return app(ContactValidator::class)->messages();
}
public function toIntent(): UpdateContactIntent
{
$data = $this->validated();
/** @var array{email: string, first_name?: string|null, last_name?: string|null} $data */
$contact = $this->resolveContact();
return new UpdateContactIntent(
$contact->uuid,
$data['email'],
$data['first_name'] ?? null,
$data['last_name'] ?? null,
);
}
private function resolveContact(): ContactData
{
$routeContact = $this->route('contact');
if ($routeContact instanceof ContactData) {
return $routeContact;
}
abort(404);
}
}