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,
|
// REFACTOR implement & use "JsonParser::parseServerResponse(const QJsonObject& object,
|
||||||
// QHash<QString, int> entries)"
|
// QHash<QString, int> entries)"
|
||||||
QJsonObject itemJsonObject = value.toObject();
|
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(),
|
.biddingRound = itemJsonObject.value("bidding_round").toInt(),
|
||||||
.amount = itemJsonObject.value("amount").toInt(),
|
.amount = itemJsonObject.value("amount").toInt(),
|
||||||
.depotWishOne = itemJsonObject.value("depot_wish_one").toString(),
|
.depotWishOne = itemJsonObject.value("depot_wish_one").toString(),
|
||||||
|
|||||||
@ -240,17 +240,46 @@ void TableModel::setOnlineCredentials(const QString& mail,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TableModel::updateBiddings(const QList<bidding> biddings) {
|
void TableModel::updateBiddings(const QList<bidding> biddings) {
|
||||||
int round = biddings.first().biddingRound;
|
|
||||||
qInfo() << "Updating bidding for round:" << round << "...";
|
|
||||||
QListIterator<bidding> i(biddings);
|
QListIterator<bidding> i(biddings);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
const bidding localBidding = i.next();
|
const bidding localBidding = i.next();
|
||||||
qWarning() << "Processing bidding:";
|
qInfo() << "Processing bidding:";
|
||||||
qInfo() << "localBidding.userId:" << localBidding.userId;
|
|
||||||
qDebug() << "localBidding.biddingRound:" << localBidding.biddingRound;
|
const int biddingRound = localBidding.biddingRound;
|
||||||
qDebug() << "localBidding.amount:" << localBidding.amount;
|
|
||||||
qDebug() << "localBidding.depotWishOne:" << localBidding.depotWishOne;
|
if (biddingRound == 0 || biddingRound > 3) {
|
||||||
qDebug() << "localBidding.depotWishTwo:" << localBidding.depotWishTwo;
|
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()) {
|
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();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
const QModelIndex itemIndex = index(itemRow, 0);
|
const QModelIndex itemIndex = index(itemRow, 0);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
struct bidding {
|
struct bidding {
|
||||||
QUuid userId;
|
QString userId;
|
||||||
int biddingRound;
|
int biddingRound;
|
||||||
int amount;
|
int amount;
|
||||||
QString depotWishOne;
|
QString depotWishOne;
|
||||||
|
|||||||
Reference in New Issue
Block a user