-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.hpp
More file actions
executable file
·53 lines (44 loc) · 1.75 KB
/
Copy pathdb.hpp
File metadata and controls
executable file
·53 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "common.hpp"
#include <pqxx/pqxx>
class pgdb
{
private:
enum req_state {
error = 0,
found,
not_found
};
std::unique_ptr<pqxx::connection> conn;
public:
//dbdetails template: "dbname=DBNAME user=DBUSER password=DBPASSWD host=DBHOST port=DBPORT"
pgdb();
~pgdb();
public:
struct messageBody
{
std::string msg;
bool isLocal;
std::string imgUri;
};
static std::string hashPassword(const std::string& username, const std::string& password);
bool createUser(const std::string& username, const std::string& pwd);
pgdb::req_state usernameExists(const std::string& username);
bool auth(const std::string& username, const std::string& password);
bool auth(const std::string& token);
int userIDFromToken(const std::string& token);
std::string usernameFromToken(const std::string& token);
void saveToken(const std::string& username, const std::string& token);
int createChat(int user1Id, int user2Id);
void storeMessage(int chatId, int senderId, const std::string& message, const std::string& filename = "");
std::vector<std::pair<std::string, bool>> getChatMessages(int chatId, int userId);
std::vector<messageBody> getChatMessagesWithImgs(int chatId, int userId);
std::vector<int> getChatIdsForUser(int userId);
std::string getFirstMessageOfChat(int chatId);
void removeChatsForUser(int userId);
void removeChatById(int chatId);
void saveDoc(int userId, const std::string& docName, const std::string& docContent);
std::string getDoc(int userId, const std::string& docName);
std::vector<std::string> getUserDocs(int userId);
void deleteDoc(int userId, const std::string& docName);
void deleteAllUserDocs(int userId);
};