From 4167f92f3d36b7384c4c5f8bf7501bba52e91a0c Mon Sep 17 00:00:00 2001 From: Aotrix Date: Sun, 29 Jun 2025 02:16:13 +0200 Subject: refactoring and added start menu --- include/hearthstoneAPIHandler.h | 29 ----------------------------- include/hearthstoneAPIHandler.hpp | 29 +++++++++++++++++++++++++++++ include/postgresHandler.h | 9 --------- include/postgresHandler.hpp | 36 ++++++++++++++++++++++++++++++++++++ include/startMenu.hpp | 16 ++++++++++++++++ 5 files changed, 81 insertions(+), 38 deletions(-) delete mode 100644 include/hearthstoneAPIHandler.h create mode 100644 include/hearthstoneAPIHandler.hpp delete mode 100644 include/postgresHandler.h create mode 100644 include/postgresHandler.hpp create mode 100644 include/startMenu.hpp (limited to 'include') diff --git a/include/hearthstoneAPIHandler.h b/include/hearthstoneAPIHandler.h deleted file mode 100644 index 9d5ec58..0000000 --- a/include/hearthstoneAPIHandler.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include - -class HearthstoneAPIHandler { - public: - HearthstoneAPIHandler(); - std::string get_cards(const std::string &t_card_parameters); - - private: - static size_t curl_callback_string_output(void *t_contents, size_t t_size, - size_t t_nmemb, std::string *t_s); - std::chrono::seconds get_current_time(); - std::string extract_string_with_regex(const std::string &t_str, - const std::string t_regex); - void write_new_token_info_to_file(const std::string &t_file_path); - void refresh_token_if_needed(); - std::string get_valid_token(); - std::string generate_request_header(); - const std::string get_url(const std::string &t_parameters); - const std::string - get_set_of_cards_url(const std::string &t_card_parameters); - std::string make_api_request(const char *t_url, const char *t_header); - std::string make_api_request(const std::string &t_url, - const std::string &t_header); - - std::string m_access_token; - std::string m_header; -}; diff --git a/include/hearthstoneAPIHandler.hpp b/include/hearthstoneAPIHandler.hpp new file mode 100644 index 0000000..9d5ec58 --- /dev/null +++ b/include/hearthstoneAPIHandler.hpp @@ -0,0 +1,29 @@ +#pragma once +#include +#include + +class HearthstoneAPIHandler { + public: + HearthstoneAPIHandler(); + std::string get_cards(const std::string &t_card_parameters); + + private: + static size_t curl_callback_string_output(void *t_contents, size_t t_size, + size_t t_nmemb, std::string *t_s); + std::chrono::seconds get_current_time(); + std::string extract_string_with_regex(const std::string &t_str, + const std::string t_regex); + void write_new_token_info_to_file(const std::string &t_file_path); + void refresh_token_if_needed(); + std::string get_valid_token(); + std::string generate_request_header(); + const std::string get_url(const std::string &t_parameters); + const std::string + get_set_of_cards_url(const std::string &t_card_parameters); + std::string make_api_request(const char *t_url, const char *t_header); + std::string make_api_request(const std::string &t_url, + const std::string &t_header); + + std::string m_access_token; + std::string m_header; +}; diff --git a/include/postgresHandler.h b/include/postgresHandler.h deleted file mode 100644 index 3c77824..0000000 --- a/include/postgresHandler.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -const pqxx::result execute_query(pqxx::work &t_transaction, - std::string_view t_query); - -void add_cards_to_database(const std::string &t_cards, pqxx::work &t_tx); - -void refresh_cards_table(); diff --git a/include/postgresHandler.hpp b/include/postgresHandler.hpp new file mode 100644 index 0000000..2c3f6f4 --- /dev/null +++ b/include/postgresHandler.hpp @@ -0,0 +1,36 @@ +#pragma once +#include "hearthstoneAPIHandler.hpp" +#include +#include + +/** + * Execute a SQL query from a libpqxx transaction + * + * @param aTransaction The SQL transaction object used to execute the query + * @param aQuery The SQL query + * @return The result of the executed SQL query + */ +const pqxx::result executeQuery(pqxx::work &aTransaction, + std::string_view aQuery); + +/** + * Get the type id of the value element in the "key": value regex match + * For instance, if the regex match is "isZilliaxCosmeticModule":false + * Then the type id is the one correponding to BOOL + * + * @param kSregexIt the regex match for a "key": value card information + * @return the type identifier of the value element + */ +const unsigned int +getTypeIndexOfRegexIterator(const std::sregex_iterator &kSregexIt); +/** + * Add a list of cards (TODO: Complete documentation and function) + * + * @param kCards + * @param aTransaction + */ +void addCardsToDatabase(HearthstoneAPIHandler &aAPIIntermediate, + pqxx::work &aTransaction, + const std::string &kURLOfCardsPage); + +void refresh_cards_table(); diff --git a/include/startMenu.hpp b/include/startMenu.hpp new file mode 100644 index 0000000..0168424 --- /dev/null +++ b/include/startMenu.hpp @@ -0,0 +1,16 @@ +#pragma once +#include +#include + +template +void launchFunction(FunctionType... aFunctions) { + std::cout << "MENU: SELECT THE FUNCTION\n" + << "=========================" << std::endl; + for (size_t aFunctionIndex = 0; aFunctionIndex < sizeof...(aFunctions); + aFunctionIndex++) { + std::cout << std::format("{}) {}", aFunctionIndex + 1, + "currentFunctionName") // FIXME: replace this + << std::endl; + } + std::cout << "=========================" << std::endl; +} -- cgit v1.2.3