gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated (a97ee62d -> 8fc047dd)


From: gnunet
Subject: [taler-merchant] branch master updated (a97ee62d -> 8fc047dd)
Date: Mon, 13 May 2024 13:50:50 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository merchant.

    from a97ee62d enforce RFC 8959 prefix for passwords
     new 0e0751a1 implement protocol spec v15
     new 8fc047dd add ref to bug

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 contrib/wallet-core                                |   2 +-
 src/backend/Makefile.am                            |   2 +
 src/backend/taler-merchant-httpd.c                 |   7 +
 src/backend/taler-merchant-httpd_config.c          |   2 +-
 src/backend/taler-merchant-httpd_private-get-pos.c | 145 +++++++++++++++++++++
 ...ID.h => taler-merchant-httpd_private-get-pos.h} |  21 ++-
 .../taler-merchant-httpd_private-get-products-ID.c |  22 ++--
 src/backenddb/Makefile.am                          |   1 +
 ..._lookup_products.c => pg_lookup_all_products.c} |  88 ++++++++-----
 ..._lookup_products.h => pg_lookup_all_products.h} |  22 ++--
 src/backenddb/pg_lookup_product.c                  |   2 +-
 src/backenddb/plugin_merchantdb_postgres.c         |   3 +
 src/include/taler_merchant_service.h               |   6 +-
 src/include/taler_merchantdb_plugin.h              |  32 +++++
 src/lib/merchant_api_get_config.c                  |   4 +-
 src/lib/merchant_api_get_product.c                 |  31 +++--
 16 files changed, 302 insertions(+), 88 deletions(-)
 create mode 100644 src/backend/taler-merchant-httpd_private-get-pos.c
 copy src/backend/{taler-merchant-httpd_get-templates-ID.h => 
taler-merchant-httpd_private-get-pos.h} (67%)
 copy src/backenddb/{pg_lookup_products.c => pg_lookup_all_products.c} (59%)
 copy src/backenddb/{pg_lookup_products.h => pg_lookup_all_products.h} (71%)

diff --git a/contrib/wallet-core b/contrib/wallet-core
index 68b2ef73..240d647d 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit 68b2ef735377373da29fd20aeb9facaf91c03832
+Subproject commit 240d647da85de6b575d15c37efec04757541e3dc
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index dbc7cde8..65ffa514 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -65,6 +65,8 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_private-get-instances-ID.h \
   taler-merchant-httpd_private-get-instances-ID-kyc.c \
     taler-merchant-httpd_private-get-instances-ID-kyc.h \
+  taler-merchant-httpd_private-get-pos.c \
+    taler-merchant-httpd_private-get-pos.h \
   taler-merchant-httpd_private-get-products.c \
     taler-merchant-httpd_private-get-products.h \
   taler-merchant-httpd_private-get-products-ID.c \
diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 7384bfc9..0fa83d81 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -48,6 +48,7 @@
 #include "taler-merchant-httpd_private-get-instances.h"
 #include "taler-merchant-httpd_private-get-instances-ID.h"
 #include "taler-merchant-httpd_private-get-instances-ID-kyc.h"
+#include "taler-merchant-httpd_private-get-pos.h"
 #include "taler-merchant-httpd_private-get-products.h"
 #include "taler-merchant-httpd_private-get-products-ID.h"
 #include "taler-merchant-httpd_private-get-orders.h"
@@ -932,6 +933,12 @@ url_handler (void *cls,
       .method = MHD_HTTP_METHOD_GET,
       .handler = &TMH_private_get_instances_ID_kyc,
     },
