51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Infrastructure\Adapters\Directories;
|
|
|
|
use App\Models\Shop;
|
|
use Domain\Models\Entities\Shop as DomainShop;
|
|
use Domain\Models\ValueObjects\Entities\ShopId;
|
|
use Domain\Ports\Directories\ShopDirectory;
|
|
|
|
class EloquentShopDirectory implements ShopDirectory
|
|
{
|
|
#[\Override]
|
|
public function find(ShopId $id): ?DomainShop
|
|
{
|
|
$shop = Shop::query()
|
|
->where('id', $id->value)
|
|
->first();
|
|
|
|
if (! $shop) {
|
|
return null;
|
|
}
|
|
|
|
return $this->toEntity($shop);
|
|
}
|
|
|
|
#[\Override]
|
|
public function getAll(): array
|
|
{
|
|
return Shop::query()
|
|
->get()
|
|
->map(fn (Shop $shop) => $this->toEntity($shop))
|
|
->all();
|
|
}
|
|
|
|
private function toEntity(Shop $model): DomainShop
|
|
{
|
|
return new DomainShop(
|
|
id: $model->getId(),
|
|
name: $model->name,
|
|
address: $model->address,
|
|
postcode: $model->postcode,
|
|
city: $model->city,
|
|
phone: $model->phone,
|
|
latitude: $model->latitude,
|
|
longitude: $model->longitude,
|
|
isDefault: (bool) $model->default
|
|
);
|
|
}
|
|
}
|