Fetching current biddings from server menu. No extracting biddings from the response and merging into the model yet.

This commit is contained in:
2026-02-14 10:02:00 +01:00
parent cfd3031cf9
commit 6e51aee3a5
10 changed files with 67 additions and 103 deletions

View File

@ -15,4 +15,6 @@ static const QString ROUTE_START_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/start_
static const QString ROUTE_RESTART_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/restart";
static const QString ROUTE_STOP_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/stop";
static const QString ROUTE_GET_BIDDINGS = apiPrefix + "biddings_of_round";
static const QString ROUTE_GET_BIDDINGS_OF_HIGHEST_ROUND = apiPrefix + "biddings_of_highest_round";
#endif // APIROUTES_H

View File

@ -6,6 +6,7 @@
#include <QRestReply>
#include "../genericcore.h"
#include "../structs.h"
#include "apiroutes.h"
using namespace Qt::StringLiterals;
@ -19,6 +20,7 @@ ServerCommunicator::ServerCommunicator(GenericCore* core)
connect(m_core, &GenericCore::sendGetRequest, this,
&ServerCommunicator::onSendGetRequestTriggered);
connect(this, &ServerCommunicator::biddingsChanged, m_core, &GenericCore::onBiddingsChanged);
}
bool ServerCommunicator::sslSupported() const {
@ -126,6 +128,10 @@ void ServerCommunicator::onSendGetRequestTriggered(const GetRequestTypes type) {
case StopCurrentBiddingRound:
path = ROUTE_STOP_BIDDINGROUND;
break;
// case GetBiddingsOfSpecificRound:
case GetBiddingsOfHighestRound:
path = ROUTE_GET_BIDDINGS_OF_HIGHEST_ROUND;
break;
default:
qWarning() << "No route found for GetRequestType:" << type;
break;
@ -166,6 +172,9 @@ void ServerCommunicator::onGetReplySuccessful(const GetRequestTypes type, const
case StopCurrentBiddingRound:
currentBiddingRoundChangedReply(doc);
break;
case GetBiddingsOfHighestRound:
currentBiddingsReply(doc);
break;
default:
qWarning() << "Can't match request type:" << type;
break;
@ -185,5 +194,22 @@ void ServerCommunicator::currentBiddingRoundChangedReply(const QJsonDocument jso
const bool stopped = rootObject["stopped"].toBool();
const bool isActive = !stopped;
// NOTE ?use ServerCommunicator::currentBiddingRoundChanged signal instead of emiting a signal of
// the core directly?
emit m_core->currentBiddingRoundChanged(roundNumber, isActive);
}
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<bidding> biddings{dummyBidding};
emit biddingsChanged(roundNumber, biddings);
}

View File

@ -9,6 +9,7 @@
#include "../model/metadata.h"
class bidding;
class GenericCore;
class ServerCommunicator : public QObject {
@ -24,7 +25,7 @@ class ServerCommunicator : public QObject {
void setServerConfiguration(const QString url, const QString email, const QString password);
public slots:
void onSendGetRequestTriggered(const GetRequestTypes type);
void onSendGetRequestTriggered(const GetRequestTypes type, QVariant data);
void onGetReplySuccessful(const GetRequestTypes type, const QJsonDocument doc);
void onGetReplyFailure(const GetRequestTypes type, const QString errorString);
@ -42,6 +43,9 @@ class ServerCommunicator : public QObject {
void deleteRequestSuccessful(const QByteArray responseData);
void deleteRequestFailure(const QString errorString);
void currentBiddingRoundChanged(int round, bool isRunning);
void biddingsChanged(int round, QList<bidding> biddings);
private:
GenericCore* m_core = nullptr;
@ -55,6 +59,7 @@ class ServerCommunicator : public QObject {
/// reply parser
void currentBiddingRoundChangedReply(const QJsonDocument jsonDoc);
void currentBiddingsReply(const QJsonDocument jsonDoc);
};
#endif // SERVERCOMMUNICATOR_H