From 0ad646616247fb468ec191592dbea803e80799a8 Mon Sep 17 00:00:00 2001 From: mayaannkkk Date: Tue, 9 Sep 2025 11:57:21 +0530 Subject: [PATCH 1/3] feat: Added API for list_Topic_logs --- Makefile | 4 ++- examples/messaging/topics/list_Topic_logs.cpp | 21 +++++++++++++ include/classes/Messaging.hpp | 9 ++++++ src/services/Messaging.cpp | 30 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 examples/messaging/topics/list_Topic_logs.cpp diff --git a/Makefile b/Makefile index 59e5cbd..daeb572 100644 --- a/Makefile +++ b/Makefile @@ -293,7 +293,9 @@ createTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/createTopic.cpp updateTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp $(LDFLAGS) - +list_Topic_logs: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/list_Topic_logs.cpp + @mkdir -p ./$(TESTS_DIR) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/list_Topic_logs $(SRCS) $(EXAMPLES_DIR)/messaging/topics/list_Topic_logs.cpp $(LDFLAGS) # Messaging - subscribers getSubscriber: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/getSubscriber.cpp @mkdir -p ./$(TESTS_DIR) diff --git a/examples/messaging/topics/list_Topic_logs.cpp b/examples/messaging/topics/list_Topic_logs.cpp new file mode 100644 index 0000000..d15d8bf --- /dev/null +++ b/examples/messaging/topics/list_Topic_logs.cpp @@ -0,0 +1,21 @@ +#include "Appwrite.hpp" +#include + +int main() { + std::string projectId = "6884bd56002f5a20341f"; + std::string apiKey = "standard_31ceb812f9444de5efc0991fdcfe1c67af3717ff4aebb85bf82f5c76c386d5854c259cfee4f68c139ccc6fa19b85b3f9f4541449dd77971e6a1114373c5c8d911b88fce9e24456446108b54c2262813c8b3d2badb80e81824f3f31a76beb12281ce1faa61a03189791255f4d5e1762dcf8f6c922e4b8a8197d56902a148914de"; + Appwrite appwrite(projectId, apiKey); + + std::string topicId = "6884bde100084222e873"; + + std::vector queries = {}; + + try { + std::string response = appwrite.getMessaging().listTopicLogs(topicId, queries); + + std::cout << "Topic Logs: " << response << std::endl; + } catch (const AppwriteException &e) { + std::cerr << "Appwrite error: " << e.what() << std::endl; + } + return 0; +} diff --git a/include/classes/Messaging.hpp b/include/classes/Messaging.hpp index 6f7a70b..451d299 100644 --- a/include/classes/Messaging.hpp +++ b/include/classes/Messaging.hpp @@ -230,6 +230,15 @@ class Messaging { */ std::string listTargets(const std::string &messageId, const std::vector &queries = {}); + + /** + * @brief List all logs for a given topic. + * @param topicID ID of the message. + * @param queries Optional query filters. + * @return JSON response. + */ + std::string listTopicLogs(const std::string &topicId, + const std::vector &queries = {}); private: std::string projectId; ///< Project ID diff --git a/src/services/Messaging.cpp b/src/services/Messaging.cpp index 8f2f62a..e57b6e3 100644 --- a/src/services/Messaging.cpp +++ b/src/services/Messaging.cpp @@ -681,3 +681,33 @@ std::string Messaging::listTargets(const std::string &messageId, } } +std::string Messaging::listTopicLogs(const std::string &topicId, + const std::vector &queries) { + if (topicId.empty()) { + throw AppwriteException("Missing required parameter: 'topicId'"); + } + + std::string url = Config::API_BASE_URL + "/messaging/topics/" + topicId + "/logs"; + + std::string queryParam = ""; + if (!queries.empty()) { + queryParam += "?queries[]=" + Utils::urlEncode(queries[0]); + for (size_t i = 1; i < queries.size(); ++i) { + queryParam += "&queries[]=" + Utils::urlEncode(queries[i]); + } + } + url += queryParam; + + std::vector headers = Config::getHeaders(projectId); + headers.push_back("X-Appwrite-Key: " + apiKey); + std::string response; + + int statusCode = Utils::getRequest(url, headers, response); + if (statusCode == HttpStatus::OK) { + return response; + } else { + throw AppwriteException( + "Error fetching topic logs. Status code: " + std::to_string(statusCode) + + "\n\nResponse: " + response); + } +} \ No newline at end of file From 077cc06b1293661c1b8257541c8e3e65fe40f008 Mon Sep 17 00:00:00 2001 From: mayaannkkk Date: Tue, 9 Sep 2025 12:16:33 +0530 Subject: [PATCH 2/3] feat: Added API for list_Topic_logs --- examples/messaging/topics/list_Topic_logs.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/messaging/topics/list_Topic_logs.cpp b/examples/messaging/topics/list_Topic_logs.cpp index d15d8bf..6160592 100644 --- a/examples/messaging/topics/list_Topic_logs.cpp +++ b/examples/messaging/topics/list_Topic_logs.cpp @@ -2,11 +2,11 @@ #include int main() { - std::string projectId = "6884bd56002f5a20341f"; - std::string apiKey = "standard_31ceb812f9444de5efc0991fdcfe1c67af3717ff4aebb85bf82f5c76c386d5854c259cfee4f68c139ccc6fa19b85b3f9f4541449dd77971e6a1114373c5c8d911b88fce9e24456446108b54c2262813c8b3d2badb80e81824f3f31a76beb12281ce1faa61a03189791255f4d5e1762dcf8f6c922e4b8a8197d56902a148914de"; + std::string projectId = ""; + std::string apiKey = ""; Appwrite appwrite(projectId, apiKey); - std::string topicId = "6884bde100084222e873"; + std::string topicId = ""; std::vector queries = {}; From 42dc630915ef09c2ea53c28178327dfb5682dbbc Mon Sep 17 00:00:00 2001 From: mayaannkkk Date: Mon, 15 Sep 2025 20:26:59 +0530 Subject: [PATCH 3/3] list_Topic_logs to listTopicLogs --- Makefile | 4 ++-- .../topics/{list_Topic_logs.cpp => listTopicLogs.cpp} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename examples/messaging/topics/{list_Topic_logs.cpp => listTopicLogs.cpp} (100%) diff --git a/Makefile b/Makefile index daeb572..ab3b45d 100644 --- a/Makefile +++ b/Makefile @@ -293,9 +293,9 @@ createTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/createTopic.cpp updateTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp @mkdir -p ./$(TESTS_DIR) $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateTopic $(SRCS) $(EXAMPLES_DIR)/messaging/topics/updateTopic.cpp $(LDFLAGS) -list_Topic_logs: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/list_Topic_logs.cpp +listTopicLogs: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/listTopicLogs.cpp @mkdir -p ./$(TESTS_DIR) - $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/list_Topic_logs $(SRCS) $(EXAMPLES_DIR)/messaging/topics/list_Topic_logs.cpp $(LDFLAGS) + $(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTopicLogs $(SRCS) $(EXAMPLES_DIR)/messaging/topics/listTopicLogs.cpp $(LDFLAGS) # Messaging - subscribers getSubscriber: $(SRCS) $(EXAMPLES_DIR)/messaging/subscribers/getSubscriber.cpp @mkdir -p ./$(TESTS_DIR) diff --git a/examples/messaging/topics/list_Topic_logs.cpp b/examples/messaging/topics/listTopicLogs.cpp similarity index 100% rename from examples/messaging/topics/list_Topic_logs.cpp rename to examples/messaging/topics/listTopicLogs.cpp