model = new ProductModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; $companyId = $body['company_id'] ?? null; $productName = $body['product_name'] ?? null; $productPrice = $body['product_price'] ?? null; $categoryId = $body['category_id'] ?? null; if (!$companyId || !$productName || !$productPrice || !$categoryId) { return ResponseLib::sendFail("Missing product_name, product_price, category_id or company_id", [], "E_VALIDATE")->withStatus(400); } $created = $this->model->createProduct( $productName, (float)$productPrice, (int)$categoryId, (int)$companyId ); return $created ? ResponseLib::sendOk(['created' => true]) : ResponseLib::sendFail("Failed to Create Product", [], "E_DATABASE")->withStatus(402); } }