aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-05-13 13:27:40 +0200
committerChristian Grothoff <christian@grothoff.org>2024-05-13 13:27:40 +0200
commit0e0751a19096f2ab08e519c9d8735f14c658bbfb (patch)
tree08a85eaa2e7129e39e2ca58e98ee7d6abf4a76c5 /src/backend
parenta97ee62dab172a39eab1bebdcd0d8512f5ce4dac (diff)
implement protocol spec v15
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile.am2
-rw-r--r--src/backend/taler-merchant-httpd.c7
-rw-r--r--src/backend/taler-merchant-httpd_config.c2
-rw-r--r--src/backend/taler-merchant-httpd_private-get-pos.c145
-rw-r--r--src/backend/taler-merchant-httpd_private-get-pos.h41
-rw-r--r--src/backend/taler-merchant-httpd_private-get-products-ID.c22
6 files changed, 209 insertions, 10 deletions
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..1f6f1262
--- /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: 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_private-get-pos.h b/src/backend/taler-merchant-httpd_private-get-pos.h
new file mode 100644
index 00000000..ce266823
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-get-pos.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ (C) 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.h
+ * @brief implement GET /pos
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_GET_POS_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_GET_POS_H
+
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Handle a GET "/pos" request.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] hc context with further information about the request
+ * @return MHD result code
+ */
+MHD_RESULT
+TMH_private_get_pos (const struct TMH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ struct TMH_HandlerContext *hc);
+
+/* 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))),