On sending (posting) item to the server the generated UUID is added to the local item.
This commit is contained in:
@ -6,20 +6,35 @@
|
||||
#include "../model/metadata.h"
|
||||
|
||||
QList<ModelItemValues> JsonParser::toItemValuesList(const QByteArray& jsonData,
|
||||
const QString& objectName) {
|
||||
const QString& rootValueName) {
|
||||
QList<ModelItemValues> result;
|
||||
|
||||
if (jsonData.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
QJsonArray itemArray = extractItemArray(jsonData, objectName);
|
||||
// NEXT tidy up the following code and encapsulate into functions;
|
||||
|
||||
foreach (QJsonValue value, itemArray) {
|
||||
QJsonObject itemJsonObject = value.toObject();
|
||||
/// check if there is an array or there is only one object inside the root object;
|
||||
// TODO ? rename objectName into jsonValueName?
|
||||
if (rootValueName == ITEMS_KEY_STRING) {
|
||||
QJsonArray itemArray = extractItemArray(jsonData, rootValueName);
|
||||
|
||||
foreach (QJsonValue value, itemArray) {
|
||||
QJsonObject itemJsonObject = value.toObject();
|
||||
ModelItemValues values = jsonObjectToItemValues(itemJsonObject);
|
||||
result.append(values);
|
||||
}
|
||||
}
|
||||
if (rootValueName == ITEM_KEY_STRING) {
|
||||
// QJsonArray itemArray = extractItemArray(jsonData, objectName);
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonData);
|
||||
QJsonObject rootObject = doc.object();
|
||||
QJsonObject itemJsonObject = rootObject.value(rootValueName).toObject();
|
||||
ModelItemValues values = jsonObjectToItemValues(itemJsonObject);
|
||||
result.append(values);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -28,7 +43,7 @@ QByteArray JsonParser::itemValuesListToJson(const QList<ModelItemValues>& itemVa
|
||||
QJsonDocument jsonDoc;
|
||||
QJsonObject rootObject;
|
||||
QJsonArray itemArray;
|
||||
for (const QHash<int, QVariant>& itemValues : itemValuesList) {
|
||||
for (const ModelItemValues& itemValues : itemValuesList) {
|
||||
QJsonObject itemObject;
|
||||
|
||||
QListIterator<UserRoles> i(USER_FACING_ROLES);
|
||||
|
||||
Reference in New Issue
Block a user