Merging received bidding into the model.
This commit is contained in:
@ -119,7 +119,7 @@ QList<bidding> JsonParser::extractBiddings(const QJsonDocument& jsonDoc) {
|
||||
// REFACTOR implement & use "JsonParser::parseServerResponse(const QJsonObject& object,
|
||||
// QHash<QString, int> 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(),
|
||||
|
||||
@ -240,17 +240,46 @@ void TableModel::setOnlineCredentials(const QString& mail,
|
||||
}
|
||||
|
||||
void TableModel::updateBiddings(const QList<bidding> biddings) {
|
||||
int round = biddings.first().biddingRound;
|
||||
qInfo() << "Updating bidding for round:" << round << "...";
|
||||
QListIterator<bidding> 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<int, QVariant> 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);
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <QUuid>
|
||||
|
||||
struct bidding {
|
||||
QUuid userId;
|
||||
QString userId;
|
||||
int biddingRound;
|
||||
int amount;
|
||||
QString depotWishOne;
|
||||
|
||||
Reference in New Issue
Block a user