diff --git a/UIs/BeetRoundWidgets/mainwindow.cpp b/UIs/BeetRoundWidgets/mainwindow.cpp index 5487c98..1fb23d4 100644 --- a/UIs/BeetRoundWidgets/mainwindow.cpp +++ b/UIs/BeetRoundWidgets/mainwindow.cpp @@ -298,24 +298,9 @@ void MainWindow::findItems() { } } -void MainWindow::fetchItems() { - showStatusMessage(tr("Invoked 'Server|Fetch items'")); - emit m_core->fetchItemsFromServer(); -} - -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::fetchCurrentBiddings() { + showStatusMessage(tr("Invoked 'Server|Fetch current biddings'")); + emit m_core->sendGetRequest(GetBiddingsOfHighestRound); } void MainWindow::execSettingsDialog() { @@ -520,25 +505,12 @@ void MainWindow::createEditActions() { } void MainWindow::createServerActions() { - m_fetchItemsAct = make_unique(tr("&Fetch item(s)"), this); - m_fetchItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down)); - m_fetchItemsAct->setStatusTip(tr("Fetches all item on configured server")); - connect(m_fetchItemsAct.get(), &QAction::triggered, this, &MainWindow::fetchItems); - ui->menu_Server->addAction(m_fetchItemsAct.get()); - - m_postItemsAct = make_unique(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(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()); + m_fetchCurrentBiddingsAct = make_unique(tr("&Fetch biddings"), this); + m_fetchCurrentBiddingsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down)); + m_fetchCurrentBiddingsAct->setStatusTip(tr("Fetches all biddings of the current round")); + connect(m_fetchCurrentBiddingsAct.get(), &QAction::triggered, this, + &MainWindow::fetchCurrentBiddings); + ui->menu_Server->addAction(m_fetchCurrentBiddingsAct.get()); } void MainWindow::createToolsActions() { diff --git a/UIs/BeetRoundWidgets/mainwindow.h b/UIs/BeetRoundWidgets/mainwindow.h index 6ad35e4..75f610d 100644 --- a/UIs/BeetRoundWidgets/mainwindow.h +++ b/UIs/BeetRoundWidgets/mainwindow.h @@ -63,9 +63,7 @@ class MainWindow : public QMainWindow { void findItems(); /// 'Server' slots - void fetchItems(); - void postItems(); - void deleteItem(); + void fetchCurrentBiddings(); /// 'Tools' slots void execSettingsDialog(); @@ -97,9 +95,7 @@ class MainWindow : public QMainWindow { unique_ptr m_deleteItemAct; unique_ptr m_findItemAct; /// Server actions - unique_ptr m_fetchItemsAct; - unique_ptr m_postItemsAct; - unique_ptr m_deleteItemsAct; + unique_ptr m_fetchCurrentBiddingsAct; /// View actions unique_ptr m_showModelUndoViewAct; diff --git a/libs/BeetRoundCore/CMakeLists.txt b/libs/BeetRoundCore/CMakeLists.txt index 11492df..a028257 100644 --- a/libs/BeetRoundCore/CMakeLists.txt +++ b/libs/BeetRoundCore/CMakeLists.txt @@ -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 ) diff --git a/libs/BeetRoundCore/genericcore.cpp b/libs/BeetRoundCore/genericcore.cpp index 6403ea5..bc57d80 100644 --- a/libs/BeetRoundCore/genericcore.cpp +++ b/libs/BeetRoundCore/genericcore.cpp @@ -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 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(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(); } diff --git a/libs/BeetRoundCore/genericcore.h b/libs/BeetRoundCore/genericcore.h index 87cc867..afc069c 100644 --- a/libs/BeetRoundCore/genericcore.h +++ b/libs/BeetRoundCore/genericcore.h @@ -4,6 +4,7 @@ #include #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 biddings); signals: void displayStatusMessage(QString message); diff --git a/libs/BeetRoundCore/model/metadata.h b/libs/BeetRoundCore/model/metadata.h index 5b8c471..dbbe9c0 100644 --- a/libs/BeetRoundCore/model/metadata.h +++ b/libs/BeetRoundCore/model/metadata.h @@ -87,7 +87,9 @@ enum GetRequestTypes { GetCurrentBiddingRound, StartNewBiddingRound, RestartLastBiddingRound, - StopCurrentBiddingRound + StopCurrentBiddingRound, + GetBiddingsOfSpecificRound, + GetBiddingsOfHighestRound }; /// functions diff --git a/libs/BeetRoundCore/network/apiroutes.h b/libs/BeetRoundCore/network/apiroutes.h index 1f54111..7e024aa 100644 --- a/libs/BeetRoundCore/network/apiroutes.h +++ b/libs/BeetRoundCore/network/apiroutes.h @@ -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 diff --git a/libs/BeetRoundCore/network/servercommunicator.cpp b/libs/BeetRoundCore/network/servercommunicator.cpp index 4ff6237..45e4a35 100644 --- a/libs/BeetRoundCore/network/servercommunicator.cpp +++ b/libs/BeetRoundCore/network/servercommunicator.cpp @@ -6,6 +6,7 @@ #include #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 biddings{dummyBidding}; + + emit biddingsChanged(roundNumber, biddings); +} diff --git a/libs/BeetRoundCore/network/servercommunicator.h b/libs/BeetRoundCore/network/servercommunicator.h index 30b971e..0f6b3df 100644 --- a/libs/BeetRoundCore/network/servercommunicator.h +++ b/libs/BeetRoundCore/network/servercommunicator.h @@ -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 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 diff --git a/libs/BeetRoundCore/structs.h b/libs/BeetRoundCore/structs.h new file mode 100644 index 0000000..c32bb93 --- /dev/null +++ b/libs/BeetRoundCore/structs.h @@ -0,0 +1,14 @@ +#ifndef STRUCTS_H +#define STRUCTS_H + +#include + +struct bidding { + QUuid userId; + int biddingRound; + int amount; + QString depotWishOne; + QString depotWishTwo; +}; + +#endif // STRUCTS_H