- Add `m_pathProfileGetInfo` to retrieve profile country and currency during login. - Update bank profile filtering logic in `BankProfileDAO`, `DeviceSettingsWindow`, and `DeviceWidget` to match the profile country from `SettingsDAO`. - Synchronize material statuses with the server in `toggleMaterial`.
124 lines
3.1 KiB
C++
124 lines
3.1 KiB
C++
#pragma once
|
|
#include <qhttpmultipart.h>
|
|
#include <QJsonArray>
|
|
#include <QNetworkAccessManager>
|
|
#include <QObject>
|
|
#include <QMap>
|
|
|
|
class NetworkService final : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit NetworkService(QObject *parent = nullptr);
|
|
|
|
~NetworkService() override;
|
|
|
|
void setPayload(const QByteArray &json) { m_json = json; }
|
|
|
|
void setDeviceId(const QString &deviceId) {
|
|
m_deviceId = deviceId;
|
|
}
|
|
|
|
void addExtra(const QString &key, const QVariant &value);
|
|
|
|
public slots:
|
|
void postAccountsData();
|
|
|
|
void postBankProfile();
|
|
|
|
void patchBankProfile();
|
|
|
|
void toggleBankProfile();
|
|
|
|
void postMaterial();
|
|
|
|
void toggleMaterial();
|
|
|
|
void postDeviceScreenshot();
|
|
|
|
void getPayments();
|
|
|
|
void postAppStatus();
|
|
|
|
void postEventStatus();
|
|
|
|
void insertTransactionData();
|
|
|
|
void updateTransactionData();
|
|
|
|
void loginAndSetup();
|
|
void syncCurrentProfile();
|
|
|
|
void createDevice();
|
|
|
|
void updateDevice();
|
|
|
|
void getTasks(const QStringList &materialIds = {});
|
|
|
|
void postTaskResult();
|
|
|
|
void postMonitoringLog(const QString &type, const QString &event,
|
|
const QString &message, const QByteArray &image);
|
|
|
|
void postMonitoringDump(const QString &text, const QByteArray &archive,
|
|
const QByteArray &image);
|
|
|
|
void start();
|
|
void stop();
|
|
void disableAllProfilesOnServer();
|
|
void deleteDeviceFromServer();
|
|
|
|
signals:
|
|
void finished();
|
|
void finishedWithResult(int value);
|
|
void tokenRefreshFailed();
|
|
void tasksReceived(QJsonArray tasks);
|
|
|
|
private:
|
|
QByteArray m_json;
|
|
QString m_deviceId;
|
|
QString m_token;
|
|
QString m_accessToken;
|
|
QString m_apiBase;
|
|
QMap<QString, QVariant> m_extraData = {};
|
|
bool m_running = true;
|
|
bool m_tokenErrorShown = false;
|
|
|
|
QString m_urlAccountUpdate;
|
|
QString m_urlPaymentsGet;
|
|
QString m_urlTransactionUpdate;
|
|
QString m_urlAppStatusUpdate;
|
|
QString m_urlTransactionInsert;
|
|
QString m_urlEventStatusUpdate;
|
|
QString m_pathAuthLogin;
|
|
QString m_pathAuthRefresh;
|
|
QString m_pathDesktopCreate;
|
|
QString m_pathDevice;
|
|
QString m_pathDeviceScreenshot;
|
|
QString m_pathBankProfile;
|
|
QString m_pathMaterial;
|
|
QString m_pathGetTasks;
|
|
QString m_pathTaskResult;
|
|
QString m_pathMonitoringLog;
|
|
QString m_pathMonitoringDump;
|
|
QString m_pathCurrentProfile;
|
|
QString m_pathProfileGetInfo;
|
|
bool m_fetchingTasks = false;
|
|
|
|
QNetworkAccessManager *m_manager;
|
|
|
|
QJsonValue post(QHttpMultiPart *multiPart, const QString &path);
|
|
QJsonArray get(const QString &path, const QMap<QString, QString> ¶ms);
|
|
QJsonValue getJson(const QString &path, bool withAuth = false);
|
|
QJsonValue postJson(const QString &path, const QJsonObject &body, bool withAuth = false);
|
|
QJsonValue patchJson(const QString &path, const QJsonObject &body, bool withAuth = false);
|
|
QJsonValue deleteJson(const QString &path, bool withAuth = false);
|
|
|
|
bool refreshToken();
|
|
bool ensureValidToken();
|
|
void scheduleNextRefresh();
|
|
void syncDevicesFromServer(const QString &desktopId);
|
|
void syncBankProfilesFromServer();
|
|
void syncBanksIfEmpty();
|
|
};
|