From d381e1ab8cd83ccb9cefcc3c6414a37f730765c9 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Thu, 19 Feb 2026 13:10:55 +0100 Subject: [PATCH] Merging received bidding into the model. --- libs/BeetRoundCore/formats/jsonparser.cpp | 2 +- libs/BeetRoundCore/model/tablemodel.cpp | 48 ++++++++++++++++++----- libs/BeetRoundCore/structs.h | 2 +- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/libs/BeetRoundCore/formats/jsonparser.cpp b/libs/BeetRoundCore/formats/jsonparser.cpp index 192d5a1..ba35875 100644 --- a/libs/BeetRoundCore/formats/jsonparser.cpp +++ b/libs/BeetRoundCore/formats/jsonparser.cpp @@ -119,7 +119,7 @@ QList JsonParser::extractBiddings(const QJsonDocument& jsonDoc) { // REFACTOR implement & use "JsonParser::parseServerResponse(const QJsonObject& object, // QHash entries)" QJsonObject itemJsonObject = value.toObject(); - bidding values{.userId = QUuid(itemJsonObject.value("user_id").toString()), + bidding values{.userId = itemJsonObject.value("user_id").toString(), .biddingRound = itemJsonObject.value("bidding_round").toInt(), .amount = itemJsonObject.value("amount").toInt(), .depotWishOne = itemJsonObject.value("depot_wish_one").toString(), diff --git a/libs/BeetRoundCore/model/tablemodel.cpp b/libs/BeetRoundCore/model/tablemodel.cpp index 581d341..248b2e3 100644 --- a/libs/BeetRoundCore/model/tablemodel.cpp +++ b/libs/BeetRoundCore/model/tablemodel.cpp @@ -240,17 +240,46 @@ void TableModel::setOnlineCredentials(const QString& mail, } 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; + qInfo() << "Processing bidding:"; + + const int biddingRound = localBidding.biddingRound; + + if (biddingRound == 0 || biddingRound > 3) { + qWarning() << "Bidding round exceeds valid bounds. Ignoring..."; + continue; + } + const QString uuid = localBidding.userId; + + const QModelIndex itemIndex = getIndexByRoleValue(localBidding.userId, OnlineIdRole); + if (itemIndex.isValid()) { + qInfo() << "Found Uuid for user:" << itemIndex.data(MailRole); + + const int amount = localBidding.amount; + const QString depotWishOne = localBidding.depotWishOne; + const QString depotWishTwo = localBidding.depotWishTwo; + + UserRoles biddingRole; + switch (biddingRound) { + case 1: + biddingRole = Bidding1Role; + break; + case 2: + biddingRole = Bidding2Role; + break; + case 3: + biddingRole = Bidding3Role; + break; + default: + break; + } + + QMap values = { + {biddingRole, amount}, {DepotWish1Role, depotWishOne}, {DepotWish2Role, depotWishTwo}}; + setItemData(itemIndex, values); + } } } @@ -618,7 +647,8 @@ QModelIndex TableModel::getIndexByRoleValue(const QString& valueString, const in } } if (itemRow < 0 || itemRow >= m_items.length()) { - qWarning() << "Couldn't find item with mail address:" << valueString << "- Returning..."; + qWarning() << "Couldn't find item with:" << valueString << " matching role" << role + << "- Returning..."; return QModelIndex(); } const QModelIndex itemIndex = index(itemRow, 0); diff --git a/libs/BeetRoundCore/structs.h b/libs/BeetRoundCore/structs.h index c32bb93..9104250 100644 --- a/libs/BeetRoundCore/structs.h +++ b/libs/BeetRoundCore/structs.h @@ -4,7 +4,7 @@ #include struct bidding { - QUuid userId; + QString userId; int biddingRound; int amount; QString depotWishOne;