diff --git a/include/orders.hpp b/include/orders.hpp index e5acdcf..f45ccb9 100644 --- a/include/orders.hpp +++ b/include/orders.hpp @@ -10,7 +10,7 @@ class orders : public json { public: - void write(const json &); + void write(); void load(); orders(const with_data_directory &); }; diff --git a/src/orders.cpp b/src/orders.cpp index e437bda..990c25f 100644 --- a/src/orders.cpp +++ b/src/orders.cpp @@ -21,14 +21,14 @@ const fs::path &orders::get_path() { orders::orders(const with_data_directory &dir) : json(json::array()), data_directory(dir) { if (!fs::exists(get_path())) { - write(*this); + write(); } } -void orders::write(const json &input) { +void orders::write() { try { std::ofstream of(get_path()); - of << input; + of << *this; } catch (const std::exception &e) { std::cerr << e.what() << std::endl; diff --git a/src/store.cpp b/src/store.cpp index 266b5bb..c84b5bf 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -29,7 +29,6 @@ Application::Application(const nlohmann::json &cfg) { int Application::run() { std::vector servers; orders orders(data_directory); - orders.load(); for (const auto &m : {"GET", "POST", "PUT", "PATCH", "OPTIONS", "HEAD"}) { if (https_server) { @@ -87,7 +86,8 @@ int Application::run() { return response::bad_request(response, v.errors()); } - // const auto json_response = dat.process(data); + orders.push_back(data); + orders.write(); response->write(Status::success_created, data.dump(), {header_access_control, header_application_data});