diff --git a/CMakeLists.txt b/CMakeLists.txt index 008aa81..a3bf6a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ endif() set(HEART_TESTS OFF) add_subdirectory(submodules/Heart) +add_subdirectory(src/db) add_subdirectory(src/core) set(PATRONUM_TESTS OFF) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index f62e278..6c44276 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -29,7 +29,7 @@ if (SECRETSERVICE_TESTS) target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}testcore) endif() -target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core Heart) +target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core "${PROJECT_NAME}DB") target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR}) target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR}) diff --git a/src/core/src/private/keystorage.h b/src/core/src/private/keystorage.h new file mode 100644 index 0000000..758bb44 --- /dev/null +++ b/src/core/src/private/keystorage.h @@ -0,0 +1,65 @@ +//# +//# Copyright (C) 2023-2023 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef KEYSTORAGE_H +#define KEYSTORAGE_H + +#include "qaservice.h" +#include + +namespace QASecret { + +/** + * @brief The KeyStorage class the storage store seccrets values on the simple key - value table. Where value is secrete and key is a sha256(secret) hash. + */ +class KeyStorage: public QuasarAppUtils::Service +{ +public: + KeyStorage(); + + /** + * @brief add adds to storage new value, and return access key. + * @param value This is value to save. + * @param alias This is simple alias for get key. + * @return access key of @a value. + */ + QByteArray add(const QByteArray& value, const QString& alias = {}); + + /** + * @brief remove This method remove secret from storage by key. + * @param key This is sha256 key of secret + */ + void remove(const QByteArray& key); + + /** + * @brief remove This method remove seccret value by alias. + * @param alias + */ + void remove(const QString& alias); + + + /** + * @brief get return value by access key. + * @param key this is access key of value. + * @return secret value + */ + QByteArray get(const QByteArray& key); + + /** + * @brief get return value by alias of key. + * @param key this is access key of value. + * @return secret value + */ + QByteArray get(const QString& alias); + +private: + QHash _storage; + QHash _aliases; + +}; +} +#endif // KEYSTORAGE_H diff --git a/src/db/CMakeLists.txt b/src/db/CMakeLists.txt new file mode 100644 index 0000000..9c2cd97 --- /dev/null +++ b/src/db/CMakeLists.txt @@ -0,0 +1,40 @@ +# +# Copyright (C) 2020-2024 QuasarApp. +# Distributed under the GPLv3 software license, see the accompanying +# Everyone is permitted to copy and distribute verbatim copies +# of this license document, but changing it is not allowed. +# + +cmake_minimum_required(VERSION 3.19) + +set(CURRENT_PROJECT "${PROJECT_NAME}DB") +add_definitions(-DSECRETDB_LIBRARY) + + +file(GLOB_RECURSE SOURCE_CPP + "src/*.cpp" + "src/*.h" +) + +file(GLOB_RECURSE SOURCE_QRC + "*.qrc" +) + +set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/public") +set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/private") + +add_library(${CURRENT_PROJECT} ${SOURCE_CPP} ${SOURCE_QRC}) + + +target_link_libraries(${CURRENT_PROJECT} PUBLIC Heart ) + + +target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR}) +target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR}) + + +prepareQM(${CURRENT_PROJECT} ${CMAKE_CURRENT_SOURCE_DIR} "${LANGS}") + +set(QML_IMPORT_PATH ${QML_IMPORT_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "" FORCE) + +configure_file_in(${CURRENT_PROJECT} "${CMAKE_CURRENT_SOURCE_DIR}/src/public/SecretDB/global.h") diff --git a/src/db/SecretDB.qrc b/src/db/SecretDB.qrc new file mode 100644 index 0000000..2f116b7 --- /dev/null +++ b/src/db/SecretDB.qrc @@ -0,0 +1,8 @@ + + + src/sql/YourTimeDB_1.sql + src/sql/YourTimeDB_2.sql + src/sql/YourTimeDB_3.sql + + + diff --git a/src/db/languages/en.ts b/src/db/languages/en.ts new file mode 100644 index 0000000..6d2eee5 --- /dev/null +++ b/src/db/languages/en.ts @@ -0,0 +1,19 @@ + + + + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + + diff --git a/src/db/languages/ru.ts b/src/db/languages/ru.ts new file mode 100644 index 0000000..098fba2 --- /dev/null +++ b/src/db/languages/ru.ts @@ -0,0 +1,19 @@ + + + + + QuasarAppUtils::Locales + + This bot is still under development. + Этот бот все еще находится в разработке. + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + Мы очень усердно работаем над нашей новой службой доставки, чтобы вам было как можно проще быть с нами, где бы вы ни находились. + + + Thank you for your wait. + Спасибо за ожидание. + + + diff --git a/src/db/languages/sr.ts b/src/db/languages/sr.ts new file mode 100644 index 0000000..3683af4 --- /dev/null +++ b/src/db/languages/sr.ts @@ -0,0 +1,19 @@ + + + + + QuasarAppUtils::Locales + + This bot is still under development. + Ovaj bot je još uvek u razvoju. + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + Radimo veoma naporno na našoj novoj usluzi dostave kako bismo vam učinili što lakšim da budete sa nama gde god da se nalazite. + + + Thank you for your wait. + Hvala vam na čekanju. + + + diff --git a/src/db/languages/sr_ME.ts b/src/db/languages/sr_ME.ts new file mode 100644 index 0000000..59df7ee --- /dev/null +++ b/src/db/languages/sr_ME.ts @@ -0,0 +1,19 @@ + + + + + QuasarAppUtils::Locales + + This bot is still under development. + Ovaj bot je još uvek u razvoju. + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + Radimo veoma naporno na našoj novoj usluzi dostave kako bismo vam učinili što lakšim da budete sa nama gde god da se nalazite. + + + Thank you for your wait. + Hvala vam na čekanju. + + + diff --git a/src/db/languages/uk.ts b/src/db/languages/uk.ts new file mode 100644 index 0000000..e358170 --- /dev/null +++ b/src/db/languages/uk.ts @@ -0,0 +1,19 @@ + + + + + QuasarAppUtils::Locales + + This bot is still under development. + Цей бот ще в розробці. + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + Ми наполегливо працюємо над нашою новою службою доставки, щоб вам було якомога легше бути з нами, де б ви не були. + + + Thank you for your wait. + Дякуємо за очікування. + + + diff --git a/src/db/src/private/image.cpp b/src/db/src/private/image.cpp new file mode 100644 index 0000000..44a694d --- /dev/null +++ b/src/db/src/private/image.cpp @@ -0,0 +1,58 @@ +//# +//# Copyright (C) 2023-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "image.h" + +namespace QASecret { + +Image::Image() {} + +const QString &Image::getId() const { + return _id; +} + +void Image::setId(const QString &id) { + _id = id; +} + +const QByteArray &Image::getImage() const { + return _image; +} + +void Image::setImage(const QByteArray &source) { + _image = source; +} + +QH::PKG::DBObject* Image::createDBObject() const { + return new Image(); +} + +bool Image::fromSqlRecord(const QSqlRecord& q) { + _id = q.value("id").toString(); + _image = q.value("data").toByteArray(); + return true; +} + +QString Image::table() const { + return "Images"; +} + +QH::PKG::DBVariantMap Image::variantMap() const { + return { + {"id", {_id, QH::PKG::MemberType::PrimaryKey}}, + {"data", {_image, QH::PKG::MemberType::InsertUpdate}} + }; +} + +QString Image::primaryKey() const { + return "id"; +} + +QVariant Image::primaryValue() const { + return _id; +} +} diff --git a/src/db/src/private/image.h b/src/db/src/private/image.h new file mode 100644 index 0000000..dcce2a2 --- /dev/null +++ b/src/db/src/private/image.h @@ -0,0 +1,49 @@ +//# +//# Copyright (C) 2023-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#ifndef IMAGE_H +#define IMAGE_H + +#include "dbobject.h" +#include + +#include +#include + +namespace QASecret { + +/** + * @brief The Image class + */ +class Image : public QH::PKG::DBObject, public iImage +{ +public: + Image(); + + // iImage interface + + const QString &getId() const override; + void setId(const QString &id) override; + const QByteArray &getImage() const override; + void setImage(const QByteArray &source) override; + + // DBObject interface + QH::PKG::DBObject* createDBObject() const override; + bool fromSqlRecord(const QSqlRecord& q) override; + QString table() const override; + QH::PKG::DBVariantMap variantMap() const override; + + QString primaryKey() const override; + QVariant primaryValue() const override; + +private: + QString _id; + QByteArray _image; +}; +} +#endif // IMAGE_H diff --git a/src/db/src/private/secretdatabase.cpp b/src/db/src/private/secretdatabase.cpp new file mode 100644 index 0000000..85fa5fd --- /dev/null +++ b/src/db/src/private/secretdatabase.cpp @@ -0,0 +1,257 @@ +//# +//# Copyright (C) 2023-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "botdatabase.h" +#include "image.h" +#include "processedid.h" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace QASecret { + +BotDataBase::BotDataBase() { + + addDBPatch({ + 0, + 1, + [](const QH::iObjectProvider* database) -> bool { + return database->doSql(":/src/sql/YourTimeDB_1.sql"); + } + }); + + addDBPatch({ + 1, + 2, + [](const QH::iObjectProvider* database) -> bool { + return database->doSql(":/src/sql/YourTimeDB_2.sql"); + } + }); + + addDBPatch({ + 2, + 3, + [this](QH::iObjectProvider* database) -> bool { + if (!database->doSql(":/src/sql/YourTimeDB_3.sql")) { + return false; + } + QH::PKG::DBObjectsRequest + request("MenuV0"); + auto&& oldMenu = database->getObject(request); + + for (const auto &oldMenuItem: oldMenu->data()) { + auto&& menuItem = getMenuById(oldMenuItem->getId(), true); + menuItem->setCategory(oldMenuItem->category()); + menuItem->setName(oldMenuItem->getName()); + menuItem->setDescription(oldMenuItem->getDescription()); + menuItem->setPrice(oldMenuItem->getPrice()); + menuItem->setTranslations(oldMenuItem->getTranslations()); + + const auto& image = oldMenuItem->getImage(); + if (image.size()) { + auto&& imageId = QCryptographicHash::hash(image, + QCryptographicHash::Sha256). + toBase64(QByteArray::Base64UrlEncoding); + + auto&& imageObj = getImageById(imageId, true); + imageObj->setImage(image); + + saveImage(imageObj); + + menuItem->setImage(imageId); + } else if (oldMenuItem->getImageSource().size()) { + menuItem->setImage(oldMenuItem->getImageSource()); + } + + saveMenuItem(menuItem); + + } + + return database->doQuery("DROP TABLE MenuV0"); + } + }); +} + +QSet BotDataBase::getProcessedIds() { + QSet result; + QH::PKG::DBObjectsRequest + request("ProcessedIds"); + + auto&& responce = db()->getObject(request); + if (!responce) + return result; + + auto&& resp = responce->data(); + + for (const auto& val: resp) { + result.insert(val->getId()); + } + + return result; +} + +void BotDataBase::addProcessedId(unsigned long long id) { + auto&& idObj = QSharedPointer::create(); + idObj->setId(id); + + db()->insertObject(idObj); +} + +void BotDataBase::removeProcessedId(unsigned long long id) { + auto&& idObj = QSharedPointer::create(); + idObj->setId(id); + + db()->deleteObject(idObj); + +} + +void BotDataBase::setProcessedIds(const QSet &ids) { + auto request = QSharedPointer>::create( + "ProcessedIds"); + + db()->deleteObject(request); + + for (const auto& id : ids) { + addProcessedId(id); + } +} + +QSharedPointer BotDataBase::getUserById(unsigned long long id, bool ifNotExistsCreate) { + return getById(id, &User::setId, ifNotExistsCreate); +} + +QList> BotDataBase::getAllUsers(iRole::RoleName roleName) { + QString condition; + if (roleName != iRole::All) { + condition = QString("role = %0").arg(roleName); + condition = QString("id IN ( SELECT userId FROM Roles WHERE %0 )").arg(condition); + } + + auto&& data = getAll("Users", condition); + return {data.begin(), data.end()}; +} + +void BotDataBase::saveUser(const QSharedPointer& user) { + saveObj(user.dynamicCast()); +} + +void BotDataBase::removeUser(unsigned long long id) { + deleteById(id, &User::setId); +} + +QSharedPointer BotDataBase::getRoleByUserId(unsigned long long userId, bool ifNotExistsCreate) { + return getById(userId, &Role::setUserId, ifNotExistsCreate); +} + +void BotDataBase::saveRole(const QSharedPointer& role) { + saveObj(role.dynamicCast()); +} + +void BotDataBase::removeRole(unsigned long long userId) { + deleteById(userId, &Role::setUserId); +} + +QSharedPointer BotDataBase::getMenuById(int id, bool ifNotExistsCreate) { + return getById(id, &MenuItem::setId, ifNotExistsCreate); +} + +QList> BotDataBase::getAllMenuItems() { + auto&& data = getAll("Menu"); + return {data.begin(), data.end()}; +} + +void BotDataBase::saveMenuItem(const QSharedPointer& menuItem) { + saveObj(menuItem.dynamicCast()); +} + +unsigned int BotDataBase::insertMenuItem(const QSharedPointer &menuItem) { + auto&& resultId = QSharedPointer::create(); + insertObj(menuItem.dynamicCast(), resultId.toWeakRef()); + + return *resultId; +} + +void BotDataBase::removeMenuItem(int id) { + deleteById(id, &MenuItem::setId); +} + +void BotDataBase::clearMenuTable() const { + db()->doQuery("DELETE FROM Menu", {}, true); +} + +QSharedPointer BotDataBase::makeMenuItem() { + if (auto&& menuItem = QSharedPointer::create()) { + menuItem->setId(insertMenuItem(menuItem)); + return std::move(menuItem); + } + + return nullptr; +} + +QSharedPointer BotDataBase::getOrderById(int id, bool ifNotExistsCreate) { + return getById(id, &Order::setId, ifNotExistsCreate); +} + +QList> BotDataBase::getAllOrders(iOrder::State state) { + + QString condition; + if (state != iOrder::All) { + condition = QString("state = %0").arg(state); + } + + auto&& data = getAll("Orders", condition); + return {data.begin(), data.end()}; +} + +void BotDataBase::saveOrder(const QSharedPointer& order) { + saveObj(order.dynamicCast()); +} + +unsigned int BotDataBase::insertOrder(const QSharedPointer &order) { + auto&& resultId = QSharedPointer::create(); + insertObj(order.dynamicCast(), resultId); + + return *resultId; +} + +QSharedPointer BotDataBase::makeOrder() { + if (auto&& newOrder = QSharedPointer::create()) { + newOrder->setId(insertOrder(newOrder)); + return std::move(newOrder); + } + + return nullptr; +} + +void BotDataBase::removeOrder(int id) { + deleteById(id, &Order::setId); +} + +QList > BotDataBase::getAllImages() { + auto&& data = getAll("Images", ""); + return {data.begin(), data.end()}; +} + +QSharedPointer BotDataBase::getImageById(const QString &id, bool ifNotExistsCreate) { + return getById(id, &Image::setId, ifNotExistsCreate); +} + +void BotDataBase::saveImage(const QSharedPointer &image) { + saveObj(image.dynamicCast()); +} + +void BotDataBase::removeImage(const QString &id) { + deleteById(id, &Image::setId); +} + + +} diff --git a/src/db/src/private/secretdatabase.h b/src/db/src/private/secretdatabase.h new file mode 100644 index 0000000..9704912 --- /dev/null +++ b/src/db/src/private/secretdatabase.h @@ -0,0 +1,64 @@ +//# +//# Copyright (C) 2023-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include + +#include + +#ifndef BOTDATABASE_H +#define BOTDATABASE_H + +namespace QASecret { + +class BotDataBase: public IDataBase, public QH::DataBase +{ +public: + BotDataBase(); + + // IDataBase interface +public: + QSet getProcessedIds() override; + void addProcessedId(unsigned long long id) override; + void removeProcessedId(unsigned long long id) override; + void setProcessedIds(const QSet &ids) override; + + QSharedPointer getUserById(unsigned long long id, bool ifNotExistsCreate = false) override; + QList > getAllUsers(iRole::RoleName roleName = iRole::All) override; + void saveUser(const QSharedPointer &user) override; + void removeUser(unsigned long long id) override; + QSharedPointer getRoleByUserId(unsigned long long userId, bool ifNotExistsCreate = false) override; + + void saveRole(const QSharedPointer &role) override; + void removeRole(unsigned long long userId) override; + + QSharedPointer getMenuById(int id, bool ifNotExistsCreate = false) override; + QList > getAllMenuItems() override; + void saveMenuItem(const QSharedPointer &menuItem) override; + unsigned int insertMenuItem(const QSharedPointer &menuItem) override; + + void removeMenuItem(int id) override; + void clearMenuTable() const override; + QSharedPointer makeMenuItem() override; + + QSharedPointer getOrderById(int id, bool ifNotExistsCreate = false) override; + QList > getAllOrders(iOrder::State state = iOrder::State::All) override; + void saveOrder(const QSharedPointer &order) override; + unsigned int insertOrder(const QSharedPointer &order) override; + QSharedPointer makeOrder() override; + + void removeOrder(int id) override; + + QList > getAllImages() override; + QSharedPointer getImageById(const QString &id, bool ifNotExistsCreate = false) override; + + void saveImage(const QSharedPointer &image) override; + void removeImage(const QString &id) override; + + +}; +} +#endif // BOTDATABASE_H diff --git a/src/db/src/public/SecretDB.cpp b/src/db/src/public/SecretDB.cpp new file mode 100644 index 0000000..d557965 --- /dev/null +++ b/src/db/src/public/SecretDB.cpp @@ -0,0 +1,28 @@ +//# +//# Copyright (C) 2021-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "SecretDB.h" + +#include + + +namespace QASecret { + +bool init() { + initSecretDBResources(); + return true; +} + +QSharedPointer database() { + auto db = QSharedPointer::create(); + db->initSqlDb(); + + return db; +} + + +} diff --git a/src/db/src/public/SecretDB.h b/src/db/src/public/SecretDB.h new file mode 100644 index 0000000..70b4e0d --- /dev/null +++ b/src/db/src/public/SecretDB.h @@ -0,0 +1,26 @@ +//# +//# Copyright (C) 2021-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "SecretDB/global.h" +#include "SecretDB/idatabase.h" +#include +#include + +inline void initSecretDBResources() { Q_INIT_RESOURCE(SecretDB); } + +namespace QASecret { + +/** + * @brief init main initialize method of The YourTimeDeliviry library + * @return true if library initialized successfull + */ +bool SECRETDB_EXPORT init(); + +QSharedPointer SECRETDB_EXPORT database(); + + +}; diff --git a/src/db/src/public/SecretDB/global.h.in b/src/db/src/public/SecretDB/global.h.in new file mode 100644 index 0000000..28604cf --- /dev/null +++ b/src/db/src/public/SecretDB/global.h.in @@ -0,0 +1,20 @@ +//# +//# Copyright (C) 2024-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef SECRETDB_GLOBAL_H +#define SECRETDB_GLOBAL_H + +#include + +#if defined(SECRETDB_LIBRARY) +# define SECRETDB_EXPORT Q_DECL_EXPORT +#else +# define SECRETDB_EXPORT Q_DECL_IMPORT +#endif + +#endif //SECRETDB_GLOBAL_H + diff --git a/src/db/src/public/SecretDB/idatabase.cpp b/src/db/src/public/SecretDB/idatabase.cpp new file mode 100644 index 0000000..ea710aa --- /dev/null +++ b/src/db/src/public/SecretDB/idatabase.cpp @@ -0,0 +1,15 @@ +//# +//# Copyright (C) 2018-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "idatabase.h" +namespace QASecret { + +IDataBase::IDataBase() +{ + +} +} diff --git a/src/db/src/public/SecretDB/idatabase.h b/src/db/src/public/SecretDB/idatabase.h new file mode 100644 index 0000000..ad87591 --- /dev/null +++ b/src/db/src/public/SecretDB/idatabase.h @@ -0,0 +1,191 @@ +//# +//# Copyright (C) 2024-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#ifndef IDATABASE_H +#define IDATABASE_H + +#include +#include +#include "global.h" +#include "irecord.h" + + +namespace QASecret { +/** + * @brief The IDataBase class Main database + */ +class SECRETDB_EXPORT IDataBase +{ +public: + IDataBase(); + + /** + * @brief Get a user by their ID. + * @param id The ID of the user to retrieve. + * @param ifNotExistsCreate - this option will create a new object if object with @a id is not existst into database. But object wil not save into database. + * @return A QSharedPointer to the user object if found, nullptr otherwise. + */ + virtual QSharedPointer getRecordByAlias(const QString& alias, bool ifNotExistsCreate = false) = 0; + + /** + * @brief Get a list of all users in the database. + * @return A list of QSharedPointer objects. + */ + virtual QList> getAllUsers(iRole::RoleName roleName = iRole::All) = 0; + + /** + * @brief Update old, or insert if not exists a new user to the database. + * @param user The user object to add. + */ + virtual void saveUser(const QSharedPointer& user) = 0; + + /** + * @brief Remove a user from the database by their ID. + * @param id The ID of the user to remove. + */ + virtual void removeUser(unsigned long long id) = 0; + + /** + * @brief Get a user's role by their ID. + * @param userId The ID of the user. + * @param ifNotExistsCreate - this option will create a new object if object with @a id is not existst into database. But object wil not save into database. + * @return A QSharedPointer to the role object if found, nullptr otherwise. + */ + virtual QSharedPointer getRoleByUserId(unsigned long long userId, bool ifNotExistsCreate = false) = 0; + + /** + * @brief Update old, or insert if not exists a new role to the database. + * @param role The role object to add. + */ + virtual void saveRole(const QSharedPointer& role) = 0; + + /** + * @brief Remove a role from the database by the user's ID. + * @param userId The ID of the user whose role should be removed. + */ + virtual void removeRole(unsigned long long userId) = 0; + + /** + * @brief Get a menu item by its ID. + * @param id The ID of the menu item to retrieve. + * @param ifNotExistsCreate - this option will create a new object if object with @a id is not existst into database. But object wil not save into database. + * @return A QSharedPointer to the menu item object if found, nullptr otherwise. + */ + virtual QSharedPointer getMenuById(int id, bool ifNotExistsCreate = false) = 0; + + /** + * @brief Get a list of all menu items in the database. + * @return A list of QSharedPointer objects. + */ + virtual QList> getAllMenuItems() = 0; + + /** + * @brief Update old, or insert if not exists a new menu item to the database. + * @param menuItem The menu item object to add. + */ + virtual void saveMenuItem(const QSharedPointer& menuItem) = 0; + + /** + * @brief insertMenuItem This method create a new record of the menuItem and return them id + * @param menuItem This is data to save. + * @return id of the new record of the @a menuItem + */ + virtual unsigned int insertMenuItem(const QSharedPointer &menuItem) = 0; + + /** + * @brief Remove a menu item from the database by its ID. + * @param id The ID of the menu item to remove. + */ + virtual void removeMenuItem(int id) = 0; + + /** + * @brief clearMenuTable This method remove all data from the menu table. + */ + virtual void clearMenuTable() const = 0; + + /** + * @brief makeMenuItem This method create a new record of the menu item in database. + * @return new record of the menu item. + */ + virtual QSharedPointer makeMenuItem() = 0; + + /** + * @brief Get an order by its ID. + * @param id The ID of the order to retrieve.\ + * @param ifNotExistsCreate - this option will create a new object if object with @a id is not existst into database. But object wil not save into database. + * @return A QSharedPointer to the order object if found, nullptr otherwise. + */ + virtual QSharedPointer getOrderById(int id, bool ifNotExistsCreate = false) = 0; + + /** + * @brief Get a list of all orders in the database. + * @param state filter order by status. If you want to get all orders with all statuses use the iOrder::State:All + * @return A list of QSharedPointer objects. + */ + virtual QList> getAllOrders(iOrder::State state = iOrder::State::All) = 0; + + /** + * @brief Update old, or insert if not exists a new order to the database. + * @param order The order object to add. + */ + virtual void saveOrder(const QSharedPointer& order) = 0; + + /** + * @brief insertOrder This method create a new record of the order and return them id + * @param order This is data to save. + * @return id of the new record of the @a order + */ + virtual unsigned int insertOrder(const QSharedPointer &order) = 0; + + /** + * @brief makeOrder This method create a new record of the order into database. + * @return new record of the order. + */ + virtual QSharedPointer makeOrder() = 0; + + + /** + * @brief Remove an order from the database by its ID. + * @param id The ID of the order to remove. + */ + virtual void removeOrder(int id) = 0; + + + /** + * @brief Get a list of all images in the database. + * @return A list of QSharedPointer objects. + */ + virtual QList> getAllImages() = 0; + + /** + * @brief Update old, or insert if not exists a new image to the database. + * @param image The order object to add. + */ + virtual void saveImage(const QSharedPointer& image) = 0; + + /** + * @brief Remove an image from the database by its ID. + * @param id The ID of the image to remove. + */ + virtual void removeImage(const QString& id) = 0; + + /** + * @brief Get an image by its ID. + * @param id The ID of the image to retrieve.\ + * @param ifNotExistsCreate - this option will create a new object if object with @a id is not existst into database. But object wil not save into database. + * @return A QSharedPointer to the image object if found, nullptr otherwise. + */ + virtual QSharedPointer getImageById(const QString &id, bool ifNotExistsCreate = false) = 0; + + + +}; +} + + +#endif // IDATABASE_H diff --git a/src/db/src/public/SecretDB/irecord.cpp b/src/db/src/public/SecretDB/irecord.cpp new file mode 100644 index 0000000..337dc49 --- /dev/null +++ b/src/db/src/public/SecretDB/irecord.cpp @@ -0,0 +1,13 @@ +//# +//# Copyright (C) 2024-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#include "irecord.h" +namespace QASecret { + +iRecord::iRecord() {} +} diff --git a/src/db/src/public/SecretDB/irecord.h b/src/db/src/public/SecretDB/irecord.h new file mode 100644 index 0000000..a013d9b --- /dev/null +++ b/src/db/src/public/SecretDB/irecord.h @@ -0,0 +1,62 @@ +//# +//# Copyright (C) 2024-2024 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef IRECORD_H +#define IRECORD_H + +#include "global.h" + +namespace QASecret { + +/** + * @brief The iRecord class This is main interface for all records of database + */ +class SECRETDB_EXPORT iRecord +{ +public: + iRecord(); + + /** + * @brief getAlias returns alias of the record. + * @return record alias. + */ + virtual const QString& getAlias() const = 0; + + /** + * @brief setAlias This method sets new alias for record. + * @param alias is a new vlaue of record + */ + virtual void setAlias(const QString& alias) = 0; + + /** + * @brief getHash return hash of data + * @return hash of record + */ + virtual const QByteArray& getHash() const = 0; + + /** + * @brief setHash This method sets new hash of record. + * @param source is raw data sources of iamge. + */ + virtual void setHash(const QByteArray& source) = 0; + + /** + * @brief getData This method returns data of the record. + * @return source secret data of record + */ + virtual const QByteArray& getData() const = 0; + + /** + * @brief setData This method sets new data of record. + * @param newData this is new value of data. + */ + virtual void setData(const QByteArray& newData) = 0; + +}; + +} +#endif // IRECORD_H diff --git a/src/db/src/sql/SecretDB_1.sql b/src/db/src/sql/SecretDB_1.sql new file mode 100644 index 0000000..919326a --- /dev/null +++ b/src/db/src/sql/SecretDB_1.sql @@ -0,0 +1,32 @@ +BEGIN TRANSACTION; + +CREATE TABLE IF NOT EXISTS "ProcessedIds" ( + "id" BIGINT NOT NULL UNIQUE +); + +CREATE TABLE IF NOT EXISTS "Orders" ( + "id" INTEGER NOT NULL PRIMARY KEY, + "time" INTEGER NOT NULL, + "finishTime" INTEGER NOT NULL, + "accepted" BOOLEAN NOT NULL DEFAULT false, + "done" BOOLEAN NOT NULL DEFAULT false, + "delivered" BOOLEAN NOT NULL DEFAULT false, + "courier" INTEGER DEFAULT NULL, + "receiver" INTEGER DEFAULT NULL, + "manufacturer" INTEGER DEFAULT NULL, + "data" BLOB NOT NULL, + + FOREIGN KEY (courier) REFERENCES Users(id) + ON DELETE CASCADE + ON UPDATE CASCADE, + + FOREIGN KEY (receiver) REFERENCES Users(id) + ON DELETE CASCADE + ON UPDATE CASCADE, + + FOREIGN KEY (manufacturer) REFERENCES Users(id) + ON DELETE CASCADE + ON UPDATE CASCADE +); + +COMMIT; diff --git a/src/db/yourtimebot.cpp b/src/db/yourtimebot.cpp new file mode 100644 index 0000000..e2bf543 --- /dev/null +++ b/src/db/yourtimebot.cpp @@ -0,0 +1,67 @@ +//# +//# Copyright (C) 2023-2023 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "yourtimebot.h" + +#include + +#include +#include + +YourTimeBot::YourTimeBot(const QSharedPointer &db) { + _db = db; + + connect(this, &YourTimeBot::sigReceiveUpdate, this, &YourTimeBot::handleIncomeNewUpdate); +} + +bool YourTimeBot::login(const QByteArray &token) { + + if (!_db) + return false; + + setProcessed(_db->getProcessedIds()); + + + if(!QuasarAppUtils::Locales::init( {QLocale::English, + QLocale::Russian, + QLocale::Ukrainian, + QLocale::Serbian}, { + ":/YourTime/languages/" + } + )){ + return false; + } + + return qTbot::TelegramRestBot::login(token); +} + +void YourTimeBot::handleIncomeNewUpdate(const QSharedPointer &update) { + + if (auto&& tupdate = update.dynamicCast()) { + if (tupdate->contains(tupdate->MessageUpdate)) { + auto mesg = tupdate->message(); + if (mesg->text() == "/start") { + + sendMessage(mesg->chatId(), QuasarAppUtils::Locales::tr("This bot is still under development.", + QLocale(mesg->languageCode()))); + QCoreApplication::processEvents(); + + sendMessage(mesg->chatId(), QuasarAppUtils::Locales::tr("We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are.", + QLocale(mesg->languageCode()))); + QCoreApplication::processEvents(); + + + sendMessage(mesg->chatId(), QuasarAppUtils::Locales::tr("Thank you for your wait.", + QLocale(mesg->languageCode()))); + + } + } + } + + markUpdateAsProcessed(update); + _db->addProcessedId(update->updateId()); +} diff --git a/src/db/yourtimebot.h b/src/db/yourtimebot.h new file mode 100644 index 0000000..99f7667 --- /dev/null +++ b/src/db/yourtimebot.h @@ -0,0 +1,32 @@ +//# +//# Copyright (C) 2023-2023 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef YOURTIMEBOT_H +#define YOURTIMEBOT_H + +#include "YourTimeDeliviry/idatabase.h" +#include + +/** + * @brief The YourTimeBot class + */ +class YourTimeBot: public qTbot::TelegramRestBot +{ + Q_OBJECT +public: + YourTimeBot(const QSharedPointer& db); + bool login(const QByteArray &token) override; + // IBot interface +protected: + void handleIncomeNewUpdate(const QSharedPointer &update) override; + +private: + QSharedPointer _db; + +}; + +#endif // YOURTIMEBOT_H diff --git a/src/example/languages/de.ts b/src/example/languages/de.ts index 6401616..3549ed4 100644 --- a/src/example/languages/de.ts +++ b/src/example/languages/de.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/en.ts b/src/example/languages/en.ts index 6401616..3549ed4 100644 --- a/src/example/languages/en.ts +++ b/src/example/languages/en.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/es.ts b/src/example/languages/es.ts index 6401616..3549ed4 100644 --- a/src/example/languages/es.ts +++ b/src/example/languages/es.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/fr.ts b/src/example/languages/fr.ts index 6401616..3549ed4 100644 --- a/src/example/languages/fr.ts +++ b/src/example/languages/fr.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/ja.ts b/src/example/languages/ja.ts index 6401616..3549ed4 100644 --- a/src/example/languages/ja.ts +++ b/src/example/languages/ja.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/pl.ts b/src/example/languages/pl.ts index 6401616..3549ed4 100644 --- a/src/example/languages/pl.ts +++ b/src/example/languages/pl.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/ru.ts b/src/example/languages/ru.ts index 6401616..3549ed4 100644 --- a/src/example/languages/ru.ts +++ b/src/example/languages/ru.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/tr.ts b/src/example/languages/tr.ts index 6401616..3549ed4 100644 --- a/src/example/languages/tr.ts +++ b/src/example/languages/tr.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/uk.ts b/src/example/languages/uk.ts index 6401616..3549ed4 100644 --- a/src/example/languages/uk.ts +++ b/src/example/languages/uk.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/example/languages/zh.ts b/src/example/languages/zh.ts index 6401616..3549ed4 100644 --- a/src/example/languages/zh.ts +++ b/src/example/languages/zh.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/de.ts b/src/service/languages/de.ts index 6401616..3549ed4 100644 --- a/src/service/languages/de.ts +++ b/src/service/languages/de.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/en.ts b/src/service/languages/en.ts index 6401616..3549ed4 100644 --- a/src/service/languages/en.ts +++ b/src/service/languages/en.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/es.ts b/src/service/languages/es.ts index 6401616..3549ed4 100644 --- a/src/service/languages/es.ts +++ b/src/service/languages/es.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/fr.ts b/src/service/languages/fr.ts index 6401616..3549ed4 100644 --- a/src/service/languages/fr.ts +++ b/src/service/languages/fr.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/ja.ts b/src/service/languages/ja.ts index 6401616..3549ed4 100644 --- a/src/service/languages/ja.ts +++ b/src/service/languages/ja.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/pl.ts b/src/service/languages/pl.ts index 6401616..3549ed4 100644 --- a/src/service/languages/pl.ts +++ b/src/service/languages/pl.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/ru.ts b/src/service/languages/ru.ts index 6401616..3549ed4 100644 --- a/src/service/languages/ru.ts +++ b/src/service/languages/ru.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/tr.ts b/src/service/languages/tr.ts index 6401616..3549ed4 100644 --- a/src/service/languages/tr.ts +++ b/src/service/languages/tr.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/uk.ts b/src/service/languages/uk.ts index 6401616..3549ed4 100644 --- a/src/service/languages/uk.ts +++ b/src/service/languages/uk.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + + diff --git a/src/service/languages/zh.ts b/src/service/languages/zh.ts index 6401616..3549ed4 100644 --- a/src/service/languages/zh.ts +++ b/src/service/languages/zh.ts @@ -1,4 +1,19 @@ + + QuasarAppUtils::Locales + + This bot is still under development. + + + + We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are. + + + + Thank you for your wait. + + +