mirror of
https://github.com/allankoechke/pocketbase-cpp.git
synced 2026-12-02 01:32:58 +00:00
Refactoring, renaming QPocketBase to PocketBase, aliasing Client to PocketBase as well.
This commit is contained in:
@@ -14,16 +14,10 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
|
||||
|
||||
add_executable(pocketbase-cpp
|
||||
main.cpp
|
||||
sdk/qpocketbase.h sdk/qpocketbase.cpp
|
||||
sdk/client.h sdk/client.cpp
|
||||
# sdk/baseauthstore.h sdk/baseauthstore.cpp
|
||||
# sdk/adminservice.h sdk/adminservice.cpp
|
||||
# sdk/collectionservice.h sdk/collectionservice.cpp
|
||||
# sdk/fileservice.h sdk/fileservice.cpp
|
||||
# sdk/realtimeservice.h sdk/realtimeservice.cpp
|
||||
# sdk/settingsservice.h sdk/settingsservice.cpp
|
||||
# sdk/logservice.h sdk/logservice.cpp
|
||||
# sdk/healthservice.h sdk/healthservice.cpp
|
||||
# sdk/backupservice.h sdk/backupservice.cpp
|
||||
# sdk/recordservice.h sdk/recordservice.cpp
|
||||
# sdk/localauthstore.h sdk/localauthstore.cpp
|
||||
# sdk/utils/basecrudservice.h sdk/utils/basecrudservice.cpp
|
||||
@@ -33,13 +27,8 @@ add_executable(pocketbase-cpp
|
||||
# sdk/utils/baseservice.hpp
|
||||
# sdk/utils/clientresponseerror.h
|
||||
# sdk/utils/crudservice.h sdk/utils/crudservice.cpp
|
||||
# sdk/utils/sseclient.h sdk/utils/sseclient.cpp
|
||||
# sdk/models/AdminModel.h
|
||||
# sdk/models/backupmodel.hpp
|
||||
# sdk/models/collectionmodel.hpp
|
||||
# sdk/models/fileuploadmodel.hpp
|
||||
# sdk/utils/eventloop.h sdk/utils/eventloop.cpp
|
||||
# sdk/event.h sdk/event.cpp
|
||||
# sdk/models/recordmodel.hpp
|
||||
# sdk/utils/utils.h
|
||||
)
|
||||
@@ -50,3 +39,16 @@ install(TARGETS pocketbase-cpp
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
|
||||
# sdk/utils/sseclient.h sdk/utils/sseclient.cpp
|
||||
# sdk/fileservice.h sdk/fileservice.cpp
|
||||
# sdk/realtimeservice.h sdk/realtimeservice.cpp
|
||||
# sdk/settingsservice.h sdk/settingsservice.cpp
|
||||
# sdk/logservice.h sdk/logservice.cpp
|
||||
# sdk/healthservice.h sdk/healthservice.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
|
||||
|
||||
9
main.cpp
9
main.cpp
@@ -1,13 +1,14 @@
|
||||
#include <QCoreApplication>
|
||||
#include "sdk/qpocketbase.h"
|
||||
#include "sdk/RecordService.h"
|
||||
#include "sdk/client.h"
|
||||
// #include "sdk/RecordService.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
QPocketBase client{"http://127.0.0.1:5740/"};
|
||||
qDebug() << client.lang();
|
||||
PocketBase client1{"http://127.0.0.1:5740/"};
|
||||
Client client2{"http://127.0.0.1:5740/"};
|
||||
qDebug() << client1.lang() << client2.lang();
|
||||
// client.collection("users")->authWithPassword("user@email.com", "123456789");
|
||||
|
||||
return a.exec();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "qpocketbase.h"
|
||||
#include "client.h"
|
||||
#include "utils/crudservice.h"
|
||||
#include "models/AdminModel.h"
|
||||
#include "baseauthstore.h"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "qpocketbase.h"
|
||||
#include "client.h"
|
||||
|
||||
QPocketBase::QPocketBase(const QString& baseUrl, const QString& lang, int timeout, QObject* parent)
|
||||
PocketBase::PocketBase(const QString& baseUrl, const QString& lang, int timeout, QObject* parent)
|
||||
: QObject(parent),
|
||||
m_timeout(timeout),
|
||||
m_networkManager(new QNetworkAccessManager(this)),
|
||||
@@ -12,7 +12,7 @@ QPocketBase::QPocketBase(const QString& baseUrl, const QString& lang, int timeou
|
||||
qDebug() << baseUrl;
|
||||
}
|
||||
|
||||
// std::shared_ptr<RecordService> QPocketBase::collection(const QString& idOrName) {
|
||||
// std::shared_ptr<RecordService> PocketBase::collection(const QString& idOrName) {
|
||||
// qDebug() << "Collection init [" << idOrName << "]";
|
||||
// if (!recordServices.contains(idOrName)) {
|
||||
// qDebug() << "[RecordService] No record, creating new one ...";
|
||||
@@ -23,7 +23,7 @@ QPocketBase::QPocketBase(const QString& baseUrl, const QString& lang, int timeou
|
||||
// return recordServices[idOrName];
|
||||
// }
|
||||
|
||||
QString QPocketBase::filter(const QString &expr, const QMap<QString, QVariant> &query) {
|
||||
QString PocketBase::filter(const QString &expr, const QMap<QString, QVariant> &query) {
|
||||
if (query.isEmpty()) {
|
||||
return expr;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ QString QPocketBase::filter(const QString &expr, const QMap<QString, QVariant> &
|
||||
return expr;
|
||||
}
|
||||
|
||||
QUrl QPocketBase::buildUrl(const QString& path) {
|
||||
QUrl PocketBase::buildUrl(const QString& path) {
|
||||
qDebug() << path;
|
||||
qDebug() << "--";
|
||||
// qDebug() << m_baseurl;
|
||||
@@ -61,7 +61,7 @@ QUrl QPocketBase::buildUrl(const QString& path) {
|
||||
return url;
|
||||
}
|
||||
|
||||
QNetworkReply* QPocketBase::send(const QString& path, const QJsonObject params) {
|
||||
QNetworkReply* PocketBase::send(const QString& path, const QJsonObject params) {
|
||||
qDebug() << path;
|
||||
qDebug() << baseUrl();
|
||||
qDebug() << "Accessing the baseURL";
|
||||
@@ -108,7 +108,7 @@ QNetworkReply* QPocketBase::send(const QString& path, const QJsonObject params)
|
||||
return reply;
|
||||
}
|
||||
|
||||
// QUrl QPocketBase::getFileUrl(const RecordService& record, const QString& filename, const QMap<QString, QString>& queryParams) {
|
||||
// QUrl PocketBase::getFileUrl(const RecordService& record, const QString& filename, const QMap<QString, QString>& queryParams) {
|
||||
// // QStringList parts = { "api", "files", QUrl::toPercentEncoding(record.collectionId), QUrl::toPercentEncoding(record.getId()), QUrl::toPercentEncoding(filename) };
|
||||
// // QUrl url = buildUrl(parts.join("/"));
|
||||
// // if (!queryParams.isEmpty()) {
|
||||
@@ -121,7 +121,7 @@ QNetworkReply* QPocketBase::send(const QString& path, const QJsonObject params)
|
||||
// return QUrl{};
|
||||
// }
|
||||
|
||||
QString QPocketBase::getFileToken() {
|
||||
QString PocketBase::getFileToken() {
|
||||
QJsonObject params;
|
||||
params.insert("method", "POST");
|
||||
|
||||
@@ -136,12 +136,12 @@ QString QPocketBase::getFileToken() {
|
||||
return QString(); // Placeholder
|
||||
}
|
||||
|
||||
QString QPocketBase::baseUrl() const
|
||||
QString PocketBase::baseUrl() const
|
||||
{
|
||||
return this->m_baseurl;
|
||||
}
|
||||
|
||||
void QPocketBase::setBaseUrl(const QString &newBaseUrl)
|
||||
void PocketBase::setBaseUrl(const QString &newBaseUrl)
|
||||
{
|
||||
if (m_baseurl == newBaseUrl)
|
||||
return;
|
||||
@@ -151,12 +151,12 @@ void QPocketBase::setBaseUrl(const QString &newBaseUrl)
|
||||
qDebug() << m_baseurl;
|
||||
}
|
||||
|
||||
QString QPocketBase::lang() const
|
||||
QString PocketBase::lang() const
|
||||
{
|
||||
return m_lang;
|
||||
}
|
||||
|
||||
void QPocketBase::setLang(const QString &newLang)
|
||||
void PocketBase::setLang(const QString &newLang)
|
||||
{
|
||||
if (m_lang == newLang)
|
||||
return;
|
||||
57
sdk/client.h
Normal file
57
sdk/client.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QHttpMultiPart>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonDocument>
|
||||
#include <QDebug>
|
||||
|
||||
class PocketBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PocketBase(const QString& baseUrl = "/", const QString& lang = "en-US", int timeout = 120, QObject* parent = nullptr);
|
||||
|
||||
Q_PROPERTY(QString baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged FINAL)
|
||||
Q_PROPERTY(QString lang READ lang WRITE setLang NOTIFY langChanged FINAL)
|
||||
|
||||
// RecordService* collection(const QString& idOrName);
|
||||
// BaseAuthStore* authStore() { return m_authStore; }
|
||||
QNetworkReply* send(const QString& path, const QJsonObject params);
|
||||
|
||||
QString filter(const QString& expr, const QMap<QString, QVariant>& query);
|
||||
QString getFileToken();
|
||||
QUrl buildUrl(const QString& path);
|
||||
|
||||
QString baseUrl() const;
|
||||
void setBaseUrl(const QString &newBaseUrl);
|
||||
|
||||
QString lang() const;
|
||||
void setLang(const QString &newLang);
|
||||
|
||||
signals:
|
||||
void baseUrlChanged();
|
||||
|
||||
void langChanged();
|
||||
|
||||
void requestFinished(QNetworkReply* reply);
|
||||
|
||||
private:
|
||||
int a = 100, b = 12331332;
|
||||
QString m_baseurl, m_lang;
|
||||
int m_timeout;
|
||||
QNetworkAccessManager* m_networkManager;
|
||||
};
|
||||
|
||||
typedef PocketBase Client;
|
||||
|
||||
#endif // CLIENT_H
|
||||
@@ -1,81 +0,0 @@
|
||||
#ifndef QPOCKETBASE_H
|
||||
#define QPOCKETBASE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonDocument>
|
||||
#include <QHttpMultiPart>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
class QPocketBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QPocketBase(const QString& baseUrl = "/", const QString& lang = "en-US", int timeout = 120, QObject* parent = nullptr);
|
||||
|
||||
/// The PocketBase backend base url address (eg. 'http://127.0.0.1:8090').
|
||||
// Q_PROPERTY(QString baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged FINAL)
|
||||
Q_PROPERTY(QString baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged FINAL)
|
||||
|
||||
/// Optional language code (default to `en-US`) that will be sent
|
||||
/// with the requests to the server as `Accept-Language` header.
|
||||
Q_PROPERTY(QString lang READ lang WRITE setLang NOTIFY langChanged FINAL)
|
||||
|
||||
/// Returns the RecordService associated to the specified collection.
|
||||
// RecordService* collection(const QString& idOrName);
|
||||
|
||||
QString filter(const QString& expr, const QMap<QString, QVariant>& query);
|
||||
|
||||
/// Legacy alias of `pb.files.getUrl()`.
|
||||
// QString getFileUrl( RecordModel record, QString filename, QString thumb="", QString token="", QMap<QString, QVariant> query = {} ) {
|
||||
// return m_files.getUrl( record, filename, thumb, token, query );
|
||||
// }
|
||||
|
||||
/// Builds and returns a full request url by safely concatenating
|
||||
/// the provided path to the base url.
|
||||
// QUrl buildUrl(QString path, QMap<QString, QVariant> queryParameters );
|
||||
|
||||
// QUrl getFileUrl(const RecordService& record, const QString& filename, const QMap<QString, QString>& queryParams);
|
||||
|
||||
QString getFileToken();
|
||||
|
||||
QString baseUrl() const;
|
||||
void setBaseUrl(const QString &newBaseUrl);
|
||||
|
||||
QString lang() const;
|
||||
void setLang(const QString &newLang);
|
||||
|
||||
// BaseAuthStore* authStore() { return m_authStore; }
|
||||
|
||||
QNetworkReply* send(const QString& path, const QJsonObject params);
|
||||
|
||||
signals:
|
||||
void baseUrlChanged();
|
||||
|
||||
void langChanged();
|
||||
|
||||
void requestFinished(QNetworkReply* reply);
|
||||
|
||||
private:
|
||||
QUrl buildUrl(const QString& path);
|
||||
|
||||
int a = 100, b = 12331332;
|
||||
QString m_baseurl, m_lang;
|
||||
int m_timeout;
|
||||
QNetworkAccessManager* m_networkManager;
|
||||
};
|
||||
|
||||
#endif // QPOCKETBASE_H
|
||||
@@ -10,10 +10,10 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QEventLoop>
|
||||
#include "qpocketbase.h"
|
||||
#include "client.h"
|
||||
#include "./utils/crudservice.h"
|
||||
#include "models/recordmodel.hpp"
|
||||
#include "utils/utils.h"
|
||||
#include "globals.h"
|
||||
#include "baseauthstore.h"
|
||||
|
||||
class RecordAuthResponse {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "../models/utils/basemodel.h"
|
||||
#include "../models/utils/listresult.h"
|
||||
#include "../models/utils/schemafield.h"
|
||||
#include "../qpocketbase.h"
|
||||
#include "../client.h"
|
||||
|
||||
BaseCrudService::BaseCrudService(QObject* parent)
|
||||
: BaseService(parent) {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "CrudService.h"
|
||||
#include "../qpocketbase.h"
|
||||
#include "../client.h"
|
||||
#include "basecrudservice.h"
|
||||
#include "../models/utils/listresult.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user