+    /* GET /pos: */
+    {
+      .url_prefix = "/pos",
+      .method = MHD_HTTP_METHOD_GET,
+      .handler = &TMH_private_get_pos
+    },
     /* GET /products: */
     {
       .url_prefix = "/products",
diff --git a/src/backend/taler-merchant-httpd_config.c 
b/src/backend/taler-merchant-httpd_config.c
index d1340249..97dd1714 100644
--- a/src/backend/taler-merchant-httpd_config.c
+++ b/src/backend/taler-merchant-httpd_config.c
@@ -42,7 +42,7 @@
  * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
  * merchant_api_config.c!
  */
-#define MERCHANT_PROTOCOL_VERSION "14:1:10"
+#define MERCHANT_PROTOCOL_VERSION "15:0:11"
 
 
 /**
diff --git a/src/backend/taler-merchant-httpd_private-get-pos.c 
b/src/backend/taler-merchant-httpd_private-get-pos.c
new file mode 100644
index 00000000..681b90c4
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pos.c
@@ -0,0 +1,145 @@
+/*
+  This file is part of TALER
+  (C) 2019, 2020, 2021, 2024 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 published by the Free 
Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-merchant-httpd_private-get-pos.c
+ * @brief implement GET /private/pos
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_private-get-pos.h"
+
+
+/**
+ * Closure for add_product().
+ */
+struct Context
+{
+  /**
+   * JSON array of products we are building.
+   */
+  json_t *pa;
+
+  /**
+   * JSON array of categories we are building.
+   */
+  json_t *ca;
+
+};
+
+
+/**
+ * Add product details to our JSON array.
+ *
+ * @param ctx a `struct Context` with JSON arrays to build
+ * @param product_id ID of the product
+ */
+static void
+add_product (void *cls,
+             uint64_t product_serial,
+             const char *product_id,
+             const struct TALER_MERCHANTDB_ProductDetails *pd)
+{
+  struct Context *ctx = cls;
+  json_t *pa = ctx->pa;
+  json_t *cata;
+
+  /* FIXME-8839: add proper category support! */
+  cata = json_array ();
+  GNUNET_assert (
+    0 == json_array_append_new (
+      cata,
+      json_integer (0)));
+  GNUNET_assert (
+    0 ==
+    json_array_append_new (
+      pa,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_string ("description",
+                                 pd->description),
+        GNUNET_JSON_pack_object_incref ("description_i18n",
+                                        (json_t *) pd->description_i18n),
+        GNUNET_JSON_pack_string ("unit",
+                                 pd->unit),
+        TALER_JSON_pack_amount ("price",
+                                &pd->price),
+        GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_string ("image",
+                                   pd->image)),
+        GNUNET_JSON_pack_array_steal ("categories",
+                                      cata),
+        GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_array_incref ("taxes",
+                                         (json_t *) pd->taxes)),
+        (INT64_MAX == pd->total_stock)
+        ? GNUNET_JSON_pack_int64 ("total_stock",
+                                  pd->total_stock)
+        : GNUNET_JSON_pack_allow_null (
+          GNUNET_JSON_pack_string ("total_stock",
+                                   NULL)),
+        GNUNET_JSON_pack_uint64 ("minimum_age",
+                                 pd->minimum_age),
+        GNUNET_JSON_pack_uint64 ("product_serial",
+                                 product_serial),
+        GNUNET_JSON_pack_string ("product_id",
+                                 product_id))));
+}
+
+
+MHD_RESULT
+TMH_private_get_pos (const struct TMH_RequestHandler *rh,
+                     struct MHD_Connection *connection,
+                     struct TMH_HandlerContext *hc)
+{
+  struct Context ctx;
+  enum GNUNET_DB_QueryStatus qs;
+
+  ctx.pa = json_array ();
+  GNUNET_assert (NULL != ctx.pa);
+  ctx.ca = json_array ();
+  GNUNET_assert (NULL != ctx.ca);
+  GNUNET_assert (
+    0 == json_array_append_new (
+      ctx.ca,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_uint64 ("id",
+                                 0),
+        GNUNET_JSON_pack_string ("name",
+                                 "default"))));
+  qs = TMH_db->lookup_all_products (TMH_db->cls,
+                                    hc->instance->settings.id,
+                                    &add_product,
+                                    &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);
+  }
+  return TALER_MHD_REPLY_JSON_PACK (
+    connection,
+    MHD_HTTP_OK,
+    GNUNET_JSON_pack_array_steal ("categories",
+                                  ctx.ca),
+    GNUNET_JSON_pack_array_steal ("products",
+                                  ctx.pa));
+}
+
+
+/* end of taler-merchant-httpd_private-get-pos.c */
diff --git a/src/backend/taler-merchant-httpd_get-templates-ID.h 
b/src/backend/taler-merchant-httpd_private-get-pos.h
similarity index 67%
copy from src/backend/taler-merchant-httpd_get-templates-ID.h
copy to src/backend/taler-merchant-httpd_private-get-pos.h
index 2fc4c0d8..ce266823 100644
--- a/src/backend/taler-merchant-httpd_get-templates-ID.h
+++ b/src/backend/taler-merchant-httpd_private-get-pos.h
@@ -14,18 +14,18 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file taler-merchant-httpd_private-get-templates-ID.h
- * @brief implement GET /templates/$ID/
- * @author Priscilla HUANG
+ * @file taler-merchant-httpd_private-get-pos.h
+ * @brief implement GET /pos
+ * @author Christian Grothoff
  */
