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

@ -298,24 +298,9 @@ void MainWindow::findItems() {
} }
} }
void MainWindow::fetchItems() { void MainWindow::fetchCurrentBiddings() {
showStatusMessage(tr("Invoked 'Server|Fetch items'")); showStatusMessage(tr("Invoked 'Server|Fetch current biddings'"));
emit m_core->fetchItemsFromServer(); emit m_core->sendGetRequest(GetBiddingsOfHighestRound);
}
void MainWindow::postItems() {
showStatusMessage(tr("Invoked 'Server|Post items'"));
const QModelIndex currentIndex = ui->tableView->currentIndex();
const QByteArray jsonData = m_proxyModel->jsonDataForServer(currentIndex);
emit m_core->postItemToServer(jsonData);
}
void MainWindow::deleteItem() {
showStatusMessage(tr("Invoked 'Server|Delete items'"));
const QModelIndex currentIndex = ui->tableView->currentIndex();
// const QByteArray jsonData = m_proxyModel->jsonDataForServer(currentIndex);
const QString currentId = m_proxyModel->getUuid(currentIndex);
emit m_core->deleteItemFromServer(currentId);
} }
void MainWindow::execSettingsDialog() { void MainWindow::execSettingsDialog() {
@ -520,25 +505,12 @@ void MainWindow::createEditActions() {
} }
void MainWindow::createServerActions() { void MainWindow::createServerActions() {
m_fetchItemsAct = make_unique<QAction>(tr("&Fetch item(s)"), this); m_fetchCurrentBiddingsAct = make_unique<QAction>(tr("&Fetch biddings"), this);
m_fetchItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down)); m_fetchCurrentBiddingsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down));
m_fetchItemsAct->setStatusTip(tr("Fetches all item on configured server")); m_fetchCurrentBiddingsAct->setStatusTip(tr("Fetches all biddings of the current round"));
connect(m_fetchItemsAct.get(), &QAction::triggered, this, &MainWindow::fetchItems); connect(m_fetchCurrentBiddingsAct.get(), &QAction::triggered, this,
ui->menu_Server->addAction(m_fetchItemsAct.get()); &MainWindow::fetchCurrentBiddings);
ui->menu_Server->addAction(m_fetchCurrentBiddingsAct.get());
m_postItemsAct = make_unique<QAction>(tr("&Post item(s)"), this);
m_postItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Up));
// m_postItemsAct->setStatusTip(tr("Posts the selected items on configured server"));
m_postItemsAct->setStatusTip(tr("Posts the current item on configured server"));
connect(m_postItemsAct.get(), &QAction::triggered, this, &MainWindow::postItems);
ui->menu_Server->addAction(m_postItemsAct.get());
m_deleteItemsAct = make_unique<QAction>(tr("&Delete item"), this);
m_deleteItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Backspace));
// m_deleteItemsAct->setStatusTip(tr("Deletes the selected items on configured server"));
m_deleteItemsAct->setStatusTip(tr("Deletes the current item on configured server"));
connect(m_deleteItemsAct.get(), &QAction::triggered, this, &MainWindow::deleteItem);
ui->menu_Server->addAction(m_deleteItemsAct.get());
} }
void MainWindow::createToolsActions() { void MainWindow::createToolsActions() {

View File

@ -63,9 +63,7 @@ class MainWindow : public QMainWindow {
void findItems(); void findItems();
/// 'Server' slots /// 'Server' slots
void fetchItems(); void fetchCurrentBiddings();
void postItems();
void deleteItem();
/// 'Tools' slots /// 'Tools' slots
void execSettingsDialog(); void execSettingsDialog();
@ -97,9 +95,7 @@ class MainWindow : public QMainWindow {
unique_ptr<QAction> m_deleteItemAct; unique_ptr<QAction> m_deleteItemAct;
unique_ptr<QAction> m_findItemAct; unique_ptr<QAction> m_findItemAct;
/// Server actions /// Server actions
unique_ptr<QAction> m_fetchItemsAct; unique_ptr<QAction> m_fetchCurrentBiddingsAct;
unique_ptr<QAction> m_postItemsAct;
unique_ptr<QAction> m_deleteItemsAct;
/// View actions /// View actions
unique_ptr<QAction> m_showModelUndoViewAct; unique_ptr<QAction> m_showModelUndoViewAct;

View File

@ -36,6 +36,7 @@ add_library(${TARGET_APP} STATIC
model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp
network/servercommunicator.h network/servercommunicator.cpp network/servercommunicator.h network/servercommunicator.cpp
network/apiroutes.h network/apiroutes.h
structs.h
# 3rd party libraries # 3rd party libraries
../3rdParty/rapidcsv/src/rapidcsv.h ../3rdParty/rapidcsv/src/rapidcsv.h
) )

View File

@ -155,36 +155,8 @@ bool GenericCore::isSyncServerSetup() const {
} }
} }
void GenericCore::onSendItemTriggered(const QByteArray& jsonData) { void GenericCore::onBiddingsChanged(int round, QList<bidding> biddings) {
m_serverCommunicator->postItems(jsonData); qInfo() << "onBiddingsChanged: round:" << round << "- biddings:" << biddings.count();
}
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::setupModels() { void GenericCore::setupModels() {
@ -246,27 +218,6 @@ QString GenericCore::getMaintenanceToolFilePath() const {
void GenericCore::setupServerConfiguration() { void GenericCore::setupServerConfiguration() {
m_serverCommunicator = make_unique<ServerCommunicator>(this); 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(); applyServerConfiguration();
} }

View File

@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include "model/metadata.h" #include "model/metadata.h"
#include "structs.h"
class QUndoStack; class QUndoStack;
class QAbstractItemModel; class QAbstractItemModel;
@ -40,13 +41,7 @@ class GenericCore : public QObject {
bool isSyncServerSetup() const; bool isSyncServerSetup() const;
public slots: public slots:
void onSendItemTriggered(const QByteArray& jsonData); void onBiddingsChanged(int round, QList<bidding> biddings);
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);
signals: signals:
void displayStatusMessage(QString message); void displayStatusMessage(QString message);

View File

@ -87,7 +87,9 @@ enum GetRequestTypes {
GetCurrentBiddingRound, GetCurrentBiddingRound,
StartNewBiddingRound, StartNewBiddingRound,
RestartLastBiddingRound, RestartLastBiddingRound,
StopCurrentBiddingRound StopCurrentBiddingRound,
GetBiddingsOfSpecificRound,
GetBiddingsOfHighestRound
}; };
/// functions /// functions

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_RESTART_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/restart";
static const QString ROUTE_STOP_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/stop"; 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 #endif // APIROUTES_H

View File

@ -6,6 +6,7 @@
#include <QRestReply> #include <QRestReply>
#include "../genericcore.h" #include "../genericcore.h"
#include "../structs.h"
#include "apiroutes.h" #include "apiroutes.h"
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
@ -19,6 +20,7 @@ ServerCommunicator::ServerCommunicator(GenericCore* core)
connect(m_core, &GenericCore::sendGetRequest, this, connect(m_core, &GenericCore::sendGetRequest, this,
&ServerCommunicator::onSendGetRequestTriggered); &ServerCommunicator::onSendGetRequestTriggered);
connect(this, &ServerCommunicator::biddingsChanged, m_core, &GenericCore::onBiddingsChanged);
} }
bool ServerCommunicator::sslSupported() const { bool ServerCommunicator::sslSupported() const {
@ -126,6 +128,10 @@ void ServerCommunicator::onSendGetRequestTriggered(const GetRequestTypes type) {
case StopCurrentBiddingRound: case StopCurrentBiddingRound:
path = ROUTE_STOP_BIDDINGROUND; path = ROUTE_STOP_BIDDINGROUND;
break; break;
// case GetBiddingsOfSpecificRound:
case GetBiddingsOfHighestRound:
path = ROUTE_GET_BIDDINGS_OF_HIGHEST_ROUND;
break;
default: default:
qWarning() << "No route found for GetRequestType:" << type; qWarning() << "No route found for GetRequestType:" << type;
break; break;
@ -166,6 +172,9 @@ void ServerCommunicator::onGetReplySuccessful(const GetRequestTypes type, const
case StopCurrentBiddingRound: case StopCurrentBiddingRound:
currentBiddingRoundChangedReply(doc); currentBiddingRoundChangedReply(doc);
break; break;
case GetBiddingsOfHighestRound:
currentBiddingsReply(doc);
break;
default: default:
qWarning() << "Can't match request type:" << type; qWarning() << "Can't match request type:" << type;
break; break;
@ -185,5 +194,22 @@ void ServerCommunicator::currentBiddingRoundChangedReply(const QJsonDocument jso
const bool stopped = rootObject["stopped"].toBool(); const bool stopped = rootObject["stopped"].toBool();
const bool isActive = !stopped; const bool isActive = !stopped;
// NOTE ?use ServerCommunicator::currentBiddingRoundChanged signal instead of emiting a signal of
// the core directly?
emit m_core->currentBiddingRoundChanged(roundNumber, isActive); 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" #include "../model/metadata.h"
class bidding;
class GenericCore; class GenericCore;
class ServerCommunicator : public QObject { class ServerCommunicator : public QObject {
@ -24,7 +25,7 @@ class ServerCommunicator : public QObject {
void setServerConfiguration(const QString url, const QString email, const QString password); void setServerConfiguration(const QString url, const QString email, const QString password);
public slots: public slots:
void onSendGetRequestTriggered(const GetRequestTypes type); void onSendGetRequestTriggered(const GetRequestTypes type, QVariant data);
void onGetReplySuccessful(const GetRequestTypes type, const QJsonDocument doc); void onGetReplySuccessful(const GetRequestTypes type, const QJsonDocument doc);
void onGetReplyFailure(const GetRequestTypes type, const QString errorString); void onGetReplyFailure(const GetRequestTypes type, const QString errorString);
@ -42,6 +43,9 @@ class ServerCommunicator : public QObject {
void deleteRequestSuccessful(const QByteArray responseData); void deleteRequestSuccessful(const QByteArray responseData);
void deleteRequestFailure(const QString errorString); void deleteRequestFailure(const QString errorString);
void currentBiddingRoundChanged(int round, bool isRunning);
void biddingsChanged(int round, QList<bidding> biddings);
private: private:
GenericCore* m_core = nullptr; GenericCore* m_core = nullptr;
@ -55,6 +59,7 @@ class ServerCommunicator : public QObject {
/// reply parser /// reply parser
void currentBiddingRoundChangedReply(const QJsonDocument jsonDoc); void currentBiddingRoundChangedReply(const QJsonDocument jsonDoc);
void currentBiddingsReply(const QJsonDocument jsonDoc);
}; };
#endif // SERVERCOMMUNICATOR_H #endif // SERVERCOMMUNICATOR_H

View 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