- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees) - Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue) - Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts - Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs - Remove legacy and dead CSV employee import/export code - Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation - Add comprehensive Pest unit, integration, and feature test coverage
120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Infrastructure\Adapters\Repositories;
|
|
|
|
use App\Models\Shop as ModelsShop;
|
|
use Domain\Models\Entities\Shop;
|
|
use Domain\Models\ValueObjects\Entities\ShopId;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Domain\Ports\Repositories\ShopRepository;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class EloquentShopRepository implements ShopRepository
|
|
{
|
|
public function findExceptionShopFor(Matricule $matricule): ?Shop
|
|
{
|
|
$shopId = DB::table('shop_employee_exception')
|
|
->where('matricule', $matricule->value)
|
|
->value('shop_id');
|
|
|
|
if ($shopId !== null) {
|
|
$model = ModelsShop::query()
|
|
->where('id', $shopId)
|
|
->first();
|
|
|
|
return $model ? $this->toDomain($model) : null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function findShopForSiteAndService(ShopperSiteCode $siteCode, ?ShopperServiceCode $serviceCode): ?Shop
|
|
{
|
|
$query = DB::table('shop_employees')
|
|
->where('site_code', $siteCode->value);
|
|
|
|
if ($serviceCode !== null) {
|
|
$query->where('service_code', $serviceCode->value);
|
|
} else {
|
|
$query->whereNull('service_code');
|
|
}
|
|
|
|
$shopId = $query->value('shop_id');
|
|
|
|
if ($shopId !== null) {
|
|
$model = ModelsShop::query()
|
|
->where('id', $shopId)
|
|
->first();
|
|
|
|
return $model ? $this->toDomain($model) : null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function find(ShopId $id): ?Shop
|
|
{
|
|
$model = ModelsShop::query()
|
|
->where('id', $id->value)
|
|
->first();
|
|
|
|
return $model ? $this->toDomain($model) : null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function persist(Shop $entity): void
|
|
{
|
|
$model = ModelsShop::query()
|
|
->where('id', $entity->id()->value->toString())
|
|
->firstOrNew();
|
|
|
|
$model->id = $entity->id()->value->toString();
|
|
$model->name = $entity->name;
|
|
$model->address = $entity->address;
|
|
$model->postcode = $entity->postcode;
|
|
$model->city = $entity->city;
|
|
$model->phone = $entity->phone;
|
|
$model->latitude = $entity->latitude;
|
|
$model->longitude = $entity->longitude;
|
|
$model->default = $entity->isDefault;
|
|
|
|
$model->save();
|
|
}
|
|
|
|
#[\Override]
|
|
public function delete(Shop $entity): void
|
|
{
|
|
ModelsShop::query()
|
|
->where('id', $entity->id()->value)
|
|
->delete();
|
|
}
|
|
|
|
public function getDefaultShop(): Shop
|
|
{
|
|
$model = ModelsShop::query()
|
|
->where('default', true)
|
|
->firstOrFail();
|
|
|
|
return $this->toDomain($model);
|
|
}
|
|
|
|
private function toDomain(ModelsShop $model): Shop
|
|
{
|
|
return new Shop(
|
|
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
|
|
);
|
|
}
|
|
}
|