PNP_PIbd-31_Rodionov_I_A_Co.../apiserver.h
2025-01-14 21:28:06 +04:00

53 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef APISERVER_H
#define APISERVER_H
#include <QCoreApplication>
#include <QHttpServer>
#include <QHttpServerResponse>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include "service/businesslogic/devicelogic.h"
#include "service/businesslogic/departmentlogic.h"
#include "service/businesslogic/devicemodellogic.h"
#include "service/businesslogic/devicetypelogic.h"
#include "service/businesslogic/locationlogic.h"
#include "service/businesslogic/manufacturerlogic.h"
class ApiServer
{
public:
ApiServer();
void start(ServiceLoadDB *serviceDB);
private:
QHttpServerResponse handleGetFilteredDevices(const QHttpServerRequest &request);
QHttpServerResponse handleGetAllDepartments(const QHttpServerRequest &request);
QHttpServerResponse handleGetAllDeviceModels(const QHttpServerRequest &request);
QHttpServerResponse handleGetAllDeviceTypes(const QHttpServerRequest &request);
QHttpServerResponse handleGetAllLocations(const QHttpServerRequest &request);
QHttpServerResponse handleGetAllManufacturers(const QHttpServerRequest &request);
QHttpServerResponse handleUpdateDevice(int id, const QHttpServerRequest &request);
template <typename T>
QJsonArray createJsonArray(const QMap<int, T> &items);
template <typename T>
T getQueryParamWithDefault(const QUrlQuery &query, const QString &paramName, const T &defaultValue);
private:
const QSet<QString> validSortOrders = {"Сначала новые", "Сначала старые", "Сначала дешевые", "Сначала дорогие", "Сначала с лайком"};
const QSet<int> validEntityTypeNumbers = {0, 1, 2, 3, 4, 5};
QHttpServer _server;
DeviceLogic *_deviceLogic;
DepartmentLogic *_departmentLogic;
DeviceModelLogic *_deviceModelLogic;
DeviceTypeLogic *_deviceTypeLogic;
LocationLogic *_locationLogic;
ManufacturerLogic *_manufacturerLogic;
};
#endif // APISERVER_H