Skip to content

Commit b0179be

Browse files
authored
feat: Added API for list_Topic_logs (#135)
* feat: Added API for list_Topic_logs * feat: Added API for list_Topic_logs * list_Topic_logs to listTopicLogs
1 parent 59c3751 commit b0179be

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ createTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/createTopic.cpp
300300
updateTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp
301301
@mkdir -p ./$(TESTS_DIR)
302302
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp $(LDFLAGS)
303-
303+
listTopicLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/listTopicLogs.cpp
304+
@mkdir -p ./$(TESTS_DIR)
305+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTopicLogs $(SRCS) $(EXAMPLES_DIR)/messaging/topics/listTopicLogs.cpp $(LDFLAGS)
304306
# Messaging - subscribers
305307
getSubscriber: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/getSubscriber.cpp
306308
@mkdir -p ./$(TESTS_DIR)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Appwrite.hpp"
2+
#include <iostream>
3+
4+
int main() {
5+
std::string projectId = "";
6+
std::string apiKey = "";
7+
Appwrite appwrite(projectId, apiKey);
8+
9+
std::string topicId = "";
10+
11+
std::vector<std::string> queries = {};
12+
13+
try {
14+
std::string response = appwrite.getMessaging().listTopicLogs(topicId, queries);
15+
16+
std::cout << "Topic Logs: " << response << std::endl;
17+
} catch (const AppwriteException &e) {
18+
std::cerr << "Appwrite error: " << e.what() << std::endl;
19+
}
20+
return 0;
21+
}

include/classes/Messaging.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ class Messaging {
261261
*/
262262
std::string listTargets(const std::string &messageId,
263263
const std::vector<std::string> &queries = {});
264+
265+
/**
266+
* @brief List all logs for a given topic.
267+
* @param topicID ID of the message.
268+
* @param queries Optional query filters.
269+
* @return JSON response.
270+
*/
271+
std::string listTopicLogs(const std::string &topicId,
272+
const std::vector<std::string> &queries = {});
264273

265274
private:
266275
std::string projectId; ///< Project ID

src/services/Messaging.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,34 @@ std::string Messaging::listTargets(const std::string &messageId,
737737
}
738738

739739

740+
std::string Messaging::listTopicLogs(const std::string &topicId,
741+
const std::vector<std::string> &queries) {
742+
if (topicId.empty()) {
743+
throw AppwriteException("Missing required parameter: 'topicId'");
744+
}
745+
746+
std::string url = Config::API_BASE_URL + "/messaging/topics/" + topicId + "/logs";
747+
748+
std::string queryParam = "";
749+
if (!queries.empty()) {
750+
queryParam += "?queries[]=" + Utils::urlEncode(queries[0]);
751+
for (size_t i = 1; i < queries.size(); ++i) {
752+
queryParam += "&queries[]=" + Utils::urlEncode(queries[i]);
753+
}
754+
}
755+
url += queryParam;
756+
757+
std::vector<std::string> headers = Config::getHeaders(projectId);
758+
headers.push_back("X-Appwrite-Key: " + apiKey);
759+
std::string response;
760+
761+
int statusCode = Utils::getRequest(url, headers, response);
762+
if (statusCode == HttpStatus::OK) {
763+
return response;
764+
} else {
765+
throw AppwriteException(
766+
"Error fetching topic logs. Status code: " + std::to_string(statusCode) +
767+
"\n\nResponse: " + response);
768+
}
769+
}
770+

0 commit comments

Comments
 (0)