Fetching current biddings from server menu. No extracting biddings from the response and merging into the model yet.
This commit is contained in:
@ -36,6 +36,7 @@ add_library(${TARGET_APP} STATIC
|
||||
model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp
|
||||
network/servercommunicator.h network/servercommunicator.cpp
|
||||
network/apiroutes.h
|
||||
structs.h
|
||||
# 3rd party libraries
|
||||
../3rdParty/rapidcsv/src/rapidcsv.h
|
||||
)
|
||||
|
||||
@ -155,36 +155,8 @@ bool GenericCore::isSyncServerSetup() const {
|
||||
}
|
||||
}
|
||||
|
||||
void GenericCore::onSendItemTriggered(const QByteArray& jsonData) {
|
||||
m_serverCommunicator->postItems(jsonData);
|
||||
}
|
||||
|
||||
void GenericCore::onItemsFetched(const QByteArray jsonData) {
|
||||
emit displayStatusMessage("New items fetched.");
|
||||
// TODO ? check compability of JSON structure beforehand?
|
||||
// NEXT check if item already exists and apply changes (UUID,...) ? ;
|
||||
m_mainModel->appendItems(jsonData);
|
||||
}
|
||||
|
||||
void GenericCore::onItemsFetchFailure(const QString errorString) {
|
||||
emit displayStatusMessage(QString("Error: %1").arg(errorString));
|
||||
}
|
||||
|
||||
void GenericCore::onPostRequestSuccessful(const QByteArray responseData) {
|
||||
const QString message = m_mainModel->updateItemsFromJson(responseData);
|
||||
emit displayStatusMessage(message);
|
||||
}
|
||||
|
||||
void GenericCore::onPostRequestFailure(const QString errorString) {
|
||||
emit displayStatusMessage(QString("Error: %1").arg(errorString));
|
||||
}
|
||||
|
||||
void GenericCore::onDeleteRequestSuccessful(const QByteArray responseData) {
|
||||
qWarning() << "TODO: Process success response!!!";
|
||||
}
|
||||
|
||||
void GenericCore::onDeleteRequestFailure(const QString errorString) {
|
||||
qWarning() << "TODO: Process error response!!!";
|
||||
void GenericCore::onBiddingsChanged(int round, QList<bidding> biddings) {
|
||||
qInfo() << "onBiddingsChanged: round:" << round << "- biddings:" << biddings.count();
|
||||
}
|
||||
|
||||
void GenericCore::setupModels() {
|
||||
@ -246,27 +218,6 @@ QString GenericCore::getMaintenanceToolFilePath() const {
|
||||
|
||||
void GenericCore::setupServerConfiguration() {
|
||||
m_serverCommunicator = make_unique<ServerCommunicator>(this);
|
||||
/// request connections
|
||||
connect(this, &GenericCore::fetchItemsFromServer, m_serverCommunicator.get(),
|
||||
&ServerCommunicator::fetchItems);
|
||||
connect(this, &GenericCore::postItemToServer, this, &GenericCore::onSendItemTriggered);
|
||||
connect(this, &GenericCore::deleteItemFromServer, m_serverCommunicator.get(),
|
||||
&ServerCommunicator::deleteItem);
|
||||
|
||||
/// response connections
|
||||
connect(m_serverCommunicator.get(), &ServerCommunicator::itemsFetched, this,
|
||||
&GenericCore::onItemsFetched);
|
||||
connect(m_serverCommunicator.get(), &ServerCommunicator::itemsFetchFailure, this,
|
||||
&GenericCore::onItemsFetchFailure);
|
||||
connect(m_serverCommunicator.get(), &ServerCommunicator::postRequestSuccessful, this,
|
||||
&GenericCore::onPostRequestSuccessful);
|
||||
connect(m_serverCommunicator.get(), &ServerCommunicator::postRequestFailure, this,
|
||||
&GenericCore::onPostRequestFailure);
|
||||
connect(m_serverCommunicator.get(), &ServerCommunicator::deleteRequestSuccessful, this,
|
||||
&GenericCore::onDeleteRequestSuccessful);
|
||||
connect(m_serverCommunicator.get(), &ServerCommunicator::deleteRequestFailure, this,
|
||||
&GenericCore::onDeleteRequestFailure);
|
||||
|
||||
applyServerConfiguration();
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "model/metadata.h"
|
||||
#include "structs.h"
|
||||
|
||||
class QUndoStack;
|
||||
class QAbstractItemModel;
|
||||
@ -40,13 +41,7 @@ class GenericCore : public QObject {
|
||||
bool isSyncServerSetup() const;
|
||||
|
||||
public slots:
|
||||
void onSendItemTriggered(const QByteArray& jsonData);
|
||||
void onItemsFetched(const QByteArray jsonData);
|
||||
void onItemsFetchFailure(const QString errorString);
|
||||
void onPostRequestSuccessful(const QByteArray responseData);
|
||||
void onPostRequestFailure(const QString errorString);
|
||||
void onDeleteRequestSuccessful(const QByteArray responseData);
|
||||
void onDeleteRequestFailure(const QString errorString);
|
||||
void onBiddingsChanged(int round, QList<bidding> biddings);
|
||||
|
||||
signals:
|
||||
void displayStatusMessage(QString message);
|
||||
|
||||
@ -87,7 +87,9 @@ enum GetRequestTypes {
|
||||
GetCurrentBiddingRound,
|
||||
StartNewBiddingRound,
|
||||
RestartLastBiddingRound,
|
||||
StopCurrentBiddingRound
|
||||
StopCurrentBiddingRound,
|
||||
GetBiddingsOfSpecificRound,
|
||||
GetBiddingsOfHighestRound
|
||||
};
|
||||
|
||||
/// functions
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
14
libs/BeetRoundCore/structs.h
Normal file
14
libs/BeetRoundCore/structs.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef STRUCTS_H
|
||||
#define STRUCTS_H
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
struct bidding {
|
||||
QUuid userId;
|
||||
int biddingRound;
|
||||
int amount;
|
||||
QString depotWishOne;
|
||||
QString depotWishTwo;
|
||||
};
|
||||
|
||||
#endif // STRUCTS_H
|
||||
Reference in New Issue
Block a user