FemaLocalSoftware/sensorlogervice.h
Lopata PC 9e459078e1 SensorTab all Done
paginationBar Done
2024-12-16 11:38:04 +03:00

48 lines
1.3 KiB
C++

#ifndef SENSORLOGSSERVICE_H
#define SENSORLOGSSERVICE_H
#include "utils.h"
#include "sensorlogs.h"
#include "httpclient.h"
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMessageBox>
#include <QJsonArray>
class SensorLogService : public QObject
{
Q_OBJECT
public:
explicit SensorLogService(HttpClient *client, QObject *parent = nullptr)
: QObject(parent), httpClient(client) {}
SensorLogs getSensorLog(const QString &targetSensorId) {
QJsonObject responseSettingsJson = httpClient->get(utils::API_URL + "/settings/deviceSettings");
QJsonObject sensors = responseSettingsJson["SENSORS"].toObject();
for (const QString &groupKey : sensors.keys()) {
QJsonObject groupData = sensors[groupKey].toObject();
for (const QString &sensorKey : groupData.keys()) {
if (sensorKey == targetSensorId) {
QJsonObject sensorData = groupData[sensorKey].toObject();
SensorLogs sensorLogs;
sensorLogs.SensorLogsParse(sensorData);
return sensorLogs;
}
}
}
return {};
}
private:
HttpClient* httpClient;
};
#endif // SENSORLOGSSERVICE_H