commit 163e9225a622bcae3b59c2e6b055a1cd8cc82bed parent 0655c23916d747b9ef22b546d34d3d45ac486f8f Author: Christian Grothoff <christian@grothoff.org> Date: Fri, 4 Jul 2025 00:10:01 +0200 add product_name to inventory (#9511) Diffstat:
20 files changed, 83 insertions(+), 15 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_private-get-pos.c b/src/backend/taler-merchant-httpd_private-get-pos.c @@ -117,6 +117,8 @@ add_product (void *cls, json_array_append_new ( pa, GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("product_name", + pd->product_name), GNUNET_JSON_pack_string ("description", pd->description), GNUNET_JSON_pack_object_incref ("description_i18n", diff --git a/src/backend/taler-merchant-httpd_private-get-products-ID.c b/src/backend/taler-merchant-httpd_private-get-products-ID.c @@ -82,6 +82,8 @@ TMH_private_get_products_ID ( ret = TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, + GNUNET_JSON_pack_string ("product_name", + pd.product_name), GNUNET_JSON_pack_string ("description", pd.description), GNUNET_JSON_pack_object_steal ("description_i18n", diff --git a/src/backend/taler-merchant-httpd_private-patch-products-ID.c b/src/backend/taler-merchant-httpd_private-patch-products-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2020-2024 Taler Systems SA + (C) 2020--2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -49,6 +49,11 @@ TMH_private_patch_products_ID ( int64_t total_stock; enum GNUNET_DB_QueryStatus qs; struct GNUNET_JSON_Specification spec[] = { + /* new in protocol v20, thus optional for backwards-compatibility */ + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("product_name", + (const char **) &pd.product_name), + NULL), GNUNET_JSON_spec_string ("description", (const char **) &pd.description), GNUNET_JSON_spec_mark_optional ( @@ -114,6 +119,10 @@ TMH_private_patch_products_ID ( return (GNUNET_NO == res) ? MHD_YES : MHD_NO; + /* For pre-v20 clients, we use the description given as the + product name; remove once we make product_name mandatory. */ + if (NULL == pd.product_name) + pd.product_name = pd.description; } if (total_stock < -1) { diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -3677,6 +3677,8 @@ merge_inventory (struct OrderContext *oc) json_t *p; p = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("product_name", + pd.product_name), GNUNET_JSON_pack_string ("description", pd.description), GNUNET_JSON_pack_object_steal ("description_i18n", diff --git a/src/backend/taler-merchant-httpd_private-post-products.c b/src/backend/taler-merchant-httpd_private-post-products.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2020-2024 Taler Systems SA + (C) 2020-2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -41,6 +41,11 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("product_id", &product_id), + /* new in protocol v20, thus optional for backwards-compatibility */ + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("product_name", + (const char **) &pd.product_name), + NULL), GNUNET_JSON_spec_string ("description", (const char **) &pd.description), GNUNET_JSON_spec_mark_optional ( @@ -101,6 +106,10 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, ? MHD_YES : MHD_NO; } + /* For pre-v20 clients, we use the description given as the + product name; remove once we make product_name mandatory. */ + if (NULL == pd.product_name) + pd.product_name = pd.description; } if (total_stock < -1) { diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am @@ -35,6 +35,7 @@ sql_DATA = \ merchant-0016.sql \ merchant-0017.sql \ merchant-0018.sql \ + merchant-0019.sql \ drop.sql BUILT_SOURCES = \ diff --git a/src/backenddb/pg_insert_product.c b/src/backenddb/pg_insert_product.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022-2024 Taler Systems SA + Copyright (C) 2022-2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -26,6 +26,7 @@ #include "pg_insert_product.h" #include "pg_helper.h" + enum GNUNET_DB_QueryStatus TMH_PG_insert_product (void *cls, const char *instance_id, @@ -55,6 +56,7 @@ TMH_PG_insert_product (void *cls, GNUNET_PQ_query_param_array_uint64 (num_cats, cats, pg->conn), + GNUNET_PQ_query_param_string (pd->product_name), GNUNET_PQ_query_param_end }; uint64_t ncat; @@ -80,7 +82,7 @@ TMH_PG_insert_product (void *cls, ",out_no_cat AS no_cat" ",out_no_instance AS no_instance" " FROM merchant_do_insert_product" - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "insert_product", params, diff --git a/src/backenddb/pg_insert_product.sql b/src/backenddb/pg_insert_product.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2024 Taler Systems SA +-- Copyright (C) 2024, 2025 Taler Systems SA -- -- TALER is free software; you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software @@ -15,7 +15,8 @@ -- -CREATE OR REPLACE FUNCTION merchant_do_insert_product ( +DROP FUNCTION IF EXISTS merchant_do_insert_product; +CREATE FUNCTION merchant_do_insert_product ( IN in_instance_id TEXT, IN in_product_id TEXT, IN in_description TEXT, @@ -29,6 +30,7 @@ CREATE OR REPLACE FUNCTION merchant_do_insert_product ( IN in_next_restock INT8, IN in_minimum_age INT4, IN ina_categories INT8[], + IN in_product_name TEXT, OUT out_no_instance BOOL, OUT out_conflict BOOL, OUT out_no_cat INT8) @@ -59,6 +61,7 @@ out_no_instance=FALSE; INSERT INTO merchant_inventory (merchant_serial ,product_id + ,product_name ,description ,description_i18n ,unit @@ -72,6 +75,7 @@ INSERT INTO merchant_inventory ) VALUES ( my_merchant_id ,in_product_id + ,in_product_name ,in_description ,in_description_i18n ,in_unit @@ -95,6 +99,7 @@ THEN FROM merchant_inventory WHERE merchant_serial=my_merchant_id AND product_id=in_product_id + AND product_name=in_product_name AND description=in_description AND description_i18n=in_description_i18n AND unit=in_unit diff --git a/src/backenddb/pg_lookup_all_products.c b/src/backenddb/pg_lookup_all_products.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2024 Taler Systems SA + Copyright (C) 2024, 2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -80,6 +80,8 @@ lookup_products_cb (void *cls, &product_id), GNUNET_PQ_result_spec_uint64 ("product_serial", &product_serial), + GNUNET_PQ_result_spec_string ("product_name", + &pd.product_name), GNUNET_PQ_result_spec_string ("description", &pd.description), TALER_PQ_result_spec_json ("description_i18n", @@ -157,6 +159,7 @@ TMH_PG_lookup_all_products (void *cls, "SELECT" " description" ",description_i18n" + ",product_name" ",unit" ",price" ",taxes" diff --git a/src/backenddb/pg_lookup_product.c b/src/backenddb/pg_lookup_product.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022, 2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -46,6 +46,7 @@ TMH_PG_lookup_product (void *cls, "SELECT" " mi.description" ",mi.description_i18n" + ",mi.product_name" ",mi.unit" ",mi.price" ",mi.taxes" @@ -84,6 +85,7 @@ TMH_PG_lookup_product (void *cls, } else { + char *my_name = NULL; char *my_description = NULL; json_t *my_description_i18n = NULL; char *my_unit = NULL; @@ -96,6 +98,8 @@ TMH_PG_lookup_product (void *cls, &my_description), TALER_PQ_result_spec_json ("description_i18n", &my_description_i18n), + GNUNET_PQ_result_spec_string ("product_name", + &my_name), GNUNET_PQ_result_spec_string ("unit", &my_unit), TALER_PQ_result_spec_amount_with_currency ("price", @@ -129,6 +133,7 @@ TMH_PG_lookup_product (void *cls, "lookup_product", params, rs); + pd->product_name = my_name; pd->description = my_description; pd->description_i18n = my_description_i18n; pd->unit = my_unit; @@ -137,6 +142,7 @@ TMH_PG_lookup_product (void *cls, pd->address = my_address; *categories = my_categories; /* Clear original pointers to that cleanup_result doesn't squash them */ + my_name = NULL; my_description = NULL; my_description_i18n = NULL; my_unit = NULL; diff --git a/src/backenddb/pg_update_product.c b/src/backenddb/pg_update_product.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022, 2024 Taler Systems SA + Copyright (C) 2022, 2024, 2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -60,6 +60,7 @@ TMH_PG_update_product (void *cls, GNUNET_PQ_query_param_array_uint64 (num_cats, cats, pg->conn), + GNUNET_PQ_query_param_string (pd->product_name), GNUNET_PQ_query_param_end }; uint64_t ncat; @@ -101,7 +102,7 @@ TMH_PG_update_product (void *cls, ",out_no_cat AS no_cat" ",out_no_instance AS no_instance" " FROM merchant_do_update_product" - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);"); + "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "update_product", params, diff --git a/src/backenddb/pg_update_product.sql b/src/backenddb/pg_update_product.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2024 Taler Systems SA +-- Copyright (C) 2024, 2025 Taler Systems SA -- -- TALER is free software; you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software @@ -15,7 +15,8 @@ -- -CREATE OR REPLACE FUNCTION merchant_do_update_product ( +DROP FUNCTION IF EXISTS merchant_do_update_product; +CREATE FUNCTION merchant_do_update_product ( IN in_instance_id TEXT, IN in_product_id TEXT, IN in_description TEXT, @@ -30,6 +31,7 @@ CREATE OR REPLACE FUNCTION merchant_do_update_product ( IN in_next_restock INT8, IN in_minimum_age INT4, IN ina_categories INT8[], + IN in_product_name TEXT, OUT out_no_instance BOOL, OUT out_no_product BOOL, OUT out_lost_reduced BOOL, @@ -121,6 +123,7 @@ END LOOP; UPDATE merchant_inventory SET description=in_description ,description_i18n=in_description_i18n + ,product_name=in_product_name ,unit=in_unit ,image=in_image ,taxes=in_taxes diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -716,6 +716,7 @@ make_product (const char *id, struct ProductData *product) { product->id = id; + product->product.product_name = "Test product"; product->product.description = "This is a test product"; product->product.description_i18n = json_array (); GNUNET_assert (NULL != product->product.description_i18n); diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h @@ -1644,6 +1644,11 @@ struct TALER_MERCHANT_ProductGetResponse * #GNUNET_TIME_UNIT_FOREVER_ABS for 'never'. */ struct GNUNET_TIME_Timestamp next_restock; + + /** + * name of the product + */ + const char *product_name; } ok; } details; diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h @@ -291,6 +291,11 @@ typedef void struct TALER_MERCHANTDB_ProductDetails { /** + * Name of the product. + */ + char *product_name; + + /** * Description of the product. */ char *description; diff --git a/src/lib/merchant_api_get_product.c b/src/lib/merchant_api_get_product.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2024 Taler Systems SA + Copyright (C) 2014--2025 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -94,6 +94,9 @@ handle_get_product_finished (void *cls, { struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ( + "product_name", + &pgr.details.ok.product_name), + GNUNET_JSON_spec_string ( "description", &pgr.details.ok.description), GNUNET_JSON_spec_object_const ( diff --git a/src/lib/merchant_api_patch_product.c b/src/lib/merchant_api_patch_product.c @@ -178,6 +178,10 @@ TALER_MERCHANT_product_patch ( json_t *req_obj; req_obj = GNUNET_JSON_PACK ( + /* FIXME: once we move to the new-style API, + allow applications to set the product name properly! */ + GNUNET_JSON_pack_string ("product_name", + description), GNUNET_JSON_pack_string ("description", description), GNUNET_JSON_pack_object_incref ("description_i18n", diff --git a/src/lib/merchant_api_post_products.c b/src/lib/merchant_api_post_products.c @@ -198,6 +198,10 @@ TALER_MERCHANT_products_post3 ( req_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("product_id", product_id), + /* FIXME: once we move to the new-style API, + allow applications to set the product name properly! */ + GNUNET_JSON_pack_string ("product_name", + description), GNUNET_JSON_pack_string ("description", description), GNUNET_JSON_pack_allow_null ( diff --git a/src/testing/test_merchant_api.conf b/src/testing/test_merchant_api.conf @@ -38,6 +38,7 @@ CURRENCY = EUR PORT = 8080 SERVE = tcp DB = postgres +STRICT_PROTOCOL_V19 = YES [merchantdb-postgres] CONFIG = postgres:///talercheck diff --git a/src/testing/test_merchant_product_creation.sh b/src/testing/test_merchant_product_creation.sh @@ -89,8 +89,8 @@ fi echo "OK" RANDOM_IMG='data:image/png;base64,abcdefg' -INFINITE_PRODUCT_TEMPLATE='{"product_id":"2","description":"product with id 2 and price :15","price":"TESTKUDOS:15","total_stock":-1,"unit":"","image":"'"$RANDOM_IMG"'","taxes":[]}' -MANAGED_PRODUCT_TEMPLATE='{"product_id":"3","description":"product with id 3 and price :10","price":"TESTKUDOS:150","total_stock":2,"unit":"","image":"'"$RANDOM_IMG"'","taxes":[]}' +INFINITE_PRODUCT_TEMPLATE='{"product_id":"2","product_name":"stuff","description":"product with id 2 and price :15","price":"TESTKUDOS:15","total_stock":-1,"unit":"","image":"'"$RANDOM_IMG"'","taxes":[]}' +MANAGED_PRODUCT_TEMPLATE='{"product_id":"3","product_name":"more stuff","description":"product with id 3 and price :10","price":"TESTKUDOS:150","total_stock":2,"unit":"","image":"'"$RANDOM_IMG"'","taxes":[]}' echo -n "Creating products..." STATUS=$(curl 'http://localhost:9966/private/products' \