-#ifndef TALER_MERCHANT_HTTPD_GET_TEMPLATES_ID_H
-#define TALER_MERCHANT_HTTPD_GET_TEMPLATES_ID_H
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_POS_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_GET_POS_H
 
 #include "taler-merchant-httpd.h"
 
 
 /**
- * Handle a GET "/templates/$ID" request.
+ * Handle a GET "/pos" request.
  *
  * @param rh context of the handler
  * @param connection the MHD connection to handle
@@ -33,10 +33,9 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_get_templates_ID (
-  const struct TMH_RequestHandler *rh,
-  struct MHD_Connection *connection,
-  struct TMH_HandlerContext *hc);
+TMH_private_get_pos (const struct TMH_RequestHandler *rh,
+                     struct MHD_Connection *connection,
+                     struct TMH_HandlerContext *hc);
 
-/* end of taler-merchant-httpd_get-templates-ID.h */
+/* end of taler-merchant-httpd_private-get-pos.h */
 #endif
diff --git a/src/backend/taler-merchant-httpd_private-get-products-ID.c 
b/src/backend/taler-merchant-httpd_private-get-products-ID.c
index 1406349f..107081f7 100644
--- a/src/backend/taler-merchant-httpd_private-get-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-products-ID.c
@@ -32,9 +32,10 @@
  * @return MHD result code
  */
 MHD_RESULT
-TMH_private_get_products_ID (const struct TMH_RequestHandler *rh,
-                             struct MHD_Connection *connection,
-                             struct TMH_HandlerContext *hc)
+TMH_private_get_products_ID (
+  const struct TMH_RequestHandler *rh,
+  struct MHD_Connection *connection,
+  struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
   struct TALER_MERCHANTDB_ProductDetails pd = { 0 };
@@ -74,10 +75,12 @@ TMH_private_get_products_ID (const struct 
TMH_RequestHandler *rh,
                                pd.unit),
       TALER_JSON_pack_amount ("price",
                               &pd.price),
-      GNUNET_JSON_pack_string ("image",
-                               pd.image),
-      GNUNET_JSON_pack_array_steal ("taxes",
-                                    pd.taxes),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_string ("image",
+                                 pd.image)),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_array_steal ("taxes",
+                                      pd.taxes)),
       GNUNET_JSON_pack_int64 ("total_stock",
                               (INT64_MAX == pd.total_stock)
                               ? -1LL
@@ -86,8 +89,9 @@ TMH_private_get_products_ID (const struct TMH_RequestHandler 
*rh,
                                pd.total_sold),
       GNUNET_JSON_pack_uint64 ("total_lost",
                                pd.total_lost),
-      GNUNET_JSON_pack_object_steal ("address",
-                                     pd.address),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_object_steal ("address",
+                                       pd.address)),
       GNUNET_JSON_pack_allow_null (
         GNUNET_JSON_pack_timestamp ("next_restock",
                                     (pd.next_restock))),
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index defc3cf9..89be9a4f 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -112,6 +112,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
   pg_update_template.h pg_update_template.c \
   pg_lookup_templates.h pg_lookup_templates.c \
   pg_lookup_template.h pg_lookup_template.c \
+  pg_lookup_all_products.h pg_lookup_all_products.c \
   pg_lookup_products.h pg_lookup_products.c \
   pg_lookup_product.h pg_lookup_product.c \
   pg_delete_product.h pg_delete_product.c \
