/
Shymer123
/
Messenger
Обзор
Документация
Войти
/
Shymer123
/
Messenger
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
server
Server/SourceFiles/DatabaseManager/DatabaseManager.h
79 строк
3 KB
Shymer123
added chat creation confirmation, and now the group and chat are created through procedures (reduced delays in accessing the database)
17 май 2025, 06:06
17 май 2025, 06:06
7df2171
Код
Авторство
О чём код?
#ifndef DATABASEMANAGER_H #define DATABASEMANAGER_H #include "DataModels/MessageData.h" #include <string> #include <vector> #include <set> #include <mysql_driver.h> #include <mysql_connection.h> #include <cppconn/prepared_statement.h> #include <cppconn/resultset.h> #include <memory> #include <nlohmann/json.hpp> class Server; using json = nlohmann::json; class DatabaseManager { public: static DatabaseManager& getInstance(); void connectToDatabase(); json getIsNameAlreadyUse(const std::string& userName); json getIsPhoneNumberAlreadyUse(const std::string& phoneNumber); json getStoredPasswordData(const std::string& userName); json getUserID(const std::string& userName); json getChats(const int userID); json getSingleChat(const int chatID); json getMessages(const int chatID); void downloadFile(const int clientSocket, const int fileID); json getContacts(const int userID); json getUserData(const int chatID, const int currentUserID); json getGroupData(const int chatID); json getDialogIDAfterCreation(const int currentUserID, const int user2ID); json getGroupID(const int userID, const std::string& groupName); json getMembersIDInGroup(const int userID, const int chatID); json getParticipantIDInDialogUsePhoneNumber(const std::string& user2PhoneNumber); json getPhoneNumberUser2InDialog(const int userID, const std::string& chatName); json getPhoneNumber(const int userID); json getMembersIDForSelected(const int userID, const std::vector<std::string>& selectedMembers); json getIsCombinedNameExists(const int userID, const std::string& combinedName); json getIsPhoneNumberValid(const int userID, const std::string& phoneNumber); // adding data only void addUserInDatabase(const std::string& userName, const std::string& hashedPassword, const std::string& salt, const std::string& phoneNumber); void addUserInServerCache(const int clientSocket, const int userID); json sendMessage(MessageData& data, std::set<int>& participantsID); json sendFile(MessageData& data, std::set<int>& participantsID); void addContact(const int currentUserID, const std::string& currentUserName, const int user2ID, const std::string& user2Name, const std::string& user2PhoneNumber); json addFavourite(const int userID, const int tempChatID); json addDialog(const int currentUserID, const std::string& participantName, const int tempChatID); void addGroup(const std::string& groupName); json addGroup(const int userID, const std::string& groupName, const std::vector<std::string>& selectedMembers, const int tempChatID); void updateListDialogsForUsers(const int participantID); void updateListGroupsForUsers(const int groupID, std::set<int>& membersID); void updateMessagesInParticipantDialog(const MessageData& data, const int participantID); void updateMessagesInParticipantsGroup(const MessageData& data, std::set<int>& membersID); void addMembersToGroup(const int groupID, const json& members); public: void setServerPointer(Server* server); private: DatabaseManager(); DatabaseManager(const DatabaseManager&) = delete; DatabaseManager& operator=(const DatabaseManager&) = delete; std::shared_ptr<sql::Connection> connection; Server* server; bool isConnected; }; #endif // DATABASEMANAGER_H