| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace Controllers;
- use Libs\ResponseLib;
- use Models\ProductModel;
- use Psr\Http\Message\ServerRequestInterface;
- class ProductGetController
- {
- private ProductModel $model;
- public function __construct()
- {
- $this->model = new ProductModel();
- }
- public function __invoke(ServerRequestInterface $request)
- {
- $body = json_decode((string)$request->getBody(), true) ?? [];
- $companyId = $body['company_id'] ?? null;
- if (!$companyId) {
- return ResponseLib::sendFail("Missing Company ID", [], "E_VALIDATE")->withStatus(401);
- }
- $products = $this->model->getProducts($companyId);
-
- if ($products) {
- return ResponseLib::sendOk($products);
- }
- return ResponseLib::sendFail("Failed to retrieve products", [], "E_DATABASE")->withStatus(500);
- }
- }
|