diff --git a/backend/src/builtin-cli.cpp b/backend/src/builtin-cli.cpp index 6679a82..361c0e7 100644 --- a/backend/src/builtin-cli.cpp +++ b/backend/src/builtin-cli.cpp @@ -17,10 +17,10 @@ void BookStoreMain(bool is_server, std::string config_dir) { std::string cmd; while (std::getline(std::cin, cmd)) { auto result = std::move(engine.Execute(cmd, login_stack)); - // debugPrint(cmd); + debugPrint(cmd); for (auto &line : result) { std::cout << line << '\n'; - // debugPrint(line); + debugPrint(line); } // debugPrint(); if (BookStore_ZYM::shut_down) return; diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 22250b6..4753a7f 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -300,11 +300,16 @@ std::vector BookStoreEngineClass::ExecuteMOdify( double price; if (!CommandModifyLexer(cmd, new_ISBN, name, author, keyword, price)) return std::vector({"Invalid"}); + // debugPrint("successfully lexed modify"); + // debugPrint("modify", new_ISBN, ' ', name, ' ', author, ' ', keyword, ' ', + // price); if (login_stack.empty() || user_data_base.GetPrevilege(login_stack.top().first) < 3) return std::vector({"Invalid"}); + // debugPrint("successfully checked authority"); if (login_stack.top().second == "" || login_stack.top().second == new_ISBN) return std::vector({"Invalid"}); + // debugPrint("successfully checked ISBN"); if (keyword != "") { std::vector key_list; if (!KeyWordSpliter(keyword, key_list, false)) @@ -316,6 +321,7 @@ std::vector BookStoreEngineClass::ExecuteMOdify( key_set.insert(i); } } + // debugPrint("successfully checked keyword"); book_data_base.ModifyInfo(login_stack.top().second, new_ISBN, name, author, keyword, price, -1); return std::vector(); diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index 7935f9d..658f5a3 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -1,5 +1,6 @@ #include "lexer.h" +#include "bs-utility.h" // clang-format off /** * @brief Lexer for command "su" @@ -336,7 +337,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, std::string &name, std::string &author, std::string &keyword, double &price) { static std::basic_regex main_pattern( - R"(^ *modify(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\"| +-price=[0-9]{1,10}\.[0-9]{2})+ *$)", + R"(^ *modify(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\"| +-price=[0-9]{1,10}(?:\.[0-9]{1,2})?)+ *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command); @@ -349,6 +350,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, price = -1; while (ss >> token) { if (token[1] == 'I') { + // debugPrint("ISBN's token is ", token); ISBN = token.substr(6); } else if (token[1] == 'n') { name = token.substr(6 + 1, token.size() - 7 - 1); @@ -383,7 +385,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, bool CommandImportLexer(const std::string &command, int &quantity, double &total_cost) { static std::basic_regex main_pattern( - R"(^ *import +[0-9]{1,10} +[0-9]{1,10}\.[0-9]{2} *$)", + R"(^ *import +[0-9]{1,10} +[0-9]{1,10}(?:\.[0-9]{1,2})? *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command);