aboutsummaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/Makefile.am8
-rw-r--r--src/backenddb/merchant-0006.sql55
-rw-r--r--src/backenddb/pg_delete_category.c54
-rw-r--r--src/backenddb/pg_delete_category.h43
-rw-r--r--src/backenddb/pg_delete_otp.c4
-rw-r--r--src/backenddb/pg_insert_category.c65
-rw-r--r--src/backenddb/pg_insert_category.h46
-rw-r--r--src/backenddb/pg_lookup_categories.c148
-rw-r--r--src/backenddb/pg_lookup_categories.h43
-rw-r--r--src/backenddb/pg_select_category.c37
-rw-r--r--src/backenddb/pg_select_category.h45
-rw-r--r--src/backenddb/pg_update_category.c59
-rw-r--r--src/backenddb/pg_update_category.h47
-rw-r--r--src/backenddb/pg_update_otp.c15
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c15
15 files changed, 667 insertions, 17 deletions
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index 89be9a4f..8d1c582c 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -22,6 +22,7 @@ sql_DATA = \
merchant-0003.sql \
merchant-0004.sql \
merchant-0005.sql \
+ merchant-0006.sql \
drop.sql
BUILT_SOURCES = \
@@ -62,7 +63,7 @@ libtalermerchantdb_la_LIBADD = \
libtalermerchantdb_la_LDFLAGS = \
$(POSTGRESQL_LDFLAGS) \
- -version-info 3:0:1 \
+ -version-info 3:1:1 \
-no-undefined
libtaler_plugin_merchantdb_postgres_la_SOURCES = \
@@ -76,6 +77,11 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
pg_insert_transfer_details.h pg_insert_transfer_details.c \
pg_store_wire_fee_by_exchange.h pg_store_wire_fee_by_exchange.c \
pg_select_open_transfers.h pg_select_open_transfers.c \
+ pg_lookup_categories.h pg_lookup_categories.c \
+ pg_select_category.h pg_select_category.c \
+ pg_update_category.h pg_update_category.c \
+ pg_insert_category.h pg_insert_category.c \
+ pg_delete_category.h pg_delete_category.c \
pg_lookup_instances.h pg_lookup_instances.c \
pg_lookup_transfers.h pg_lookup_transfers.c \
pg_update_transfer_status.h pg_update_transfer_status.c \
diff --git a/src/backenddb/merchant-0006.sql b/src/backenddb/merchant-0006.sql
new file mode 100644
index 00000000..d68927c0
--- /dev/null
+++ b/src/backenddb/merchant-0006.sql
@@ -0,0 +1,55 @@
+--
+-- This file is part of TALER
+-- 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
+-- 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/>
+--
+
+-- Everything in one big transaction
+BEGIN;
+
+-- Check patch versioning is in place.
+SELECT _v.register_patch('merchant-0006', NULL, NULL);
+
+SET search_path TO merchant;
+
+CREATE TABLE IF NOT EXISTS merchant_categories
+ (category_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
+ ,merchant_serial BIGINT NOT NULL
+ REFERENCES merchant_instances (merchant_serial) ON DELETE CASCADE
+ ,category_name TEXT NOT NULL UNIQUE
+ ,category_name_i18n BYTEA NOT NULL
+ );
+
+COMMENT ON COLUMN merchant_categories.category_name
+ IS 'name of the category';
+COMMENT ON COLUMN merchant_categories.category_name_i18n
+ IS 'JSON with translations of the category name';
+
+CREATE TABLE merchant_product_categories
+ (category_serial BIGINT NOT NULL
+ REFERENCES merchant_categories (category_serial) ON DELETE CASCADE
+ ,product_serial BIGINT NOT NULL
+ REFERENCES merchant_inventory (product_serial) ON DELETE CASCADE);
+CREATE INDEX merchant_categories_by_category
+ ON merchant_categories (category_serial);
+CREATE INDEX merchant_categories_by_product
+ ON merchant_categories (product_serial);
+
+COMMENT ON COLUMN merchant_product_categories.category_serial
+ IS 'Reference to a category the product is part of';
+COMMENT ON COLUMN merchant_product_categories.product_serial
+ IS 'Reference to a product which is in the given category';
+
+
+-- Complete transaction
+COMMIT;
diff --git a/src/backenddb/pg_delete_category.c b/src/backenddb/pg_delete_category.c
new file mode 100644
index 00000000..4a43aa37
--- /dev/null
+++ b/src/backenddb/pg_delete_category.c
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_delete_category.c
+ * @brief Implementation of the delete_category function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_delete_category.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_delete_category (void *cls,
+ const char *instance_id,
+ uint64_t category_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_uint64 (&category_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+ PREPARE (pg,
+ "delete_category",
+ "DELETE"
+ " FROM merchant_categories"
+ " WHERE merchant_serial="
+ " (SELECT merchant_serial "
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)"
+ " AND category_serial=$2");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "delete_category",
+ params);
+}
diff --git a/src/backenddb/pg_delete_category.h b/src/backenddb/pg_delete_category.h
new file mode 100644
index 00000000..8837a6b8
--- /dev/null
+++ b/src/backenddb/pg_delete_category.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_delete_category.h
+ * @brief implementation of the delete_category function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DELETE_CATEGORY_H
+#define PG_DELETE_CATEGORY_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Delete information about a product category.
+ *
+ * @param cls closure
+ * @param instance_id instance to delete category of
+ * @param category_id identifies the category to delete
+ * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ * if template unknown.
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_delete_category (void *cls,
+ const char *instance_id,
+ uint64_t category_id);
+
+
+#endif
diff --git a/src/backenddb/pg_delete_otp.c b/src/backenddb/pg_delete_otp.c
index 5f011a4b..60f20481 100644
--- a/src/backenddb/pg_delete_otp.c
+++ b/src/backenddb/pg_delete_otp.c
@@ -43,11 +43,11 @@ TMH_PG_delete_otp (void *cls,
"delete_otp",
"DELETE"
" FROM merchant_otp_devices"
- " WHERE merchant_otp_devices.merchant_serial="
+ " WHERE merchant_serial="
" (SELECT merchant_serial "
" FROM merchant_instances"
" WHERE merchant_id=$1)"
- " AND merchant_otp_devices.otp_id=$2");
+ " AND otp_id=$2");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"delete_otp",
params);
diff --git a/src/backenddb/pg_insert_category.c b/src/backenddb/pg_insert_category.c
new file mode 100644
index 00000000..f820b2c6
--- /dev/null
+++ b/src/backenddb/pg_insert_category.c
@@ -0,0 +1,65 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_insert_category.c
+ * @brief Implementation of the insert_category function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_insert_category.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_insert_category (void *cls,
+ const char *instance_id,
+ const char *category_name,
+ const json_t *category_name_i18n,
+ uint64_t *category_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_string (category_name),
+ TALER_PQ_query_param_json (category_name_i18n),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("category_serial",
+ category_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ PREPARE (pg,
+ "insert_category",
+ "INSERT INTO merchant_categories"
+ "(category_name"
+ ",category_name_i18n"
+ ")"
+ " SELECT merchant_serial,"
+ " $2, $3"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1"
+ " RETURNING category_serial");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "insert_category",
+ params,
+ rs);
+}
diff --git a/src/backenddb/pg_insert_category.h b/src/backenddb/pg_insert_category.h
new file mode 100644
index 00000000..8f4bfc99
--- /dev/null
+++ b/src/backenddb/pg_insert_category.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_insert_category.h
+ * @brief implementation of the insert_category function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_CATEGORY_H
+#define PG_INSERT_CATEGORY_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Insert new product category.
+ *
+ * @param cls closure
+ * @param instance_id instance to insert OTP device for
+ * @param category_name name of the category
+ * @param category_name_i18n translations of the category name
+ * @param[out] category_id set to the category id on success
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_insert_category (void *cls,
+ const char *instance_id,
+ const char *category_name,
+ const json_t *category_name_i18n,
+ uint64_t *category_id);
+
+
+#endif
diff --git a/src/backenddb/pg_lookup_categories.c b/src/backenddb/pg_lookup_categories.c
new file mode 100644
index 00000000..9aea5477
--- /dev/null
+++ b/src/backenddb/pg_lookup_categories.c
@@ -0,0 +1,148 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_lookup_categories.c
+ * @brief Implementation of the lookup_categories function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_categories.h"
+#include "pg_helper.h"
+
+
+/**
+ * Context used for TMH_PG_lookup_categories().
+ */
+struct LookupCategoryContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_MERCHANTDB_CategoriesCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Did database result extraction fail?
+ */
+ bool extract_failed;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about otp_device.
+ *
+ * @param[in,out] cls of type `struct LookupCategoryContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_categories_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupCategoryContext *tlc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t category_id;
+ char *category_name;
+ json_t *category_name_i18n;
+ uint64_t product_count;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("category_serial",
+ &category_id),
+ GNUNET_PQ_result_spec_string ("category_name",
+ &category_name),
+ TALER_PQ_result_spec_json ("category_name_i18n",
+ &category_name_i18n),
+ GNUNET_PQ_result_spec_uint64 ("product_count",
+ &product_count),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ tlc->extract_failed = true;
+ return;
+ }
+ tlc->cb (tlc->cb_cls,
+ category_id,
+ category_name,
+ category_name_i18n,
+ product_count);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_categories (void *cls,
+ const char *instance_id,
+ TALER_MERCHANTDB_CategoriesCallback cb,
+ void *cb_cls)
+{
+
+ struct PostgresClosure *pg = cls;
+ struct LookupCategoryContext tlc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ /* Can be overwritten by the lookup_categories_cb */
+ .extract_failed = false,
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ check_connection (pg);
+ PREPARE (pg,
+ "lookup_categories",
+ "SELECT"
+ " mc.category_serial"
+ ",mc.category_name"
+ ",mc.category_name_i18n"
+ ",COALESCE(COUNT(mpc.product_serial),0)"
+ " AS product_count"
+ " FROM merchant_categories mc"
+ " JOIN merchant_product_categories mpc"
+ " JOIN merchant_instances mi"
+ " USING (merchant_serial)"
+ " WHERE mi.merchant_id=$1"
+ " GROUP BY mc.category_serial"
+ " ORDER BY mc.category_serial;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_categories",
+ params,
+ &lookup_categories_cb,
+ &tlc);
+ /* If there was an error inside lookup_categories_cb, return a hard error. */
+ if (tlc.extract_failed)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/backenddb/pg_lookup_categories.h b/src/backenddb/pg_lookup_categories.h
new file mode 100644
index 00000000..500295c0
--- /dev/null
+++ b/src/backenddb/pg_lookup_categories.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_lookup_categories.h
+ * @brief implementation of the lookup_categories function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_CATEGORIES_H
+#define PG_LOOKUP_CATEGORIES_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+/**
+ * Lookup all of the product categories the given instance has configured.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup OTP devices for
+ * @param cb function to call on all categories found
+ * @param cb_cls closure for @a cb
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_categories (void *cls,
+ const char *instance_id,
+ TALER_MERCHANTDB_CategoriesCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/backenddb/pg_select_category.c b/src/backenddb/pg_select_category.c
new file mode 100644
index 00000000..c20d7bb7
--- /dev/null
+++ b/src/backenddb/pg_select_category.c
@@ -0,0 +1,37 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_select_category.c
+ * @brief Implementation of the select_category function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_select_category.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_select_category (void *cls,
+ const char *instance_id,
+ uint64_t category_id,
+ struct TALER_MERCHANTDB_CategoryDetails *cd)
+{
+ GNUNET_break (0); // FIXME
+ return GNUNET_DB_STATUS_HARD_ERROR;
+}
diff --git a/src/backenddb/pg_select_category.h b/src/backenddb/pg_select_category.h
new file mode 100644
index 00000000..9eeb14aa
--- /dev/null
+++ b/src/backenddb/pg_select_category.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_select_category.h
+ * @brief implementation of the select_category function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_CATEGORY_H
+#define PG_SELECT_CATEGORY_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+
+/**
+ * Lookup details about product category.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup template for
+ * @param category_id category to update
+ * @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)
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_select_category (void *cls,
+ const char *instance_id,
+ uint64_t category_id,
+ struct TALER_MERCHANTDB_CategoryDetails *cd);
+
+#endif
diff --git a/src/backenddb/pg_update_category.c b/src/backenddb/pg_update_category.c
new file mode 100644
index 00000000..3b07a266
--- /dev/null
+++ b/src/backenddb/pg_update_category.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_update_category.c
+ * @brief Implementation of the update_category function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_update_category.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_update_category (void *cls,
+ const char *instance_id,
+ uint64_t category_id,
+ const char *category_name,
+ const json_t *category_name_i18n)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (instance_id),
+ GNUNET_PQ_query_param_uint64 (&category_id),
+ GNUNET_PQ_query_param_string (category_name),
+ TALER_PQ_query_param_json (category_name_i18n),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+ PREPARE (pg,
+ "update_category",
+ "UPDATE merchant_categories SET"
+ " category_name=$3"
+ ",category_name_i18n=$4"
+ " WHERE merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1)"
+ " AND category_serial=$2");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_category",
+ params);
+}
diff --git a/src/backenddb/pg_update_category.h b/src/backenddb/pg_update_category.h
new file mode 100644
index 00000000..616a714a
--- /dev/null
+++ b/src/backenddb/pg_update_category.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ 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
+ 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 backenddb/pg_update_category.h
+ * @brief implementation of the update_category function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_CATEGORY_H
+#define PG_UPDATE_CATEGORY_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+
+/**
+ * Update descriptions of a product category.
+ *
+ * @param cls closure
+ * @param instance_id instance to update OTP device for
+ * @param category_id category to update
+ * @param category_name name of the category
+ * @param category_name_i18n translations of the category name
+ * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
+ * does not yet exist.
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_update_category (void *cls,
+ const char *instance_id,
+ uint64_t category_id,
+ const char *category_name,
+ const json_t *category_name_i18n);
+
+#endif
diff --git a/src/backenddb/pg_update_otp.c b/src/backenddb/pg_update_otp.c
index bdcb9624..218ae74e 100644
--- a/src/backenddb/pg_update_otp.c
+++ b/src/backenddb/pg_update_otp.c
@@ -26,17 +26,6 @@
#include "pg_helper.h"
-/**
- * Update details about a particular OTP device.
- *
- * @param cls closure
- * @param instance_id instance to update OTP device for
- * @param otp_id OTP device to update
- * @param td update to the OTP device details on success, can be NULL
- * (in that case we only want to check if the template exists)
- * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
- * does not yet exist.
- */
enum GNUNET_DB_QueryStatus
TMH_PG_update_otp (void *cls,
const char *instance_id,
@@ -52,7 +41,7 @@ TMH_PG_update_otp (void *cls,
GNUNET_PQ_query_param_uint32 (&pos32),
GNUNET_PQ_query_param_uint64 (&td->otp_ctr),
(NULL == td->otp_key)
- ? GNUNET_PQ_query_param_null()
+ ? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_string (td->otp_key),
GNUNET_PQ_query_param_end
};
@@ -74,5 +63,3 @@ TMH_PG_update_otp (void *cls,
"update_otp",
params);
}
-
-
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 4a03dbfe..ede43100 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -44,6 +44,11 @@
#include "pg_lookup_instances.h"
#include "pg_lookup_transfers.h"
#include "pg_lookup_pending_deposits.h"
+#include "pg_lookup_categories.h"
+#include "pg_select_category.h"
+#include "pg_update_category.h"
+#include "pg_insert_category.h"
+#include "pg_delete_category.h"
#include "pg_update_wirewatch_progress.h"
#include "pg_select_wirewatch_accounts.h"
#include "pg_select_open_transfers.h"
@@ -564,6 +569,16 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
= &TMH_PG_insert_pending_webhook;
plugin->update_pending_webhook
= &TMH_PG_update_pending_webhook;
+ plugin->lookup_categories
+ = &TMH_PG_lookup_categories;
+ plugin->select_category
+ = &TMH_PG_select_category;
+ plugin->update_category
+ = &TMH_PG_update_category;
+ plugin->insert_category
+ = &TMH_PG_insert_category;
+ plugin->delete_category
+ = &TMH_PG_delete_category;
plugin->delete_exchange_accounts
= &TMH_PG_delete_exchange_accounts;
plugin->select_accounts_by_exchange