u
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "../router.hpp"
|
||||
#include "../queries/category_list.hpp"
|
||||
|
||||
void handle_category(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_category(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t cursor = std::stoll(req.get_query_param("lastChangedCategory", "0"));
|
||||
int limit = std::stoi(req.get_query_param("limit", "20"));
|
||||
auto categories = get_category_list(cursor, limit);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../log.hpp"
|
||||
#include "../queries/image.hpp"
|
||||
|
||||
void handle_cimage(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_cimage(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
std::string path = req.get_query_param("path");
|
||||
if (path.empty()) {
|
||||
resp.send_json(400, {{"Message", "Missing required query parameter 'path'."}});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../router.hpp"
|
||||
#include "../queries/customer_groups.hpp"
|
||||
|
||||
void handle_customergroup(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_customergroup(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t cursor = std::stoll(req.get_query_param("lastChangedCustomerGroup", "0"));
|
||||
auto groups = get_customer_group_list(cursor);
|
||||
resp.send_json(200, groups);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../router.hpp"
|
||||
#include "../queries/deleted_entity_list.hpp"
|
||||
|
||||
void handle_deleted_entity(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_deleted_entity(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t cursor = std::stoll(req.get_query_param("lastChangedDeletedEntity", "0"));
|
||||
int limit = std::stoi(req.get_query_param("limit", "600"));
|
||||
auto deleted = get_deleted_entity_list(cursor, limit);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "../http.hpp"
|
||||
#include "../tls_server.hpp"
|
||||
#include "../router.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../queries/counts.hpp"
|
||||
#include "../queries/customer_groups.hpp"
|
||||
#include "../queries/shop.hpp"
|
||||
#include "../config.hpp"
|
||||
|
||||
void handle_init(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_init(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t product_cursor = std::stoll(req.get_query_param("lastChangedProduct", "0"));
|
||||
int64_t category_cursor = std::stoll(req.get_query_param("lastChangedCategory", "0"));
|
||||
int64_t cg_cursor = std::stoll(req.get_query_param("lastChangedCustomerGroup", "0"));
|
||||
@@ -17,6 +18,7 @@ void handle_init(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
int shop = get_active_shop_id();
|
||||
|
||||
int64_t product_count = 0, category_count = 0, cg_count = 0, composite_count = 0, deleted_count = 0;
|
||||
int64_t max_order_id_count = 0;
|
||||
|
||||
if (get_pool().execute_scalar("SELECT 1") != 0) {
|
||||
product_count = get_product_count(root, shop, product_cursor);
|
||||
@@ -24,6 +26,16 @@ void handle_init(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
cg_count = get_customer_group_count(cg_cursor);
|
||||
composite_count = get_composite_count(shop, composite_cursor);
|
||||
deleted_count = get_deleted_count(deleted_cursor);
|
||||
max_order_id_count = get_max_order_id_count(get_active_shop_subshop_id());
|
||||
logc::info("init counts: products=%lld categories=%lld cg=%lld composite=%lld deleted=%lld max_order=%lld root=%d shop=%d subshop=%d",
|
||||
product_count, category_count, cg_count, composite_count, deleted_count, max_order_id_count,
|
||||
root, shop, get_active_shop_subshop_id());
|
||||
if (product_cursor == 0 && category_cursor == 0 &&
|
||||
product_count == 0 && category_count == 0 && deleted_count == 0) {
|
||||
logc::warn("init: all counts zero with cursors at 0 — check DB connectivity and shop/category config");
|
||||
}
|
||||
} else {
|
||||
logc::warn("init: DB connection check failed, returning zero counts");
|
||||
}
|
||||
|
||||
resp.send_json(200, {
|
||||
@@ -36,6 +48,6 @@ void handle_init(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
{"configurationGroup_count", "0"},
|
||||
{"configurationItem_count", "0"},
|
||||
{"deletedEntity_count", std::to_string(deleted_count)},
|
||||
{"max_orderId_count", "0"}
|
||||
{"max_orderId_count", std::to_string(max_order_id_count)}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
// POST /v1/order — creates one or more POS orders.
|
||||
// Port of src/endpoints/order.js and src/queries/create-order.js.
|
||||
|
||||
#include "../http.hpp"
|
||||
#include "../tls_server.hpp"
|
||||
#include "../router.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../order_log.hpp"
|
||||
#include "../queries/create_order.hpp"
|
||||
|
||||
void handle_order(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
// TODO: full order creation (Milestone 5/6)
|
||||
// For now, parse the JSON body and acknowledge
|
||||
#include <string>
|
||||
|
||||
static nlohmann::json get_orders(const nlohmann::json& body) {
|
||||
if (!body.is_object()) return nlohmann::json::array();
|
||||
auto it = body.find("orders");
|
||||
if (it == body.end() || !it->is_array()) return nlohmann::json::array();
|
||||
return *it;
|
||||
}
|
||||
|
||||
void handle_order(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
nlohmann::json body;
|
||||
try {
|
||||
body = nlohmann::json::parse(req.body);
|
||||
@@ -14,15 +25,44 @@ void handle_order(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
}
|
||||
|
||||
nlohmann::json results = nlohmann::json::array();
|
||||
if (body.contains("orders") && body["orders"].is_array()) {
|
||||
for (auto& order : body["orders"]) {
|
||||
std::string ext_id = order.value("externalId", "");
|
||||
nlohmann::json orders = get_orders(body);
|
||||
|
||||
int successful = 0;
|
||||
int failed = 0;
|
||||
|
||||
for (const auto& order : orders) {
|
||||
std::string externalOrderId = order.value("externalId", "");
|
||||
g_order_log.log_order(order.dump(), externalOrderId);
|
||||
|
||||
try {
|
||||
nlohmann::json created = order::create_order(order);
|
||||
logc::success("order %s (kAuftrag=%s) created for externalId=%s",
|
||||
created.value("orderNumber", "").c_str(),
|
||||
created.value("orderId", "").c_str(),
|
||||
externalOrderId.c_str());
|
||||
results.push_back({
|
||||
{"status", "OK"},
|
||||
{"externalOrderId", ext_id},
|
||||
{"externalOrderId", externalOrderId},
|
||||
{"message", ""}
|
||||
});
|
||||
++successful;
|
||||
} catch (const std::exception& ex) {
|
||||
logc::error("order externalId=%s failed: %s", externalOrderId.c_str(), ex.what());
|
||||
results.push_back({
|
||||
{"status", "ERROR"},
|
||||
{"externalOrderId", externalOrderId},
|
||||
{"message", ex.what()}
|
||||
});
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
resp.send_json(200, results);
|
||||
|
||||
if (orders.empty()) {
|
||||
logc::info("POST /v1/order: no orders in body");
|
||||
} else {
|
||||
logc::info("POST /v1/order: %d order(s), %d OK, %d ERROR",
|
||||
static_cast<int>(orders.size()), successful, failed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../log.hpp"
|
||||
#include "../queries/image.hpp"
|
||||
|
||||
void handle_pimage(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_pimage(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
std::string path = req.get_query_param("path");
|
||||
if (path.empty()) {
|
||||
resp.send_json(400, {{"Message", "Missing required query parameter 'path'."}});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../router.hpp"
|
||||
#include "../queries/product_list.hpp"
|
||||
|
||||
void handle_product(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_product(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t cursor = std::stoll(req.get_query_param("lastChangedProduct", "0"));
|
||||
int limit = std::stoi(req.get_query_param("limit", "20"));
|
||||
auto products = get_product_list(cursor, limit);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../router.hpp"
|
||||
#include "../queries/composite_product_list.hpp"
|
||||
|
||||
void handle_productcomposite(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
void handle_productcomposite(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t cursor = std::stoll(req.get_query_param("lastChangedCompositeProduct", "0"));
|
||||
int limit = std::stoi(req.get_query_param("limit", "100"));
|
||||
auto composites = get_composite_product_list(cursor, limit);
|
||||
|
||||
Reference in New Issue
Block a user