model = new TableModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; // Validação dos campos com Respect Validation try { v::key('table_number', v::alnum(' ')->notEmpty()) ->key('company_id', v::intType()->positive()) ->key('status_status', v::stringType()->notEmpty()) ->assert($body); } catch (ValidationException $e) { return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400); } $tableNumber = $body['table_number']; $companyId = $body['company_id']; $statusStatus = $body['status_status']; $statusId = $this->model->getStatusIdByName($statusStatus); if ($statusId === null) { return ResponseLib::sendFail("Invalid status_status: '{$statusStatus}'", [], "E_VALIDATE")->withStatus(400); } $updated = $this->model->updateTableByNumber((string)$tableNumber, (int)$companyId, $statusId); return $updated ? ResponseLib::sendOk(['updated' => true]) : ResponseLib::sendFail("Failed to update status or table not found", [], "E_DATABASE")->withStatus(404); } }