-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfull_flow_test.cpp
171 lines (145 loc) · 5.17 KB
/
full_flow_test.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include "json.hpp"
#include "Appwrite.hpp"
using json = nlohmann::json;
Account account;
Databases databases;
void displayMenu() {
std::cout << "\n=== Appwrite C++ SDK Test Menu ===\n";
std::cout << "1. Create Account\n";
std::cout << "2. Create Session\n";
std::cout << "3. List Databases\n";
std::cout << "4. List Collections\n";
std::cout << "5. Create Collection\n";
std::cout << "6. Create Email Attribute\n";
std::cout << "7. List Documents\n";
std::cout << "8. List Attributes\n";
std::cout << "9. Create Document\n";
std::cout << "10. Create Index\n";
std::cout << "11. Exit\n";
std::cout << "Enter your choice: ";
}
void handleCreateAccount() {
std::string email = "[email protected]";
std::string password = "securePassword";
std::string userId = "uniqueUserId";
std::string name = "Test User";
bool success = account.createAccount(email, password, userId, name);
std::cout << (success ? "Account created successfully.\n" : "Failed to create account.\n");
}
void handleCreateSession() {
std::string email = "[email protected]";
std::string password = "securePassword";
std::string sessionId = account.createSession(email, password);
if (!sessionId.empty()) {
std::cout << "Session created successfully. Session ID: " << sessionId << "\n";
} else {
std::cout << "Failed to create session.\n";
}
}
void handleListDatabases() {
std::string response = databases.list();
std::cout << "Databases:\n" << response << "\n";
}
void handleListCollections() {
std::string databaseId = "database123";
std::string response = databases.listCollection(databaseId);
std::cout << "Collections:\n" << response << "\n";
}
void handleCreateCollection() {
std::string databaseId = "database123";
std::string collectionId = "test1234collectionnew";
std::string name = "Sample Collection";
bool enabled = true;
std::string response = databases.createCollection(databaseId, collectionId, name, enabled);
std::cout << "Collection Creation Response:\n" << response << "\n";
}
void handleCreateEmailAttribute() {
std::string databaseId = "database123";
std::string collectionId = "test1234collectionnew";
std::string attributeId = "email";
bool required = true;
std::string defaultValue = "";
std::string response = databases.createEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue);
std::cout << "Email Attribute Creation Response:\n" << response << "\n";
}
void handleListDocuments() {
std::string databaseId = "database123";
std::string collectionId = "test1234collectionnew";
std::string response = databases.listDocument(databaseId, collectionId);
std::cout << "Documents:\n" << response << "\n";
}
void handleListAttributes() {
std::string databaseId = "database123";
std::string collectionId = "test1234collectionnew";
std::string response = databases.listAttributes(databaseId, collectionId);
std::cout << "Attributes:\n" << response << "\n";
}
void handleCreateDocument() {
std::string databaseId = "database123";
std::string collectionId = "test1234collectionnew";
std::string documentId = "sampleDocumentId";
json data = {
{"email", "[email protected]"}
};
std::string response = databases.createDocument(databaseId, collectionId, documentId, data);
std::cout << "Document Creation Response:\n" << response << "\n";
}
void handleCreateIndex() {
std::string databaseId = "database123";
std::string collectionId = "test1234collectionnew";
std::string key = "indexKey";
std::string type = "unique";
std::vector<std::string> attributes = {"email"};
std::string response = databases.createIndexes(databaseId, collectionId, key, type, attributes);
std::cout << "Index Creation Response:\n" << response << "\n";
}
int main() {
std::string projectId = "66fbb5a100070a3a1d19";
std::string apiKey = "";
account.setup(projectId);
databases.setup(apiKey, projectId);
int choice;
do {
displayMenu();
std::cin >> choice;
switch (choice) {
case 1:
handleCreateAccount();
break;
case 2:
handleCreateSession();
break;
case 3:
handleListDatabases();
break;
case 4:
handleListCollections();
break;
case 5:
handleCreateCollection();
break;
case 6:
handleCreateEmailAttribute();
break;
case 7:
handleListDocuments();
break;
case 8:
handleListAttributes();
break;
case 9:
handleCreateDocument();
break;
case 10:
handleCreateIndex();
break;
case 11:
std::cout << "Exiting program.\n";
break;
default:
std::cout << "Invalid choice. Please try again.\n";
}
} while (choice != 11);
return 0;
}