diff --git a/CMakeLists.txt b/CMakeLists.txt index e795afd..8d2fab0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,10 @@ add_executable(pocketbase-cpp sdk/dtos/recordmodel.h sdk/dtos/collectionmodel.h sdk/dtos/AdminModel.h sdk/dtos/logsmodel.h + sdk/services/realtimeservice.h sdk/services/realtimeservice.cpp + sdk/services/sseclient.h sdk/services/sseclient.cpp + sdk/services/eventloop.h sdk/services/eventloop.cpp + sdk/services/event.h sdk/services/event.cpp ) target_link_libraries(pocketbase-cpp Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network) @@ -41,13 +45,10 @@ install(TARGETS pocketbase-cpp ) + # sdk/localauthstore.h sdk/localauthstore.cpp -# sdk/models/utils/schemafield.h sdk/models/utils/schemafield.cpp -# sdk/utils/sseclient.h sdk/utils/sseclient.cpp +# sdk/models/schemafield.h sdk/models/schemafield.cpp # sdk/fileservice.h sdk/fileservice.cpp -# sdk/realtimeservice.h sdk/realtimeservice.cpp # sdk/backupservice.h sdk/backupservice.cpp # sdk/models/backupmodel.hpp # sdk/models/fileuploadmodel.hpp - # sdk/utils/eventloop.h sdk/utils/eventloop.cpp - # sdk/event.h sdk/event.cpp diff --git a/sdk/services/_pending/adminservice.h b/sdk/services/_pending/adminservice.h deleted file mode 100644 index f1e601c..0000000 --- a/sdk/services/_pending/adminservice.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef ADMINSERVICE_H -#define ADMINSERVICE_H - -#include -#include -#include -#include -#include - -#include "client.h" -#include "utils/crudservice.h" -#include "models/AdminModel.h" -#include "baseauthstore.h" -#include "recordservice.h" - -class AdminAuthResponse { -public: - AdminAuthResponse(const QString& token, std::shared_ptr admin); - - QString getToken() const; - std::shared_ptr getAdmin() const; - -private: - QString token; - std::shared_ptr admin; -}; - -class AdminService : public CrudService { - Q_OBJECT - -public: - explicit AdminService(QPocketBase* client, QObject* parent = nullptr); - - std::shared_ptr decode(const QJsonObject& data) override; - QString baseCrudPath() const override; - - std::shared_ptr update(const QString& id, const QJsonObject& bodyParams, const QJsonObject& queryParams = QJsonObject()); - bool deleteItem(const QString& id, const QJsonObject& queryParams = QJsonObject()); - - AdminAuthResponse authResponse(const QJsonObject& responseData); - QJsonObject authWithPassword(const QString& email, const QString& password, const QJsonObject& bodyParams = QJsonObject(), const QJsonObject& queryParams = QJsonObject()); - AdminAuthResponse authRefresh(const QJsonObject& bodyParams = QJsonObject(), const QJsonObject& queryParams = QJsonObject()); - bool requestPasswordReset(const QString& email, const QJsonObject& bodyParams = QJsonObject(), const QJsonObject& queryParams = QJsonObject()); - bool confirmPasswordReset(const QString& passwordResetToken, const QString& password, const QString& passwordConfirm, const QJsonObject& bodyParams = QJsonObject(), const QJsonObject& queryParams = QJsonObject()); -}; - - -#endif // ADMINSERVICE_H diff --git a/sdk/services/_pending/collectionservice.cpp b/sdk/services/_pending/collectionservice.cpp deleted file mode 100644 index c5c1c51..0000000 --- a/sdk/services/_pending/collectionservice.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "collectionservice.h" - -CollectionService::CollectionService(QObject *parent) - : QObject{parent} -{} diff --git a/sdk/services/_pending/collectionservice.h b/sdk/services/_pending/collectionservice.h deleted file mode 100644 index 3cb3bc9..0000000 --- a/sdk/services/_pending/collectionservice.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COLLECTIONSERVICE_H -#define COLLECTIONSERVICE_H - -#include - -class CollectionService : public QObject -{ - Q_OBJECT -public: - explicit CollectionService(QObject *parent = nullptr); - -signals: -}; - -#endif // COLLECTIONSERVICE_H diff --git a/sdk/services/_pending/localauthstore.cpp b/sdk/services/_pending/localauthstore.cpp deleted file mode 100644 index 2fece22..0000000 --- a/sdk/services/_pending/localauthstore.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "LocalAuthStore.h" -#include "RecordService.h" -#include "AdminService.h" - -#include -#include -#include -#include -#include - -LocalAuthStore::LocalAuthStore(const QString& filename, const QString& filepath, const QString& baseToken, std::shared_ptr baseModel, QObject* parent) - : BaseAuthStore(baseToken, baseModel, parent), filename(filename), filepath(filepath) { - completeFilepath = QDir(filepath).filePath(filename); -} - -QString LocalAuthStore::token() const { - QVariantMap data = storageGet(completeFilepath); - if (data.isEmpty() || !data.contains("token")) { - return QString(); - } - return data["token"].toString(); -} - -std::shared_ptr LocalAuthStore::model() const { - QVariantMap data = storageGet(completeFilepath); - if (data.isEmpty() || !data.contains("model")) { - return nullptr; - } - // Assuming Record has a method to deserialize from QVariant - // return std::make_shared(data["model"].toMap()); - return std::make_shared(nullptr, ""); -} - -void LocalAuthStore::save(const QString& token, std::shared_ptr model) { - QVariantMap data; - data["token"] = token; - if (model) { - // Assuming Record has a method to serialize to QVariant - // data["model"] = QVariant::fromValue(model->toVariantMap()); - } - - storageSet(completeFilepath, data); - BaseAuthStore::save(token, model); -} - -void LocalAuthStore::clear() { - storageRemove(completeFilepath); - BaseAuthStore::clear(); -} - -void LocalAuthStore::storageSet(const QString& key, const QVariantMap& value) const { - QFile file(key); - if (file.open(QIODevice::WriteOnly)) { - QDataStream out(&file); - out << value; - file.close(); - } -} - -QVariantMap LocalAuthStore::storageGet(const QString& key) const { - QVariantMap value; - QFile file(key); - if (file.exists() && file.open(QIODevice::ReadOnly)) { - QDataStream in(&file); - in >> value; - file.close(); - } - return value; -} - -void LocalAuthStore::storageRemove(const QString& key) const { - QFile file(key); - if (file.exists()) { - file.remove(); - } -} diff --git a/sdk/services/_pending/localauthstore.h b/sdk/services/_pending/localauthstore.h deleted file mode 100644 index a40eff5..0000000 --- a/sdk/services/_pending/localauthstore.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef LOCALAUTHSTORE_H -#define LOCALAUTHSTORE_H - -#include "BaseAuthStore.h" -#include -#include -#include -#include -#include - -class RecordService; -class AdminService; - -class LocalAuthStore : public BaseAuthStore { - Q_OBJECT - -public: - explicit LocalAuthStore(const QString& filename = "pocketbase_auth.data", const QString& filepath = "", const QString& baseToken = "", std::shared_ptr baseModel = nullptr, QObject* parent = nullptr); - - QString token() const; - std::shared_ptr model() const; - - void save(const QString& token = "", std::shared_ptr model = nullptr); - void clear(); - -private: - QString filename; - QString filepath; - QString completeFilepath; - - void storageSet(const QString& key, const QVariantMap& value) const; - QVariantMap storageGet(const QString& key) const; - void storageRemove(const QString& key) const; -}; - -#endif // LOCALAUTHSTORE_H - diff --git a/sdk/services/_pending/event.cpp b/sdk/services/event.cpp similarity index 100% rename from sdk/services/_pending/event.cpp rename to sdk/services/event.cpp diff --git a/sdk/services/_pending/event.h b/sdk/services/event.h similarity index 75% rename from sdk/services/_pending/event.h rename to sdk/services/event.h index daf5e88..cbb7bb7 100644 --- a/sdk/services/_pending/event.h +++ b/sdk/services/event.h @@ -5,7 +5,10 @@ class Event { public: - Event(const QString& id = "", const QString& event = "message", const QString& data = "", int retry = -1); + Event(const QString& id = "", + const QString& event = "message", + const QString& data = "", + int retry = -1); QString getId() const; QString getEvent() const; diff --git a/sdk/services/_pending/eventloop.cpp b/sdk/services/eventloop.cpp similarity index 100% rename from sdk/services/_pending/eventloop.cpp rename to sdk/services/eventloop.cpp diff --git a/sdk/services/_pending/eventloop.h b/sdk/services/eventloop.h similarity index 100% rename from sdk/services/_pending/eventloop.h rename to sdk/services/eventloop.h diff --git a/sdk/services/_pending/realtimeservice.cpp b/sdk/services/realtimeservice.cpp similarity index 100% rename from sdk/services/_pending/realtimeservice.cpp rename to sdk/services/realtimeservice.cpp diff --git a/sdk/services/_pending/realtimeservice.h b/sdk/services/realtimeservice.h similarity index 100% rename from sdk/services/_pending/realtimeservice.h rename to sdk/services/realtimeservice.h diff --git a/sdk/services/_pending/sseclient.cpp b/sdk/services/sseclient.cpp similarity index 82% rename from sdk/services/_pending/sseclient.cpp rename to sdk/services/sseclient.cpp index c2f3ee2..711df97 100644 --- a/sdk/services/_pending/sseclient.cpp +++ b/sdk/services/sseclient.cpp @@ -1,7 +1,13 @@ #include "SSEClient.h" -Event::Event(const QString& id, const QString& event, const QString& data, int retry) - : id(id), event(event), data(data), retry(retry) {} +Event::Event(const QString& id, + const QString& event, + const QString& data, + int retry) + : id(id), + event(event), + data(data), + retry(retry) {} QString Event::getId() const { return id; } @@ -11,7 +17,12 @@ QString Event::getData() const { return data; } int Event::getRetry() const { return retry; } -EventLoop::EventLoop(const QString& url, const QString& method, const QMap& headers, const QByteArray& payload, const QString& encoding, QObject* parent) +EventLoop::EventLoop(const QString& url, + const QString& method, + const QMap& headers, + const QByteArray& payload, + const QString& encoding, + QObject* parent) : QThread(parent), url(url), method(method), @@ -23,7 +34,8 @@ EventLoop::EventLoop(const QString& url, const QString& method, const QMap listener) { +void EventLoop::addListener(const QString& event, + std::function listener) { listeners[event] = listener; } diff --git a/sdk/services/_pending/sseclient.h b/sdk/services/sseclient.h similarity index 62% rename from sdk/services/_pending/sseclient.h rename to sdk/services/sseclient.h index d824ca9..5e43e34 100644 --- a/sdk/services/_pending/sseclient.h +++ b/sdk/services/sseclient.h @@ -13,7 +13,10 @@ class Event : public QObject { Q_OBJECT public: - explicit Event(const QString& id = "", const QString& event = "message", const QString& data = "", int retry = -1); + explicit Event(const QString& id = "", + const QString& event = "message", + const QString& data = "", + int retry = -1); QString getId() const; void setId(const QString& nId) { id = nId; }; @@ -38,7 +41,12 @@ class EventLoop : public QThread { Q_OBJECT public: - explicit EventLoop(const QString& url, const QString& method = "GET", const QMap& headers = {}, const QByteArray& payload = {}, const QString& encoding = "utf-8", QObject* parent = nullptr); + explicit EventLoop(const QString& url, + const QString& method = "GET", + const QMap& headers = {}, + const QByteArray& payload = {}, + const QString& encoding = "utf-8", + QObject* parent = nullptr); void addListener(const QString& event, std::function listener); void removeListener(const QString& event); void run() override; @@ -69,8 +77,14 @@ class SSEClient : public QObject { Q_OBJECT public: - explicit SSEClient(const QString& url, const QString& method = "GET", const QMap& headers = {}, const QByteArray& payload = QByteArray(), const QString& encoding = "utf-8", QObject* parent = nullptr); - void addEventListener(const QString& event, std::function callback); + explicit SSEClient(const QString& url, + const QString& method = "GET", + const QMap& headers = {}, + const QByteArray& payload = QByteArray(), + const QString& encoding = "utf-8", + QObject* parent = nullptr); + void addEventListener(const QString& event, + std::function callback); void removeEventListener(const QString& event); void close();