diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-08-04 22:31:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-08-04 22:31:41 +0200 |
commit | 347695fa07bf2bb3a0d818fa2381731f2178e0e9 (patch) | |
tree | ede0a33fe01c92fc3909cb89eff16f47633175f7 | |
parent | 78bdd0933ca0df12ed0caeafb500d703da8e4398 (diff) |
fix select_category implementation
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-categories-ID.c | 27 | ||||
-rw-r--r-- | src/backenddb/pg_select_category.c | 17 | ||||
-rw-r--r-- | src/backenddb/pg_select_category.h | 5 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 5 |
4 files changed, 21 insertions, 33 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-categories-ID.c b/src/backend/taler-merchant-httpd_private-get-categories-ID.c index eb474ae9..85c0b9d8 100644 --- a/src/backend/taler-merchant-httpd_private-get-categories-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-categories-ID.c @@ -43,7 +43,7 @@ TMH_private_get_categories_ID ( char dummy; struct TALER_MERCHANTDB_CategoryDetails cd; size_t num_products = 0; - const char* *products = NULL; + char *products = NULL; GNUNET_assert (NULL != mi); GNUNET_assert (NULL != hc->infix); @@ -53,10 +53,11 @@ TMH_private_get_categories_ID ( &dummy)) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "category_id must be a number"); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "category_id must be a number"); } qs = TMH_db->select_category (TMH_db->cls, @@ -83,30 +84,24 @@ TMH_private_get_categories_ID ( { MHD_RESULT ret; json_t *jproducts; + const char *pos = products; jproducts = json_array (); GNUNET_assert (NULL != jproducts); for (unsigned int i = 0; i<num_products; i++) { - const char* product_id = &products[i]; + const char *product_id = pos; json_t *jprod; + pos = pos + strlen (product_id) + 1; jprod = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("product_id", - product_id) - // FIXME: also return product details - // GNUNET_JSON_pack_string ("product_id", - // product->product_id), - // GNUNET_JSON_pack_string ("description", - // product->description), - // GNUNET_JSON_pack_object_steal ("description_i18n", - // product->description_i18n) - ); + product_id)); GNUNET_assert (0 == json_array_append_new (jproducts, jprod)); } - + GNUNET_free (products); ret = TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, diff --git a/src/backenddb/pg_select_category.c b/src/backenddb/pg_select_category.c index 74e69a0b..58747d71 100644 --- a/src/backenddb/pg_select_category.c +++ b/src/backenddb/pg_select_category.c @@ -32,7 +32,7 @@ TMH_PG_select_category (void *cls, uint64_t category_id, struct TALER_MERCHANTDB_CategoryDetails *cd, size_t *num_products, - const char* **products) + char **products) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -48,10 +48,11 @@ TMH_PG_select_category (void *cls, }; check_connection (pg); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "select_category", - params, - rs_null); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "select_category", + params, + rs_null); } else { @@ -80,9 +81,6 @@ TMH_PG_select_category (void *cls, " SELECT ARRAY (" " SELECT " " mi.product_id AS product_id" - // FIXME: also return product details (or NOT) - // " ,mi.description AS description" - // " ,mi.description_i18n AS description_i18n" " FROM merchant_product_categories mpc" " JOIN merchant_inventory mi" " USING (product_serial)" @@ -91,14 +89,11 @@ TMH_PG_select_category (void *cls, " ) t" " WHERE inst.merchant_id=$1" " AND mc.category_serial=$2"); - - check_connection (pg); return GNUNET_PQ_eval_prepared_singleton_select ( pg->conn, "select_category", params, rs); - } } diff --git a/src/backenddb/pg_select_category.h b/src/backenddb/pg_select_category.h index 3b6e458b..eecf170e 100644 --- a/src/backenddb/pg_select_category.h +++ b/src/backenddb/pg_select_category.h @@ -35,8 +35,7 @@ * @param[out] cd set to the category details on success, can be NULL * (in that case we only want to check if the category exists) * @param[out] num_products set to length of @a products array - * @param[out] products set to array of products the - * category is in, caller must free() it. + * @param[out] products set to buffer with @a num_products 0-terminated strings with the product IDs, caller must free() it. * @return database result code */ enum GNUNET_DB_QueryStatus @@ -45,6 +44,6 @@ TMH_PG_select_category (void *cls, uint64_t category_id, struct TALER_MERCHANTDB_CategoryDetails *cd, size_t *num_products, - const char* **products); + char **products); #endif diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 7c7f7fbe..7882f789 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -3267,8 +3267,7 @@ struct TALER_MERCHANTDB_Plugin * @param[out] cd set to the category details on success, can be NULL * (in that case we only want to check if the category exists) * @param[out] num_products set to length of @a products array - * @param[out] products set to array of products the - * category is in, caller must free() it. + * @param[out] products set to buffer with @a num_products 0-terminated strings with the product IDs, caller must free() it. * @return database result code */ enum GNUNET_DB_QueryStatus @@ -3277,7 +3276,7 @@ struct TALER_MERCHANTDB_Plugin uint64_t category_id, struct TALER_MERCHANTDB_CategoryDetails *cd, size_t *num_products, - const char* **products); + char **products); /** |