diff --git a/src/store.cpp b/src/store.cpp index f4b4130..93772af 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -52,6 +52,37 @@ int Application::run() { {header_access_control, header_application_data}); }; + http_server.resource["^/orders/?$"]["PUT"] = + [&](std::shared_ptr response, + std::shared_ptr request) { + const auto content_type = request->header.find("Content-Type"); + + const auto missing_content_type = content_type == request->header.end(); + if (missing_content_type) { + return response::not_found(response); + } + + const auto is_json = content_type->second == "application/json"; + if (!is_json) { + return response::not_found(response); + } + + json data = nullptr; + try { + request->content >> data; + } catch (...) { + return response::not_found(response); + } + + if (!data.is_object()) { + return response::not_found(response); + } + + const auto j = dat.process(data); + + response->write(Status::success_ok, data.dump(), + {header_access_control, header_application_data}); + }; servers.emplace_back([&]() { http_server.start(web_server_started); });