ldc-boutique-cnc-sable/app/Queries/Customers/GetCustomerByEmailQuery.php

29 lines
785 B
PHP

<?php
declare(strict_types=1);
namespace App\Queries\Customers;
use App\Contracts\Query;
use App\Contracts\QueryInput;
use App\Models\Customer;
use Domain\Models\ValueObjects\Entities\ShopperId;
use Webmozart\Assert\Assert;
/**
* @implements \App\Contracts\Query<\App\Queries\Customers\GetCustomerByEmailQueryInput, \Domain\Models\ValueObjects\Entities\ShopperId|null>
*/
final readonly class GetCustomerByEmailQuery implements Query
{
public function __invoke(QueryInput $input): ?ShopperId
{
Assert::isInstanceOf($input, GetCustomerByEmailQueryInput::class);
/** @var Customer|null $customer */
$customer = Customer::query()
->where('email', $input->email->value)
->first();
return $customer?->getId();
}
}