* @brief Patch any subset of action fields by id. */
| 5033 | * @brief Patch any subset of action fields by id. |
| 5034 | */ |
| 5035 | API::CommandResponse API::Handlers::ProjectHandler::actionUpdate(const QString& id, |
| 5036 | const QJsonObject& params) |
| 5037 | { |
| 5038 | if (!params.contains(QStringLiteral("actionId"))) |
| 5039 | return CommandResponse::makeError( |
| 5040 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: actionId")); |
| 5041 | |
| 5042 | const int actionId = params.value(QStringLiteral("actionId")).toInt(); |
| 5043 | auto& project = DataModel::ProjectModel::instance(); |
| 5044 | const auto& actions = project.actions(); |
| 5045 | if (actionId < 0 || static_cast<size_t>(actionId) >= actions.size()) |
| 5046 | return CommandResponse::makeError( |
| 5047 | id, ErrorCode::InvalidParam, QStringLiteral("Action id not found: %1").arg(actionId)); |
| 5048 | |
| 5049 | DataModel::Action a = actions[actionId]; |
| 5050 | bool rebuildTree = false; |
| 5051 | QSet<QString> consumed{QStringLiteral("actionId")}; |
| 5052 | const auto identityKeyCount = consumed.size(); |
| 5053 | |
| 5054 | const auto take = [&](const QString& key) -> bool { |
| 5055 | if (!params.contains(key)) |
| 5056 | return false; |
| 5057 | |
| 5058 | consumed.insert(key); |
| 5059 | return true; |
| 5060 | }; |
| 5061 | |
| 5062 | if (take(QStringLiteral("title"))) { |
| 5063 | a.title = params.value(QStringLiteral("title")).toString(); |
| 5064 | rebuildTree = true; |
| 5065 | } |
| 5066 | if (take(QStringLiteral("icon"))) { |
| 5067 | a.icon = params.value(QStringLiteral("icon")).toString(); |
| 5068 | rebuildTree = true; |
| 5069 | } |
| 5070 | if (take(QStringLiteral("txData"))) |
| 5071 | a.txData = params.value(QStringLiteral("txData")).toString(); |
| 5072 | |
| 5073 | if (take(QStringLiteral("eolSequence"))) |
| 5074 | a.eolSequence = params.value(QStringLiteral("eolSequence")).toString(); |
| 5075 | |
| 5076 | if (take(QStringLiteral("timerMode"))) |
| 5077 | a.timerMode = |
| 5078 | static_cast<DataModel::TimerMode>(params.value(QStringLiteral("timerMode")).toInt()); |
| 5079 | |
| 5080 | if (take(QStringLiteral("timerIntervalMs"))) |
| 5081 | a.timerIntervalMs = params.value(QStringLiteral("timerIntervalMs")).toInt(); |
| 5082 | |
| 5083 | if (take(QStringLiteral("repeatCount"))) |
| 5084 | a.repeatCount = params.value(QStringLiteral("repeatCount")).toInt(); |
| 5085 | |
| 5086 | if (take(Keys::SourceId)) |
| 5087 | a.sourceId = params.value(Keys::SourceId).toInt(); |
| 5088 | |
| 5089 | if (take(QStringLiteral("txEncoding"))) |
| 5090 | a.txEncoding = params.value(QStringLiteral("txEncoding")).toInt(); |
| 5091 | |
| 5092 | if (take(QStringLiteral("binaryData"))) |
nothing calls this directly
no test coverage detected