diff --git a/src/backenddb/pg_lookup_products.c 
b/src/backenddb/pg_lookup_all_products.c
similarity index 59%
copy from src/backenddb/pg_lookup_products.c
copy to src/backenddb/pg_lookup_all_products.c
index fa2887a8..29751a45 100644
--- a/src/backenddb/pg_lookup_products.c
+++ b/src/backenddb/pg_lookup_all_products.c
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2024 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
@@ -14,9 +14,9 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_products.c
- * @brief Implementation of the lookup_products function for Postgres
- * @author Iván Ávalos
+ * @file backenddb/pg_lookup_all_products.c
+ * @brief Implementation of the lookup_all_products function for Postgres
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include <taler/taler_error_codes.h>
@@ -26,14 +26,14 @@
 #include "pg_helper.h"
 
 /**
- * Context used for TMH_PG_lookup_products().
+ * Context used for TMH_PG_lookup_all_products().
  */
 struct LookupProductsContext
 {
   /**
    * Function to call with the results.
    */
-  TALER_MERCHANTDB_ProductsCallback cb;
+  TALER_MERCHANTDB_ProductCallback cb;
 
   /**
    * Closure for @a cb.
@@ -66,11 +66,36 @@ lookup_products_cb (void *cls,
   {
     char *product_id;
     uint64_t product_serial;
+    struct TALER_MERCHANTDB_ProductDetails pd;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_string ("product_id",
                                     &product_id),
       GNUNET_PQ_result_spec_uint64 ("product_serial",
                                     &product_serial),
+      GNUNET_PQ_result_spec_string ("description",
+                                    &pd.description),
+      TALER_PQ_result_spec_json ("description_i18n",
+                                 &pd.description_i18n),
+      GNUNET_PQ_result_spec_string ("unit",
+                                    &pd.unit),
+      TALER_PQ_result_spec_amount_with_currency ("price",
+                                   &pd.price),
+      TALER_PQ_result_spec_json ("taxes",
+                                 &pd.taxes),
+      GNUNET_PQ_result_spec_uint64 ("total_stock",
+                                    &pd.total_stock),
+      GNUNET_PQ_result_spec_uint64 ("total_sold",
+                                    &pd.total_sold),
+      GNUNET_PQ_result_spec_uint64 ("total_lost",
+                                    &pd.total_lost),
+      GNUNET_PQ_result_spec_string ("image",
+                                    &pd.image),
+      TALER_PQ_result_spec_json ("address",
+                                 &pd.address),
+      GNUNET_PQ_result_spec_timestamp ("next_restock",
+                                       &pd.next_restock),
+      GNUNET_PQ_result_spec_uint32 ("minimum_age",
+                                    &pd.minimum_age),
       GNUNET_PQ_result_spec_end
     };
 
@@ -85,22 +110,20 @@ lookup_products_cb (void *cls,
     }
     plc->cb (plc->cb_cls,
              product_serial,
-             product_id);
+             product_id,
+             &pd);
     GNUNET_PQ_cleanup_result (rs);
   }
 }
 
 
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_products (void *cls,
+TMH_PG_lookup_all_products (void *cls,
                         const char *instance_id,
-                        uint64_t offset,
-                        int64_t limit,
-                        TALER_MERCHANTDB_ProductsCallback cb,
+                        TALER_MERCHANTDB_ProductCallback cb,
                         void *cb_cls)
 {
   struct PostgresClosure *pg = cls;
-  uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
   struct LookupProductsContext plc = {
     .cb = cb,
     .cb_cls = cb_cls,
@@ -109,42 +132,35 @@ TMH_PG_lookup_products (void *cls,
   };
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (instance_id),
-    GNUNET_PQ_query_param_uint64 (&offset),
-    GNUNET_PQ_query_param_uint64 (&plimit),
     GNUNET_PQ_query_param_end
   };
   enum GNUNET_DB_QueryStatus qs;
 
   check_connection (pg);
   PREPARE (pg,
-           "lookup_products_asc",
+           "lookup_all_products",
            "SELECT"
-           "  product_id"
-           " ,product_serial"
+           " description"
+           ",description_i18n"
+           ",unit"
+           ",price"
+           ",taxes"
+           ",total_stock"
+           ",total_sold"
+           ",total_lost"
+           ",image"
+           ",merchant_inventory.address"
+           ",next_restock"
+           ",minimum_age"
+           ",product_id"
+           ",product_serial"
            " FROM merchant_inventory"
            " JOIN merchant_instances"
            "   USING (merchant_serial)"
-           " WHERE merchant_instances.merchant_id=$1"
-           "   AND product_serial > $2"
-           " ORDER BY product_serial ASC"
-           " LIMIT $3");
-  PREPARE (pg,
-           "lookup_products_desc",
-           "SELECT"
-           "  product_id"
-           " ,product_serial"
-           " FROM merchant_inventory"
-           " JOIN merchant_instances"
-           "   USING (merchant_serial)"
-           " WHERE merchant_instances.merchant_id=$1"
-           "   AND product_serial < $2"
-           " ORDER BY product_serial DESC"
-           " LIMIT $3");
+           " WHERE merchant_instances.merchant_id=$1");
   qs = GNUNET_PQ_eval_prepared_multi_select (
     pg->conn,
-    (limit > 0)
-    ? "lookup_products_asc"
-    : "lookup_products_desc",
+    "lookup_all_products",
     params,
     &lookup_products_cb,
     &plc);
diff --git a/src/backenddb/pg_lookup_products.h 
b/src/backenddb/pg_lookup_all_products.h
similarity index 71%
copy from src/backenddb/pg_lookup_products.h
copy to src/backenddb/pg_lookup_all_products.h
index d96328c8..390fa60d 100644
--- a/src/backenddb/pg_lookup_products.h
+++ b/src/backenddb/pg_lookup_all_products.h
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2022 Taler Systems SA
+   Copyright (C) 2024 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
@@ -14,12 +14,12 @@
    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 /**
- * @file backenddb/pg_lookup_products.h
- * @brief implementation of the lookup_products function for Postgres
- * @author Iván Ávalos
+ * @file backenddb/pg_lookup_all_products.h
+ * @brief implementation of the lookup_all_products function for Postgres
+ * @author Christian Grothoff
  */
-#ifndef PG_LOOKUP_PRODUCTS_H
-#define PG_LOOKUP_PRODUCTS_H
+#ifndef PG_LOOKUP_ALL_PRODUCTS_H
+#define PG_LOOKUP_ALL_PRODUCTS_H
 
 #include <taler/taler_util.h>
 #include <taler/taler_json_lib.h>
@@ -38,11 +38,9 @@
  * @return database result code
  */
 enum GNUNET_DB_QueryStatus
-TMH_PG_lookup_products (void *cls,
-                        const char *instance_id,
-                        uint64_t offset,
-                        int64_t limit,
-                        TALER_MERCHANTDB_ProductsCallback cb,
-                        void *cb_cls);
+TMH_PG_lookup_all_products (void *cls,
+                            const char *instance_id,
+                            TALER_MERCHANTDB_ProductCallback cb,
+                            void *cb_cls);
 
 #endif
diff --git a/src/backenddb/pg_lookup_product.c 
b/src/backenddb/pg_lookup_product.c
index 65a3c0e5..a078cf8e 100644
--- a/src/backenddb/pg_lookup_product.c
+++ b/src/backenddb/pg_lookup_product.c
@@ -60,7 +60,7 @@ TMH_PG_lookup_product (void *cls,
       GNUNET_PQ_result_spec_string ("unit",
                                     &pd->unit),
       TALER_PQ_result_spec_amount_with_currency ("price",
-                                   &pd->price),
+                                                 &pd->price),
       TALER_PQ_result_spec_json ("taxes",
                                  &pd->taxes),
       GNUNET_PQ_result_spec_uint64 ("total_stock",
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index e5f3f2a1..4a03dbfe 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -63,6 +63,7 @@
 #include "pg_inactivate_account.h"
 #include "pg_activate_account.h"
 #include "pg_lookup_products.h"
+#include "pg_lookup_all_products.h"
 #include "pg_lookup_product.h"
 #include "pg_delete_product.h"
 #include "pg_insert_product.h"
@@ -407,6 +408,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
     = &TMH_PG_update_transfer_status;
   plugin->lookup_products
     = &TMH_PG_lookup_products;
+  plugin->lookup_all_products
+    = &TMH_PG_lookup_all_products;
   plugin->lookup_product
     = &TMH_PG_lookup_product;
   plugin->delete_product
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 057c9eff..537a2485 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -1516,12 +1516,12 @@ struct TALER_MERCHANT_ProductGetResponse
       struct TALER_Amount price;
 
       /**
-       * base64-encoded product image
+       * base64-encoded product image, can be NULL if none is set.
        */
       const char *image;
 
       /**
-       * list of taxes paid by the merchant
+       * list of taxes paid by the merchant, can be NULL if no taxes were 
specified.
        */
       const json_t *taxes;
 
@@ -1544,7 +1544,7 @@ struct TALER_MERCHANT_ProductGetResponse
       uint64_t total_lost;
 
       /**
-       * where the product is in stock
+       * where the product is in stock, can be NULL if no location was given.
        */
       const json_t *location;
 
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 44fdc0ab..12b13e33 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -334,6 +334,22 @@ struct TALER_MERCHANTDB_ProductDetails
 };
 
 
+/**
+ * Typically called by `lookup_all_products`.
+ *
+ * @param cls a `json_t *` JSON array to build
+ * @param product_serial row ID of the product
+ * @param product_id ID of the product
+ * @param pd full product details
+ */
+typedef void
+(*TALER_MERCHANTDB_ProductCallback)(
+  void *cls,
+  uint64_t product_serial,
+  const char *product_id,
+  const struct TALER_MERCHANTDB_ProductDetails *pd);
+
+
 /**
  * Typically called by `lookup_templates`.
  *
@@ -1619,6 +1635,22 @@ struct TALER_MERCHANTDB_Plugin
                      TALER_MERCHANTDB_ProductsCallback cb,
                      void *cb_cls);
 
+
+  /**
+   * Lookup full details of all of the products the given instance has 
configured (expensive).
+   *
+   * @param cls closure
+   * @param instance_id instance to lookup products for
+   * @param cb function to call on all products found
+   * @param cb_cls closure for @a cb
+   * @return database result code
+   */
+  enum GNUNET_DB_QueryStatus
+  (*lookup_all_products)(void *cls,
+                         const char *instance_id,
+                         TALER_MERCHANTDB_ProductCallback cb,
+                         void *cb_cls);
+
   /**
    * Lookup details about a particular product.
    *
diff --git a/src/lib/merchant_api_get_config.c 
b/src/lib/merchant_api_get_config.c
index b4b700bd..cf5147fe 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -34,12 +34,12 @@
  * Which version of the Taler protocol is implemented
  * by this library?  Used to determine compatibility.
  */
-#define MERCHANT_PROTOCOL_CURRENT 14
+#define MERCHANT_PROTOCOL_CURRENT 15
 
 /**
  * How many configs are we backwards-compatible with?
  */
-#define MERCHANT_PROTOCOL_AGE 2
+#define MERCHANT_PROTOCOL_AGE 3
 
 /**
  * How many exchanges do we allow at most per merchant?
diff --git a/src/lib/merchant_api_get_product.c 
b/src/lib/merchant_api_get_product.c
index 3f026bf3..bb10a438 100644
--- 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-2023 Taler Systems SA
+  Copyright (C) 2014-2024 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
@@ -105,12 +105,16 @@ handle_get_product_finished (void *cls,
         TALER_JSON_spec_amount_any (
           "price",
           &pgr.details.ok.price),
-        GNUNET_JSON_spec_string (
-          "image",
-          &pgr.details.ok.image),
-        GNUNET_JSON_spec_array_const (
-          "taxes",
-          &pgr.details.ok.taxes),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string (
+            "image",
+            &pgr.details.ok.image),
+          NULL),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_array_const (
+            "taxes",
+            &pgr.details.ok.taxes),
+          NULL),
         GNUNET_JSON_spec_int64 (
           "total_stock",
           &pgr.details.ok.total_stock),
@@ -120,12 +124,15 @@ handle_get_product_finished (void *cls,
         GNUNET_JSON_spec_uint64 (
           "total_lost",
           &pgr.details.ok.total_lost),
-        GNUNET_JSON_spec_object_const (
-          "address",
-          &pgr.details.ok.location),
         GNUNET_JSON_spec_mark_optional (
-          GNUNET_JSON_spec_timestamp ("next_restock",
-                                      &pgr.details.ok.next_restock),
+          GNUNET_JSON_spec_object_const (
+            "address",
+            &pgr.details.ok.location),
+          NULL),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_timestamp (
+            "next_restock",
+            &pgr.details.ok.next_restock),
           NULL),
         GNUNET_JSON_spec_end ()
       };

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]