From 0ce49789c7c63be9149e9938efcd3f7c4839dff9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 15 Sep 2024 00:55:47 +0200 Subject: fix category array construction (#8834) --- src/backend/taler-merchant-httpd_private-get-pos.c | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src') diff --git a/src/backend/taler-merchant-httpd_private-get-pos.c b/src/backend/taler-merchant-httpd_private-get-pos.c index f8f84400..6221fc08 100644 --- a/src/backend/taler-merchant-httpd_private-get-pos.c +++ b/src/backend/taler-merchant-httpd_private-get-pos.c @@ -40,6 +40,40 @@ struct Context }; +/** + * Add category to the @e ca array. + * + * @param cls a `struct Context` with JSON arrays to build + * @param category_id ID of the category + * @param category_name name of the category + * @param category_name_i18n translations of the @a category_name + * @param product_count number of products in the category + */ +static void +add_category ( + void *cls, + uint64_t category_id, + const char *category_name, + const json_t *category_name_i18n, + uint64_t product_count) +{ + struct Context *ctx = cls; + + (void) product_count; + GNUNET_assert ( + 0 == + json_array_append_new ( + ctx->ca, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("id", + category_id), + GNUNET_JSON_pack_object_incref ("name_i18n", + (json_t *) category_name_i18n), + GNUNET_JSON_pack_string ("name", + category_name)))); +} + + /** * Add product details to our JSON array. * @@ -134,6 +168,20 @@ TMH_private_get_pos (const struct TMH_RequestHandler *rh, 0), GNUNET_JSON_pack_string ("name", "default")))); + qs = TMH_db->lookup_categories (TMH_db->cls, + hc->instance->settings.id, + &add_category, + &ctx); + if (0 > qs) + { + GNUNET_break (0); + json_decref (ctx.pa); + json_decref (ctx.ca); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + } qs = TMH_db->lookup_all_products (TMH_db->cls, hc->instance->settings.id, &add_product, -- cgit v1.2.3