u
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
#include "../queries/category_list.hpp"
|
||||
|
||||
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"));
|
||||
int64_t cursor = req.get_query_int64("lastChangedCategory");
|
||||
int limit = req.get_query_int("limit", 20);
|
||||
auto categories = get_category_list(cursor, limit);
|
||||
resp.send_json(200, categories);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,27 @@
|
||||
#include "../tls_server.hpp"
|
||||
#include "../router.hpp"
|
||||
|
||||
static std::string config_string(const json& config, const char* key,
|
||||
const std::string& def = "") {
|
||||
if (!config.is_object()) return def;
|
||||
json v = config.value(key, json());
|
||||
if (v.is_null()) return def;
|
||||
if (v.is_string()) return v.get<std::string>();
|
||||
if (v.is_number_integer()) return std::to_string(v.get<int64_t>());
|
||||
if (v.is_number_unsigned()) return std::to_string(v.get<uint64_t>());
|
||||
return def;
|
||||
}
|
||||
|
||||
static json build_client_step1(const json& config) {
|
||||
return {
|
||||
{"authCode", nullptr},
|
||||
{"authToken", config["authToken"]},
|
||||
{"certificateFingerprint", config["certificateFingerprint"]},
|
||||
{"certificateSerialNumber", config["certificateSerialNumber"]},
|
||||
{"mandantId", config["mandantId"]},
|
||||
{"authToken", config_string(config, "authToken")},
|
||||
{"certificateFingerprint", config_string(config, "certificateFingerprint")},
|
||||
{"certificateSerialNumber", config_string(config, "certificateSerialNumber")},
|
||||
{"mandantId", config_string(config, "mandantId")},
|
||||
{"mandantName", nullptr},
|
||||
{"mandantDatabase", nullptr},
|
||||
{"serverFingerprint", config["serverFingerprint"]},
|
||||
{"serverFingerprint", config_string(config, "serverFingerprint")},
|
||||
{"name", nullptr},
|
||||
{"serverTimestamp", server_timestamp()},
|
||||
};
|
||||
@@ -24,12 +35,12 @@ static json build_client_step1(const json& config) {
|
||||
static json build_client_step2(const std::string& auth_code, const json& config) {
|
||||
return {
|
||||
{"authCode", auth_code},
|
||||
{"authToken", config["authToken"]},
|
||||
{"certificateFingerprint", config["certificateFingerprint"]},
|
||||
{"certificateSerialNumber", config["certificateSerialNumber"]},
|
||||
{"mandantId", config["mandantId"]},
|
||||
{"mandantName", config["mandantName"]},
|
||||
{"mandantDatabase", config["mandantDatabase"]},
|
||||
{"authToken", config_string(config, "authToken")},
|
||||
{"certificateFingerprint", config_string(config, "certificateFingerprint")},
|
||||
{"certificateSerialNumber", config_string(config, "certificateSerialNumber")},
|
||||
{"mandantId", config_string(config, "mandantId")},
|
||||
{"mandantName", config_string(config, "mandantName")},
|
||||
{"mandantDatabase", config_string(config, "mandantDatabase")},
|
||||
{"serverFingerprint", nullptr},
|
||||
{"name", nullptr},
|
||||
{"serverTimestamp", server_timestamp()},
|
||||
@@ -47,7 +58,7 @@ void handle_client(HttpRequest& req, HttpResponse& resp, RouteContext& ctx) {
|
||||
if (auth_code.size() == 6) {
|
||||
if (ctx.pairing_store->has_pairing_code(auth_code)) {
|
||||
ctx.pairing_store->revoke_pairing_code(auth_code);
|
||||
ctx.pairing_store->register_device(ctx.config["authToken"].get<std::string>(), name);
|
||||
ctx.pairing_store->register_device(config_string(ctx.config, "authToken"), name);
|
||||
return resp.send_json(200, build_client_step2(auth_code, ctx.config));
|
||||
}
|
||||
return resp.send_json(400, {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../queries/customer_groups.hpp"
|
||||
|
||||
void handle_customergroup(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
int64_t cursor = std::stoll(req.get_query_param("lastChangedCustomerGroup", "0"));
|
||||
int64_t cursor = req.get_query_int64("lastChangedCustomerGroup");
|
||||
auto groups = get_customer_group_list(cursor);
|
||||
resp.send_json(200, groups);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "../queries/deleted_entity_list.hpp"
|
||||
|
||||
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"));
|
||||
int64_t cursor = req.get_query_int64("lastChangedDeletedEntity");
|
||||
int limit = req.get_query_int("limit", 600);
|
||||
auto deleted = get_deleted_entity_list(cursor, limit);
|
||||
resp.send_json(200, deleted);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include "../config.hpp"
|
||||
|
||||
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"));
|
||||
int64_t composite_cursor = std::stoll(req.get_query_param("lastChangedCompositeProduct", "0"));
|
||||
int64_t deleted_cursor = std::stoll(req.get_query_param("lastChangedDeletedEntity", "0"));
|
||||
int64_t product_cursor = req.get_query_int64("lastChangedProduct");
|
||||
int64_t category_cursor = req.get_query_int64("lastChangedCategory");
|
||||
int64_t cg_cursor = req.get_query_int64("lastChangedCustomerGroup");
|
||||
int64_t composite_cursor = req.get_query_int64("lastChangedCompositeProduct");
|
||||
int64_t deleted_cursor = req.get_query_int64("lastChangedDeletedEntity");
|
||||
|
||||
int root = config::get_int("ROOT_CATEGORY_ID", 1);
|
||||
int shop = get_active_shop_id();
|
||||
@@ -27,9 +27,6 @@ void handle_init(HttpRequest& req, HttpResponse& resp, RouteContext& /*ctx*/) {
|
||||
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");
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "../queries/product_list.hpp"
|
||||
|
||||
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"));
|
||||
int64_t cursor = req.get_query_int64("lastChangedProduct");
|
||||
int limit = req.get_query_int("limit", 20);
|
||||
auto products = get_product_list(cursor, limit);
|
||||
resp.send_json(200, products);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "../queries/composite_product_list.hpp"
|
||||
|
||||
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"));
|
||||
int64_t cursor = req.get_query_int64("lastChangedCompositeProduct");
|
||||
int limit = req.get_query_int("limit", 100);
|
||||
auto composites = get_composite_product_list(cursor, limit);
|
||||
resp.send_json(200, composites);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user