Commit bcfa4d6f authored by Volker Krause's avatar Volker Krause

Remove some code duplication

This now leaves us with exactly one path for adding or changing
reservations.
parent 6c43ad3a
......@@ -144,12 +144,8 @@ void ReservationManager::importReservations(const QVector<QVariant> &resData)
postproc.setContextDate(QDateTime(QDate::currentDate(), QTime(0, 0)));
postproc.process(resData);
const QString basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/reservations/");
QDir::root().mkpath(basePath);
for (auto res : postproc.result()) {
QString resId;
bool oldResFound = false;
// check if we know this one already, and update if that's the case
for (const auto &oldResId : reservations()) {
......@@ -157,28 +153,14 @@ void ReservationManager::importReservations(const QVector<QVariant> &resData)
if (MergeUtil::isSame(oldRes, res)) {
res = JsonLdDocument::apply(oldRes, res);
resId = oldResId;
oldResFound = true;
break;
}
}
if (resId.isEmpty()) {
resId = QUuid::createUuid().toString();
}
const QString path = basePath + resId + QLatin1String(".jsonld");
QFile f(path);
if (!f.open(QFile::WriteOnly)) {
qCWarning(Log) << "Unable to create file:" << f.errorString();
continue;
}
f.write(QJsonDocument(JsonLdDocument::toJson({res})).toJson());
m_reservations.insert(resId, res);
if (oldResFound) {
emit reservationUpdated(resId);
addReservation(res);
} else {
emit reservationAdded(resId);
updateReservation(resId, res);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment