From b5f0866471f08e8ee8b58b12c8fd0490ef14093e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Sun, 23 May 2021 15:21:02 +0200 Subject: [PATCH] add validation --- include/data.hpp | 1 + src/data.cpp | 10 ++++++++-- src/store.cpp | 7 +++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/data.hpp b/include/data.hpp index 3328d67..1219826 100644 --- a/include/data.hpp +++ b/include/data.hpp @@ -8,6 +8,7 @@ class data : public json { fs::path &get_data_path(); void create_data_directory(); fs::path get_store_path(); + bool validate(const json &); public: data(); diff --git a/src/data.cpp b/src/data.cpp index 55fe337..dd21cf0 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -42,6 +42,12 @@ void data::create_data_directory() { fs::path data::get_store_path() { return get_data_path() / "store.json"; } -nlohmann::json data::process(const nlohmann::json &) { +json data::process(const json &input) { + if (!validate(input)) { + return nullptr; + } + return {{"success", true}}; -} \ No newline at end of file +} + +bool data::validate(const json &input) {} diff --git a/src/store.cpp b/src/store.cpp index 5f1950e..e9a2776 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -80,8 +80,11 @@ int Application::run() { const auto json_response = dat.process(data); - response->write(Status::client_error_precondition_required, - json_response.dump(), + if (json_response.is_null()) { + return response::bad_object(response); + } + + response->write(Status::success_created, json_response.dump(), {header_access_control, header_application_data}); };