merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 0ce49789c7c63be9149e9938efcd3f7c4839dff9
parent e2354ce622ea3ba015ece7607ee01754fd135f78
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 15 Sep 2024 00:55:47 +0200

fix category array construction (#8834)

Diffstat:
Msrc/backend/taler-merchant-httpd_private-get-pos.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-pos.c b/src/backend/taler-merchant-httpd_private-get-pos.c @@ -41,6 +41,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. * * @param cls a `struct Context` with JSON arrays to build @@ -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,