| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace Controllers;
- use Libs\ResponseLib;
- use Models\TableModel;
- use Psr\Http\Message\ServerRequestInterface;
- use Respect\Validation\Validator as v;
- use Respect\Validation\Exceptions\ValidationException;
- class TableGetController
- {
- private TableModel $model;
- public function __construct()
- {
- $this->model = new TableModel();
- }
- public function __invoke(ServerRequestInterface $request)
- {
- $body = json_decode((string)$request->getBody(), true) ?? [];
- // Validação do company_id
- try {
- v::key('company_id', v::intType()->positive())
- ->assert($body);
- } catch (ValidationException $e) {
- return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
- }
- $companyId = $body['company_id'];
- $tables = $this->model->getTables((int)$companyId);
- if ($tables) {
- return ResponseLib::sendOk($tables);
- }
- return ResponseLib::sendFail("Table Not Found", [], "E_DATABASE")->withStatus(404);
- }
- }
|