* @brief Set painter code for a specific group by id. */
| 4638 | * @brief Set painter code for a specific group by id. |
| 4639 | */ |
| 4640 | API::CommandResponse API::Handlers::ProjectHandler::painterSetCode(const QString& id, |
| 4641 | const QJsonObject& params) |
| 4642 | { |
| 4643 | if (!params.contains(QStringLiteral("groupId"))) |
| 4644 | return CommandResponse::makeError( |
| 4645 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: groupId")); |
| 4646 | |
| 4647 | if (!params.contains(QStringLiteral("code"))) |
| 4648 | return CommandResponse::makeError( |
| 4649 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: code")); |
| 4650 | |
| 4651 | const int groupId = params.value(QStringLiteral("groupId")).toInt(); |
| 4652 | const QString code = params.value(QStringLiteral("code")).toString(); |
| 4653 | auto& project = DataModel::ProjectModel::instance(); |
| 4654 | const auto& groups = project.groups(); |
| 4655 | |
| 4656 | if (groupId < 0 || static_cast<size_t>(groupId) >= groups.size()) |
| 4657 | return CommandResponse::makeError( |
| 4658 | id, ErrorCode::InvalidParam, QStringLiteral("Group id not found: %1").arg(groupId)); |
| 4659 | |
| 4660 | DataModel::Group g = groups[groupId]; |
| 4661 | g.painterCode = code; |
| 4662 | project.updateGroup(groupId, g, true); |
| 4663 | |
| 4664 | QJsonObject result; |
| 4665 | result[QStringLiteral("groupId")] = groupId; |
| 4666 | result[QStringLiteral("codeLength")] = code.size(); |
| 4667 | return CommandResponse::makeSuccess(id, result); |
| 4668 | } |
| 4669 | |
| 4670 | /** |
| 4671 | * @brief Read the painter code for a group. |
nothing calls this directly
no test coverage detected