From 440333b589ddfb1495664582fcfe9f1572d00408 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Thu, 19 Feb 2026 11:18:46 +0100 Subject: [PATCH] Routing the received biddings to the model. Just debug outputs there yet. --- libs/BeetRoundCore/formats/jsonparser.cpp | 24 +++++++++++++++++++ libs/BeetRoundCore/formats/jsonparser.h | 3 ++- libs/BeetRoundCore/genericcore.cpp | 5 ++-- libs/BeetRoundCore/genericcore.h | 2 +- libs/BeetRoundCore/model/tablemodel.cpp | 23 ++++++++++++++---- libs/BeetRoundCore/model/tablemodel.h | 3 +++ .../network/servercommunicator.cpp | 13 ++++------ .../network/servercommunicator.h | 2 +- 8 files changed, 57 insertions(+), 18 deletions(-) diff --git a/libs/BeetRoundCore/formats/jsonparser.cpp b/libs/BeetRoundCore/formats/jsonparser.cpp index 72bc5ee..192d5a1 100644 --- a/libs/BeetRoundCore/formats/jsonparser.cpp +++ b/libs/BeetRoundCore/formats/jsonparser.cpp @@ -4,6 +4,7 @@ #include #include "../model/metadata.h" +#include "../structs.h" QList JsonParser::toItemValuesList(const QByteArray& jsonData, const QString& rootValueName) { @@ -106,6 +107,29 @@ ModelItemValues JsonParser::serverUserCredentialsToItemValues(const QJsonDocumen return values; } +QList JsonParser::extractBiddings(const QJsonDocument& jsonDoc) { + QList result; + + if (jsonDoc.isEmpty()) { + return result; + } + QJsonArray itemArray = JsonParser::extractItemArray(jsonDoc, "data"); + + foreach (QJsonValue value, itemArray) { + // REFACTOR implement & use "JsonParser::parseServerResponse(const QJsonObject& object, + // QHash entries)" + QJsonObject itemJsonObject = value.toObject(); + bidding values{.userId = QUuid(itemJsonObject.value("user_id").toString()), + .biddingRound = itemJsonObject.value("bidding_round").toInt(), + .amount = itemJsonObject.value("amount").toInt(), + .depotWishOne = itemJsonObject.value("depot_wish_one").toString(), + .depotWishTwo = itemJsonObject.value("depot_wish_two").toString()}; + result.append(values); + } + + return result; +} + QJsonArray JsonParser::extractItemArray(const QJsonDocument& doc, const QString& objectName) { QJsonArray itemArray; if (objectName.isEmpty()) { diff --git a/libs/BeetRoundCore/formats/jsonparser.h b/libs/BeetRoundCore/formats/jsonparser.h index fd97090..d62db09 100644 --- a/libs/BeetRoundCore/formats/jsonparser.h +++ b/libs/BeetRoundCore/formats/jsonparser.h @@ -9,6 +9,7 @@ class QByteArray; class QJsonArray; typedef QMap ModelItemValues; +class bidding; using namespace std; @@ -22,7 +23,7 @@ class JsonParser { const QString& objectName = ""); static ModelItemValues serverUserCredentialsToItemValues(const QJsonDocument& jsonDoc); - + static QList extractBiddings(const QJsonDocument& jsonDoc); // static ModelItemValues parseServerResponse(const QJsonDocument& jsonDoc, // QHash entries); // static ModelItemValues parseServerResponse(const QJsonObject& object, diff --git a/libs/BeetRoundCore/genericcore.cpp b/libs/BeetRoundCore/genericcore.cpp index 6283a50..7aaafcf 100644 --- a/libs/BeetRoundCore/genericcore.cpp +++ b/libs/BeetRoundCore/genericcore.cpp @@ -156,9 +156,10 @@ bool GenericCore::isSyncServerSetup() const { } } -void GenericCore::onBiddingsChanged(int round, QList biddings) { - qInfo() << "onBiddingsChanged: round:" << round << "- biddings:" << biddings.count(); +void GenericCore::onBiddingsChanged(const QList biddings) { + qInfo() << "onBiddingsChanged: biddings:" << biddings.count(); // NEXT merge biddings into model + m_mainModel->updateBiddings(biddings); } void GenericCore::onCreateOnlineAccountTriggered(const QString& mailAddress) { diff --git a/libs/BeetRoundCore/genericcore.h b/libs/BeetRoundCore/genericcore.h index c3e5609..56300bd 100644 --- a/libs/BeetRoundCore/genericcore.h +++ b/libs/BeetRoundCore/genericcore.h @@ -47,7 +47,7 @@ class GenericCore : public QObject { bool isSyncServerSetup() const; public slots: - void onBiddingsChanged(int round, QList biddings); + void onBiddingsChanged(const QList biddings); void onCreateOnlineAccountTriggered(const QString& mailAddress); void onOnlineUserAccountReceived(const QString mailAddress, diff --git a/libs/BeetRoundCore/model/tablemodel.cpp b/libs/BeetRoundCore/model/tablemodel.cpp index 969d82a..581d341 100644 --- a/libs/BeetRoundCore/model/tablemodel.cpp +++ b/libs/BeetRoundCore/model/tablemodel.cpp @@ -1,16 +1,17 @@ #include "tablemodel.h" +#include +#include +#include + #include "../formats/jsonparser.h" +#include "../structs.h" #include "commands/edititemcommand.h" #include "commands/insertrowscommand.h" #include "commands/removerowscommand.h" #include "metadata.h" #include "modelitem.h" -#include -#include -#include - QByteArray TableModel::generateExampleItems() { QJsonDocument doc = QJsonDocument(); QJsonObject rootObject; @@ -238,6 +239,20 @@ void TableModel::setOnlineCredentials(const QString& mail, setItemData(itemIndex, {{OnlineIdRole, uuid}, {AccessCodeRole, token}}); } +void TableModel::updateBiddings(const QList biddings) { + int round = biddings.first().biddingRound; + qInfo() << "Updating bidding for round:" << round << "..."; + QListIterator i(biddings); + while (i.hasNext()) { + const bidding localBidding = i.next(); + qWarning() << "Processing bidding:"; + qInfo() << "localBidding.userId:" << localBidding.userId; + qDebug() << "localBidding.biddingRound:" << localBidding.biddingRound; + qDebug() << "localBidding.amount:" << localBidding.amount; + qDebug() << "localBidding.depotWishOne:" << localBidding.depotWishOne; + qDebug() << "localBidding.depotWishTwo:" << localBidding.depotWishTwo; + } +} bool TableModel::removeRows(int firstRow, int nRows, const QModelIndex& parentIndex) { if (parentIndex != QModelIndex()) { diff --git a/libs/BeetRoundCore/model/tablemodel.h b/libs/BeetRoundCore/model/tablemodel.h index 2303b4b..14e4f5a 100644 --- a/libs/BeetRoundCore/model/tablemodel.h +++ b/libs/BeetRoundCore/model/tablemodel.h @@ -4,6 +4,7 @@ #include #include "metadata.h" +class bidding; class QUndoStack; class ModelItem; @@ -45,6 +46,8 @@ class TableModel : public QAbstractTableModel { bool updateItem(const ModelItemValues& itemValues); void setOnlineCredentials(const QString& mail, const QString& uuid, const QString& token); + void updateBiddings(const QList biddings); + public slots: // bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex()) // override; diff --git a/libs/BeetRoundCore/network/servercommunicator.cpp b/libs/BeetRoundCore/network/servercommunicator.cpp index 2e56259..cf2509f 100644 --- a/libs/BeetRoundCore/network/servercommunicator.cpp +++ b/libs/BeetRoundCore/network/servercommunicator.cpp @@ -194,6 +194,7 @@ void ServerCommunicator::onPostReplyFailure(const PostRequestTypes type, const QString errorString) { const QString message = QString("Request of type %1 returned: %2").arg(QString::number(type), errorString); + // NEXT improve error message to the UI; m_core->displayStatusMessage(message); } @@ -215,15 +216,9 @@ void ServerCommunicator::currentBiddingRoundChangedReply(const QJsonDocument jso void ServerCommunicator::currentBiddingsReply(const QJsonDocument jsonDoc) { qCritical() << "currentBiddingsReply:" << jsonDoc; - // NEXT extract biddings from jsonDoc - const int roundNumber = 0; - const bidding dummyBidding{.userId = QUuid(), - .biddingRound = 0, - .amount = 123, - .depotWishOne = "one", - .depotWishTwo = "two"}; - const QList biddings{dummyBidding}; - emit biddingsChanged(roundNumber, biddings); + const QList biddings = JsonParser::extractBiddings(jsonDoc); + + emit biddingsChanged(biddings); } void ServerCommunicator::onlineUserAccountReply(const QJsonDocument jsonDoc) { diff --git a/libs/BeetRoundCore/network/servercommunicator.h b/libs/BeetRoundCore/network/servercommunicator.h index 1e0bbf6..36da14b 100644 --- a/libs/BeetRoundCore/network/servercommunicator.h +++ b/libs/BeetRoundCore/network/servercommunicator.h @@ -44,7 +44,7 @@ class ServerCommunicator : public QObject { void deleteRequestFailure(const QString errorString); void currentBiddingRoundChanged(int round, bool isRunning); - void biddingsChanged(int round, QList biddings); + void biddingsChanged(QList biddings); void onlineUserAccountReceived(const QString mailAddress, const QString uuid, const QString accessToken);