model = new ProductModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; try { v::key('company_id', v::intType()->positive()) ->assert($body); } catch (ValidationException $e) { return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401); } $companyId = (int) $body['company_id']; $products = $this->model->getProducts($companyId); if ($products) { return ResponseLib::sendOk($products); } return ResponseLib::sendFail("Failed to retrieve products", [], "E_DATABASE")->withStatus(500); } }