FemaLocalSoftware/sensorlogervice.h
lopata29435_NSK 3af06d02ec finish
2025-01-08 05:13:48 +07:00

52 lines
1.4 KiB
C++

#ifndef SENSORLOGSSERVICE_H
#define SENSORLOGSSERVICE_H
#include "httpclient.h"
#include "sensorlogs.h"
#include "utils.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QObject>
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