diff --git a/src/bank.cpp b/src/bank.cpp index a15d792..b20a231 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -62,7 +62,7 @@ BankResponse Bank::GetLogs(const std::string &name) noexcept { BankResponse res; #if MAX_LOG_SIZE > 0 - if (!users.modify_if(name, [&res](User &u) { res = BankResponse(k200OK, u.log.GetLog().toStyledString()); })) + if (!users.modify_if(name, [&res](User &u) { res = BankResponse(k200OK, u.log.GetLog()); })) { return BankResponse(k404NotFound, "\"User not found\""); } diff --git a/src/bank_api.cpp b/src/bank_api.cpp index 652d915..97ea88c 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -51,12 +51,11 @@ void api::GetLogs(req_args) { if constexpr (MAX_LOG_SIZE > 0) { - RESPONSE_PARSE(bank.GetLogs(NAME_PARAM)); + RESPONSE_PARSE(bank.GetLogs("twix")); } else { - auto resp = HttpResponse::newHttpJsonResponse("Logs are Disabled"); - resp->setStatusCode(k404NotFound); + auto resp = HttpResponse::newCustomHttpResponse(BankResponse(k404NotFound, "\"Logs are Disabled\"")); CACHE_FOREVER callback(resp); } diff --git a/src/log.cpp b/src/log.cpp index f2b3a04..31094da 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,5 +1,10 @@ #include "log.h" +Log::Log() noexcept +{ + log_flag.SetChangesOn(); +} + void Log::AddTrans(Transaction &&t) noexcept { #if MAX_LOG_SIZE == 1 @@ -7,7 +12,7 @@ void Log::AddTrans(Transaction &&t) noexcept #else if (data.size() == MAX_LOG_SIZE) // If we hit the max size { - for (uint32_t i = 1; i < data.size(); i++) // Make room at the back + for (size_t i = 1; i < data.size(); i++) // Make room at the back { data[i - 1] = std::move(data[i]); // Shifts everything left } @@ -19,7 +24,7 @@ void Log::AddTrans(Transaction &&t) noexcept log_flag.SetChangesOn(); } -const Json::Value &Log::GetLog() noexcept +const std::string &Log::GetLog() noexcept { if (log_flag.GetChangeState()) //if there are changes { @@ -42,7 +47,7 @@ const Json::Value &Log::GetLog() noexcept res[i - 1]["time"] = (Json::Int64)data[data.size() - i].time; } #endif - log_snapshot = res; + log_snapshot = res.toStyledString(); log_flag.SetChangesOff(); } return log_snapshot;