Skip to content

Commit 717f596

Browse files
authored
Merge pull request #27 from pooranjoyb/refactor-account
feat: refactored account class
2 parents 84c99dd + 12c084f commit 717f596

File tree

9 files changed

+12
-16
lines changed

9 files changed

+12
-16
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ all: $(BINS)
8686

8787
# Account
8888
createAccount: $(SRCS) $(EXAMPLES_DIR)/account/createAccount.cpp
89-
$(CXX) $(CXXFLAGS) -o ./tests/createAccount $(SRCS) $(EXAMPLES_DIR)/account/createAccount.cpp $(LDFLAGS)
89+
$(CXX) $(CXXFLAGS) -o ./tests/account/createAccount $(SRCS) $(EXAMPLES_DIR)/account/createAccount.cpp $(LDFLAGS)
9090
createSession: $(SRCS) $(EXAMPLES_DIR)/account/createSession.cpp
91-
$(CXX) $(CXXFLAGS) -o ./tests/createSession $(SRCS) $(EXAMPLES_DIR)/account/createSession.cpp $(LDFLAGS)
91+
$(CXX) $(CXXFLAGS) -o ./tests/account/createSession $(SRCS) $(EXAMPLES_DIR)/account/createSession.cpp $(LDFLAGS)
9292

9393
# Database
9494
createDatabase: $(SRCS) $(EXAMPLES_DIR)/database/createDatabase.cpp

examples/account/createAccount.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33

44
int main() {
55
std::string projectId = "66fbb5a100070a3a1d19";
6-
std::string email = "cbeow@main.com";
6+
std::string email = "cbeocscw@main.com";
77
std::string password = "pasvsdvsefefword";
8-
std::string userId = "13ferf2421wefew52";
9-
std::string name = "pooranjoy bhattacharya";
8+
std::string userId = "13ferf2csc421wefew52";
9+
std::string name = "pooranjoy cdcdscd";
1010

1111
Appwrite appwrite(projectId);
12-
Account& auth = appwrite.getAccount();
1312

1413
try {
15-
if (auth.createAccount(email, password, userId, name)) {
14+
if (appwrite.getAccount().createAccount(email, password, userId, name)) {
1615
std::cout << "\nAccount created successfully!" << std::endl;
1716

1817

examples/account/createSession.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ int main() {
77
std::string password = "pasvsdvsefefword";
88

99
Appwrite appwrite(projectId);
10-
Account& auth = appwrite.getAccount();
1110

1211
try {
13-
std::string response = auth.createSession(email, password);
12+
std::string response = appwrite.getAccount().createSession(email, password);
1413
std::cout << "\nSession created." << std::endl;
15-
std::cout<< "\n\nResponse : " << response;
14+
std::cout<< "\nResponse : " << response;
1615

1716
} catch (const AppwriteException& ex) {
1817
std::cerr << "Exception: " << ex.what() << std::endl;

include/Appwrite.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Appwrite {
1010
public:
11-
Appwrite(const std::string& projectId, const std::string& apiKey);
11+
Appwrite(const std::string& projectId, const std::string& apiKey = "");
1212
Account& getAccount();
1313
Databases& getDatabases();
1414
Storage& getStorage();

include/classes/Account.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
class Account {
1010
public:
11-
Account(const std::string& projectId, const std::string& apiKey);
11+
explicit Account(const std::string& projectId);
1212

1313
bool createAccount(const std::string& email, const std::string& password, const std::string& userId, const std::string& name);
1414
std::string createSession(const std::string& email, const std::string& password);
1515

1616
private:
17-
std::string apiKey;
1817
std::string projectId;
1918
};
2019

src/Appwrite.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Appwrite.hpp"
22

33
Appwrite::Appwrite(const std::string& projectId, const std::string& apiKey)
4-
: projectId(projectId), apiKey(apiKey), account(projectId, apiKey),
4+
: projectId(projectId), apiKey(apiKey), account(projectId),
55
databases(projectId, apiKey), storage(projectId, apiKey), health(projectId, apiKey) {}
66

77

src/services/Account.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "enums/HttpStatus.hpp"
77
#include "exceptions/AppwriteException.hpp"
88

9-
Account::Account(const std::string& projectId, const std::string& apiKey)
10-
: projectId(projectId), apiKey(apiKey) {}
9+
Account::Account(const std::string& projectId) : projectId(projectId) {}
1110

1211
bool Account::createAccount(const std::string& email, const std::string& password, const std::string& userId, const std::string& name = "") {
1312

tests/account/createAccount

719 KB
Binary file not shown.

tests/account/createSession

725 KB
Binary file not shown.

0 commit comments

Comments
 (0)