|
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|
|
namespace Core\Api;
|
|
namespace Core\Api;
|
|
|
|
|
|
|
|
use Core\System\InventoryItem;
|
|
use Core\System\InventoryItem;
|
|
|
|
|
+use Core\System\Notifications;
|
|
|
use PDOException;
|
|
use PDOException;
|
|
|
use Throwable;
|
|
use Throwable;
|
|
|
|
|
|
|
@@ -21,6 +22,10 @@ final class InventoryController extends Controller
|
|
|
private const HTTP_NOT_FOUND = 404;
|
|
private const HTTP_NOT_FOUND = 404;
|
|
|
private const HTTP_CONFLICT = 409;
|
|
private const HTTP_CONFLICT = 409;
|
|
|
private const HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
private const HTTP_UNPROCESSABLE_ENTITY = 422;
|
|
|
|
|
+ private const INVENTORY_PATH = '/inventory';
|
|
|
|
|
+ private const INVENTORY_ITEM_ADDED_NOTIFICATION = 'Inventory item added.';
|
|
|
|
|
+ private const INVENTORY_ITEM_UPDATED_NOTIFICATION = 'Inventory item updated.';
|
|
|
|
|
+ private const INVENTORY_ITEM_DELETED_NOTIFICATION = 'Inventory item deleted.';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* List all inventory items as safe DTOs.
|
|
* List all inventory items as safe DTOs.
|
|
@@ -75,6 +80,7 @@ final class InventoryController extends Controller
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->sendInventoryNotification(self::INVENTORY_ITEM_ADDED_NOTIFICATION);
|
|
|
$this->respond($this->toDto($item), self::HTTP_CREATED);
|
|
$this->respond($this->toDto($item), self::HTTP_CREATED);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -125,6 +131,7 @@ final class InventoryController extends Controller
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->sendInventoryNotification(self::INVENTORY_ITEM_UPDATED_NOTIFICATION);
|
|
|
$this->respond($this->toDto($item), self::HTTP_OK);
|
|
$this->respond($this->toDto($item), self::HTTP_OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -167,9 +174,26 @@ final class InventoryController extends Controller
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->sendInventoryNotification(self::INVENTORY_ITEM_DELETED_NOTIFICATION);
|
|
|
$this->sendJson(['deleted' => true], self::HTTP_OK);
|
|
$this->sendJson(['deleted' => true], self::HTTP_OK);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Records an inventory operation in the shared notification feed.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $caption Notification message describing the completed operation.
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @side-effects Persists a notification and logs a non-blocking persistence failure.
|
|
|
|
|
+ */
|
|
|
|
|
+ private function sendInventoryNotification(string $caption): void
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ (new Notifications())->notify(Notifications::FB_GENERIC, $caption, self::INVENTORY_PATH);
|
|
|
|
|
+ } catch (Throwable $exception) {
|
|
|
|
|
+ error_log(sprintf('Inventory notification persistence failed: %s', $exception->getMessage()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Sends an inventory API response with the standard JSON and cache headers.
|
|
* Sends an inventory API response with the standard JSON and cache headers.
|
|
|
*
|
|
*
|