* @brief Returns the register list for a single table. */
| 349 | * @brief Returns the register list for a single table. |
| 350 | */ |
| 351 | API::CommandResponse API::Handlers::DataTablesHandler::tableGet(const QString& id, |
| 352 | const QJsonObject& params) |
| 353 | { |
| 354 | QString name; |
| 355 | if (!requireString(params, QStringLiteral("name"), name)) |
| 356 | return CommandResponse::makeError( |
| 357 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: name")); |
| 358 | |
| 359 | const auto& tables = DataModel::ProjectModel::instance().tables(); |
| 360 | const auto& folders = DataModel::ProjectModel::instance().editorTableFolders(); |
| 361 | |
| 362 | QString path; |
| 363 | for (const auto& t : tables) { |
| 364 | const QString full = DataModel::tableFullPath(folders, t.parentFolderId, t.name); |
| 365 | if (full == name || t.name == name) { |
| 366 | path = full; |
| 367 | break; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (path.isEmpty()) |
| 372 | return CommandResponse::makeError( |
| 373 | id, ErrorCode::InvalidParam, QStringLiteral("Table not found: %1").arg(name)); |
| 374 | |
| 375 | const auto registers = DataModel::ProjectModel::instance().registersForTable(path); |
| 376 | |
| 377 | QJsonArray arr = QJsonArray::fromVariantList(registers); |
| 378 | |
| 379 | QJsonObject result; |
| 380 | result[QStringLiteral("name")] = name; |
| 381 | result[QStringLiteral("path")] = path; |
| 382 | result[QStringLiteral("registers")] = arr; |
| 383 | return CommandResponse::makeSuccess(id, result); |
| 384 | } |
| 385 | |
| 386 | //-------------------------------------------------------------------------------------------------- |
| 387 | // Table mutations |
nothing calls this directly
no test coverage detected