2026-09-30 11:20:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
namespace App\Cqs\Actions\Shops;
|
2026-09-30 11:20:39 +02:00
|
|
|
|
|
|
|
|
use App\Contracts\Action;
|
|
|
|
|
use App\Contracts\ActionInput;
|
2026-11-16 01:58:44 +01:00
|
|
|
use App\Models\PickupException;
|
2026-09-30 11:20:39 +02:00
|
|
|
use App\Models\Shop;
|
2026-11-16 01:58:44 +01:00
|
|
|
use Illuminate\Support\Facades\Date;
|
2026-09-30 11:20:39 +02:00
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-10 14:28:00 +01:00
|
|
|
* @implements \App\Contracts\Action<\App\Cqs\Actions\Shops\CreateShopInput, \App\Models\Shop>
|
2026-09-30 11:20:39 +02:00
|
|
|
*/
|
|
|
|
|
final class CreateShop implements Action
|
|
|
|
|
{
|
|
|
|
|
/**
|
2026-11-10 14:28:00 +01:00
|
|
|
* @param \App\Cqs\Actions\Shops\CreateShopInput $input
|
2026-09-30 11:20:39 +02:00
|
|
|
*/
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function __invoke(ActionInput $input): Shop
|
|
|
|
|
{
|
|
|
|
|
Assert::isInstanceOf($input, CreateShopInput::class);
|
|
|
|
|
|
|
|
|
|
$attributes = [
|
|
|
|
|
'name' => $input->name,
|
|
|
|
|
'address' => $input->address,
|
|
|
|
|
'postcode' => $input->postcode,
|
|
|
|
|
'city' => $input->city,
|
|
|
|
|
'phone' => $input->phone?->value,
|
|
|
|
|
'latitude' => $input->coordinates !== null ? (string) $input->coordinates->latitude : null,
|
|
|
|
|
'longitude' => $input->coordinates !== null ? (string) $input->coordinates->longitude : null,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$shop = new Shop();
|
|
|
|
|
$shop->fill($attributes);
|
|
|
|
|
$shop->default = $input->default;
|
|
|
|
|
$shop->saveOrFail();
|
|
|
|
|
|
2026-11-16 01:58:44 +01:00
|
|
|
$publicHolidays = PickupException::query()
|
|
|
|
|
->where('auto_updated', true)
|
|
|
|
|
->where('date', '>=', Date::now('Europe/Paris')->startOfYear()->format('Y-m-d'))
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
if ($publicHolidays->isNotEmpty()) {
|
|
|
|
|
$shop->pickupExceptions()->syncWithoutDetaching($publicHolidays);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 11:20:39 +02:00
|
|
|
return $shop;
|
|
|
|
|
}
|
|
|
|
|
}
|