From f427685d64c67c0e29af72b2d7daba58a477d331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Sun, 23 May 2021 19:13:38 +0200 Subject: [PATCH] add an auto increment id --- include/orders.hpp | 2 +- src/orders.cpp | 5 +++++ src/store.cpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/orders.hpp b/include/orders.hpp index 3913f46..65b6555 100644 --- a/include/orders.hpp +++ b/include/orders.hpp @@ -12,6 +12,6 @@ public: void write(); void load(); orders(const with_data_directory &); - void push(); + void push(json); ~orders(); }; diff --git a/src/orders.cpp b/src/orders.cpp index c1c8e40..833f26d 100644 --- a/src/orders.cpp +++ b/src/orders.cpp @@ -38,3 +38,8 @@ void orders::write() { } orders::~orders() { write(); } + +void orders::push(json data) { + data["id"] = std::to_string(size() + 1); + push_back(data); +} \ No newline at end of file diff --git a/src/store.cpp b/src/store.cpp index c84b5bf..dac8464 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -86,7 +86,7 @@ int Application::run() { return response::bad_request(response, v.errors()); } - orders.push_back(data); + orders.push(data); orders.write(); response->write(Status::success_created, data.dump(),