FemaLocalSoftware/sensorlogervice.h

52 lines
1.4 KiB
C
Raw Normal View History

2024-12-16 08:38:04 +00:00
#ifndef SENSORLOGSSERVICE_H
#define SENSORLOGSSERVICE_H
#include "httpclient.h"
2025-01-07 22:13:48 +00:00
#include "sensorlogs.h"
#include "utils.h"
2024-12-16 08:38:04 +00:00
2025-01-07 22:13:48 +00:00
#include <QJsonArray>
2024-12-16 08:38:04 +00:00
#include <QJsonDocument>
#include <QJsonObject>
#include <QMessageBox>
2025-01-07 22:13:48 +00:00
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QObject>
2024-12-16 08:38:04 +00:00
class SensorLogService : public QObject
{
Q_OBJECT
public:
explicit SensorLogService(HttpClient *client, QObject *parent = nullptr)
2025-01-07 22:13:48 +00:00
: QObject(parent)
, httpClient(client)
{}
2024-12-16 08:38:04 +00:00
2025-01-07 22:13:48 +00:00
SensorLogs getSensorLog(const QString &targetSensorId)
{
QJsonObject responseSettingsJson = httpClient->get(utils::API_URL
+ "/settings/deviceSettings");
2024-12-16 08:38:04 +00:00
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:
2025-01-07 22:13:48 +00:00
HttpClient *httpClient;
2024-12-16 08:38:04 +00:00
};
#endif // SENSORLOGSSERVICE_H