* @brief Delete a dataset by id, returning the deleted entity + any renumbered peers. */
| 2090 | * @brief Delete a dataset by id, returning the deleted entity + any renumbered peers. |
| 2091 | */ |
| 2092 | API::CommandResponse API::Handlers::ProjectHandler::datasetDelete(const QString& id, |
| 2093 | const QJsonObject& params) |
| 2094 | { |
| 2095 | if (!params.contains(QStringLiteral("groupId"))) |
| 2096 | return CommandResponse::makeError( |
| 2097 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: groupId")); |
| 2098 | |
| 2099 | if (!params.contains(Keys::DatasetId)) |
| 2100 | return CommandResponse::makeError( |
| 2101 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: datasetId")); |
| 2102 | |
| 2103 | const int groupId = params.value(QStringLiteral("groupId")).toInt(); |
| 2104 | const int datasetId = params.value(Keys::DatasetId).toInt(); |
| 2105 | auto& project = DataModel::ProjectModel::instance(); |
| 2106 | const auto& groups = project.groups(); |
| 2107 | if (groupId < 0 || static_cast<size_t>(groupId) >= groups.size()) |
| 2108 | return CommandResponse::makeError( |
| 2109 | id, ErrorCode::InvalidParam, QStringLiteral("Group id not found: %1").arg(groupId)); |
| 2110 | |
| 2111 | if (datasetId < 0 || static_cast<size_t>(datasetId) >= groups[groupId].datasets.size()) |
| 2112 | return CommandResponse::makeError(id, |
| 2113 | ErrorCode::InvalidParam, |
| 2114 | QStringLiteral("Dataset id not found: %1 in group %2") |
| 2115 | .arg(QString::number(datasetId), QString::number(groupId))); |
| 2116 | |
| 2117 | const auto& targetGroup = groups[groupId]; |
| 2118 | const auto& targetDataset = targetGroup.datasets[datasetId]; |
| 2119 | |
| 2120 | QJsonObject deleted; |
| 2121 | deleted[QStringLiteral("groupId")] = groupId; |
| 2122 | deleted[QStringLiteral("groupTitle")] = targetGroup.title; |
| 2123 | deleted[Keys::DatasetId] = datasetId; |
| 2124 | deleted[Keys::UniqueId] = targetDataset.uniqueId; |
| 2125 | deleted[QStringLiteral("title")] = targetDataset.title; |
| 2126 | if (!targetDataset.units.isEmpty()) |
| 2127 | deleted[QStringLiteral("units")] = targetDataset.units; |
| 2128 | |
| 2129 | if (!targetDataset.transformCode.isEmpty()) { |
| 2130 | deleted[QStringLiteral("hadTransform")] = true; |
| 2131 | deleted[QStringLiteral("transformByteCount")] = targetDataset.transformCode.size(); |
| 2132 | } |
| 2133 | |
| 2134 | const bool isDryRun = params.value(QStringLiteral("dryRun")).toBool(false); |
| 2135 | |
| 2136 | QJsonArray renumbered; |
| 2137 | for (const auto& d : targetGroup.datasets) { |
| 2138 | if (d.datasetId <= datasetId) |
| 2139 | continue; |
| 2140 | |
| 2141 | QJsonObject row; |
| 2142 | row[QStringLiteral("groupId")] = groupId; |
| 2143 | row[QStringLiteral("oldDatasetId")] = d.datasetId; |
| 2144 | row[QStringLiteral("newDatasetId")] = d.datasetId - 1; |
| 2145 | row[Keys::UniqueId] = d.uniqueId; |
| 2146 | row[QStringLiteral("title")] = d.title; |
| 2147 | renumbered.append(row); |
| 2148 | } |
| 2149 |
nothing calls this directly
no test coverage detected