Browse Source

write him self to the stack si

master
Jørgen Sverre Lien Sellæg 5 years ago
parent
commit
052e4994cb
  1. 2
      include/orders.hpp
  2. 6
      src/orders.cpp
  3. 4
      src/store.cpp

2
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 &);
};

6
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;

4
src/store.cpp

@ -29,7 +29,6 @@ Application::Application(const nlohmann::json &cfg) {
int Application::run() {
std::vector<std::thread> 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});

Loading…
Cancel
Save