[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 14/277: implement PATCH
From: |
gnunet |
Subject: |
[taler-merchant] 14/277: implement PATCH |
Date: |
Sun, 05 Jul 2020 20:48:47 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit 212298abf8ced772d55598bf9a869bd6d63aea3e
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Apr 19 14:01:01 2020 +0200
implement PATCH
---
src/backend/Makefile.am | 2 +
src/backend/taler-merchant-httpd.c | 7 +-
src/backend/taler-merchant-httpd.h | 5 ++
.../taler-merchant-httpd_private-post-instances.c | 16 ++++-
src/backenddb/plugin_merchantdb_postgres.c | 81 +++++++++++++++++++++-
src/include/taler_merchantdb_plugin.h | 23 +++++-
6 files changed, 129 insertions(+), 5 deletions(-)
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index fb17879..916fc0f 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -29,6 +29,8 @@ taler_merchant_httpd_SOURCES = \
taler-merchant-httpd_private-get-instances.h \
taler-merchant-httpd_private-get-instances-ID.c \
taler-merchant-httpd_private-get-instances-ID.h \
+ taler-merchant-httpd_private-patch-instances-ID.c \
+ taler-merchant-httpd_private-patch-instances-ID.h \
taler-merchant-httpd_private-post-instances.c \
taler-merchant-httpd_private-post-instances.h
diff --git a/src/backend/taler-merchant-httpd.c
b/src/backend/taler-merchant-httpd.c
index fead294..02150da 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -31,6 +31,7 @@
#include "taler-merchant-httpd_private-delete-instances-ID.h"
#include "taler-merchant-httpd_private-get-instances.h"
#include "taler-merchant-httpd_private-get-instances-ID.h"
+#include "taler-merchant-httpd_private-patch-instances-ID.h"
#include "taler-merchant-httpd_private-post-instances.h"
/**
@@ -707,6 +708,7 @@ url_handler (void *cls,
void **con_cls)
{
static struct TMH_RequestHandler private_handlers[] = {
+ /* GET /: */
{
.url_prefix = "/",
.method = MHD_HTTP_METHOD_GET,
@@ -718,12 +720,14 @@ url_handler (void *cls,
.handler = &TMH_MHD_handler_static_response,
.response_code = MHD_HTTP_OK
},
+ /* GET /agpl: */
{
.url_prefix = "/agpl",
.method = MHD_HTTP_METHOD_GET,
.skip_instance = true,
.handler = &TMH_MHD_handler_agpl_redirect
},
+ /* GET /instances: */
{
.url_prefix = "/instances",
.method = MHD_HTTP_METHOD_GET,
@@ -742,14 +746,13 @@ url_handler (void *cls,
.method = MHD_HTTP_METHOD_DELETE,
.handler = &TMH_private_delete_instances_ID
},
-#if 0
/* PATCH /instances/$ID/: */
{
.url_prefix = "/",
.method = MHD_HTTP_METHOD_PATCH,
.handler = &TMH_private_patch_instances_ID
},
-#endif
+ /* POST /instances: */
{
.url_prefix = "/instances",
.method = MHD_HTTP_METHOD_POST,
diff --git a/src/backend/taler-merchant-httpd.h
b/src/backend/taler-merchant-httpd.h
index 00d8df7..4d4aa7d 100644
--- a/src/backend/taler-merchant-httpd.h
+++ b/src/backend/taler-merchant-httpd.h
@@ -70,6 +70,11 @@ struct TMH_WireMethod
*/
bool active;
+ /**
+ * Are we currently in a transaction to delete this account?
+ */
+ bool deleting;
+
};
diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c
b/src/backend/taler-merchant-httpd_private-post-instances.c
index 6bbd882..1846609 100644
--- a/src/backend/taler-merchant-httpd_private-post-instances.c
+++ b/src/backend/taler-merchant-httpd_private-post-instances.c
@@ -363,6 +363,7 @@ TMH_private_post_instances (const struct TMH_RequestHandler
*rh,
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
TMH_db->rollback (TMH_db->cls);
+ // TODO: only on soft error do:
continue;
}
for (struct TMH_WireMethod *wm = wm_head;
@@ -370,7 +371,19 @@ TMH_private_post_instances (const struct
TMH_RequestHandler *rh,
wm = wm->next)
{
struct TALER_MERCHANTDB_AccountDetails ad;
-
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("payto_uri",
+ &ad.payto_uri),
+ GNUNET_JSON_spec_fixed_auto ("salt",
+ &ad.salt)
+ };
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_MHD_parse_json_data (NULL,
+ wm->j_wire,
+ spec));
+ ad.h_wire = wm->h_wire;
+ ad.active = wm->active;
qs = TMH_db->insert_account (TMH_db->cls,
mi->settings.id,
&ad);
@@ -380,6 +393,7 @@ TMH_private_post_instances (const struct TMH_RequestHandler
*rh,
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
TMH_db->rollback (TMH_db->cls);
+ // TODO: only on soft error do:
continue;
}
qs = TMH_db->commit (TMH_db->cls);
diff --git a/src/backenddb/plugin_merchantdb_postgres.c
b/src/backenddb/plugin_merchantdb_postgres.c
index 6b86a1e..70a98d5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -605,7 +605,6 @@ postgres_insert_account (
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_account",
params);
-
}
@@ -659,6 +658,63 @@ postgres_purge_instance (void *cls,
}
+/**
+ * Update information about an instance into our database.
+ *
+ * @param cls closure
+ * @param is details about the instance
+ * @return database result code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_patch_instance (void *cls,
+ const struct TALER_MERCHANTDB_InstanceSettings *is)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (is->id),
+ GNUNET_PQ_query_param_string (is->name),
+ TALER_PQ_query_param_json (is->address),
+ TALER_PQ_query_param_json (is->jurisdiction),
+ TALER_PQ_query_param_amount (&is->default_max_deposit_fee),
+ TALER_PQ_query_param_amount (&is->default_max_wire_fee),
+ GNUNET_PQ_query_param_uint32 (&is->default_wire_fee_amortization),
+ GNUNET_PQ_query_param_relative_time (
+ &is->default_wire_transfer_delay),
+ GNUNET_PQ_query_param_relative_time (&is->default_pay_delay),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_instance",
+ params);
+}
+
+
+/**
+ * Set an instance's account in our database to "inactive".
+ *
+ * @param cls closure
+ * @param h_wire hash of the wire account to set to inactive
+ * @return database result code
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_inactivate_account (void *cls,
+ const struct GNUNET_HashCode *h_wire)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_end
+ };
+
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "inactivate_account",
+ params);
+}
+
+
/* ********************* OLD API ************************** */
/**
@@ -3621,6 +3677,27 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
"DELETE FROM merchant_instances"
" WHERE merchant_instances.merchant_id = $1",
1),
+ /* for postgres_patch_instance() */
+ GNUNET_PQ_make_prepare ("update_instance",
+ "UPDATE merchant_instances SET"
+ " merchant_name=$2"
+ ",address=$3"
+ ",jurisdiction=$4"
+ ",default_max_deposit_fee_val=$5"
+ ",default_max_deposit_fee_frac=$6"
+ ",default_max_wire_fee_val=$7"
+ ",default_max_wire_fee_frac=$8"
+ ",default_wire_fee_amortization=$9"
+ ",default_wire_transfer_delay=$10"
+ ",default_pay_delay=$11"
+ " WHERE merchant_id = $1",
+ 11),
+ /* for postgres_inactivate_account() */
+ GNUNET_PQ_make_prepare ("inactivate_account",
+ "UPDATE merchant_accounts SET"
+ " active=FALSE"
+ " WHERE h_wire = $1",
+ 1),
/* OLD API: */
#if 0
GNUNET_PQ_make_prepare ("insert_deposit",
@@ -4122,6 +4199,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
plugin->insert_account = &postgres_insert_account;
plugin->delete_instance_private_key = &postgres_delete_instance_private_key;
plugin->purge_instance = &postgres_purge_instance;
+ plugin->patch_instance = &postgres_patch_instance;
+ plugin->inactivate_account = &postgres_inactivate_account;
/* old API: */
plugin->store_deposit = &postgres_store_deposit;
diff --git a/src/include/taler_merchantdb_plugin.h
b/src/include/taler_merchantdb_plugin.h
index c2357de..4723ca4 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -383,7 +383,6 @@ struct TALER_MERCHANTDB_Plugin
const char *id,
const struct TALER_MERCHANTDB_AccountDetails *account_details);
-
/**
* Delete private key of an instance from our database.
*
@@ -409,6 +408,28 @@ struct TALER_MERCHANTDB_Plugin
(*purge_instance)(void *cls,
const char *merchant_id);
+ /**
+ * Update information about an instance into our database.
+ *
+ * @param cls closure
+ * @param is details about the instance
+ * @return database result code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*patch_instance)(void *cls,
+ const struct TALER_MERCHANTDB_InstanceSettings *is);
+
+ /**
+ * Set an instance's account in our database to "inactive".
+ *
+ * @param cls closure
+ * @param h_wire hash of the wire account to set to inactive
+ * @return database result code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*inactivate_account)(void *cls,
+ const struct GNUNET_HashCode *h_wire);
+
/* ****************** OLD API ******************** */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-merchant] 02/277: rework merchant schema, (continued)
- [taler-merchant] 02/277: rework merchant schema, gnunet, 2020/07/05
- [taler-merchant] 04/277: starting v1 protocol dispatching logic, gnunet, 2020/07/05
- [taler-merchant] 06/277: complete bootstrap logic in new design, gnunet, 2020/07/05
- [taler-merchant] 05/277: sketch instance loading, gnunet, 2020/07/05
- [taler-merchant] 07/277: implement GET /instances, gnunet, 2020/07/05
- [taler-merchant] 09/277: implement instances_get in library, gnunet, 2020/07/05
- [taler-merchant] 11/277: implement GET /instances/, gnunet, 2020/07/05
- [taler-merchant] 08/277: support PATCH as well, gnunet, 2020/07/05
- [taler-merchant] 12/277: start on DELETE instance, gnunet, 2020/07/05
- [taler-merchant] 10/277: implement POST /instances, gnunet, 2020/07/05
- [taler-merchant] 14/277: implement PATCH,
gnunet <=
- [taler-merchant] 13/277: implement DELETE /instances/$ID, gnunet, 2020/07/05
- [taler-merchant] 18/277: implement POST products/lock, gnunet, 2020/07/05
- [taler-merchant] 15/277: implement GET /products, gnunet, 2020/07/05
- [taler-merchant] 17/277: implement PATCH handlers, gnunet, 2020/07/05
- [taler-merchant] 19/277: backenddb implementation work, gnunet, 2020/07/05
- [taler-merchant] 23/277: specify remaining /instance API, gnunet, 2020/07/05
- [taler-merchant] 26/277: implement GET /products, gnunet, 2020/07/05
- [taler-merchant] 30/277: implement POST /products//lock, gnunet, 2020/07/05
- [taler-merchant] 21/277: simplifying SQL, gnunet, 2020/07/05
- [taler-merchant] 16/277: work on delete/get products by ID, gnunet, 2020/07/05