refactor(backend): reorganize domains into Core, Commerce, Ticketing and Shared
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Purchase\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class InsufficientStockException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* @param array<int, array{
|
||||
* index: int,
|
||||
* catalog_item_id: int,
|
||||
* variant_id: int|null,
|
||||
* requested_quantity: int,
|
||||
* available_quantity: int,
|
||||
* message: string
|
||||
* }> $unavailableItems
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $unavailableItems,
|
||||
) {
|
||||
parent::__construct(
|
||||
collect($unavailableItems)->pluck('message')->unique()->implode(' '),
|
||||
);
|
||||
}
|
||||
|
||||
/** @return array<string, array<int, string>> */
|
||||
public function errors(): array
|
||||
{
|
||||
return collect($this->unavailableItems)
|
||||
->mapWithKeys(fn (array $item): array => [
|
||||
"direct_items.{$item['index']}.cantidad" => [$item['message']],
|
||||
])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Purchase\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class PurchaseExpiredException extends RuntimeException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(__('api.purchase.expired'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Purchase\Exceptions;
|
||||
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PurchaseLimitExceededException extends ValidationException
|
||||
{
|
||||
public readonly int $catalogItemId;
|
||||
|
||||
public readonly string $catalogItemName;
|
||||
|
||||
public readonly int $maximumAddableQuantity;
|
||||
|
||||
public function __construct(CatalogItem $catalogItem, int $maximumAddableQuantity, string $field)
|
||||
{
|
||||
$this->catalogItemId = (int) $catalogItem->getKey();
|
||||
$this->catalogItemName = $catalogItem->nombre;
|
||||
$this->maximumAddableQuantity = $maximumAddableQuantity;
|
||||
|
||||
parent::__construct(validator([], []));
|
||||
|
||||
$message = trans_choice('api.purchase_limit.exceeded', $maximumAddableQuantity, [
|
||||
'max' => $maximumAddableQuantity,
|
||||
'product' => $this->catalogItemName,
|
||||
]);
|
||||
$this->message = $message;
|
||||
$this->validator->errors()->add($field, $message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user