gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 53/277: implemente DELETE /orders/ID


From: gnunet
Subject: [taler-merchant] 53/277: implemente DELETE /orders/ID
Date: Sun, 05 Jul 2020 20:49:26 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit ff42a36520baabd9d558ce51b2f92d54944e2d00
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Apr 25 22:46:04 2020 +0200

    implemente DELETE /orders/ID
---
 src/backend/Makefile.am                            |   2 +
 src/backend/taler-merchant-httpd.c                 |   1 +
 ...taler-merchant-httpd_private-delete-orders-ID.c |  85 +++++++++++++++
 ...taler-merchant-httpd_private-delete-orders-ID.h |  41 +++++++
 src/backenddb/plugin_merchantdb_postgres.c         | 118 ++++++++++++---------
 src/include/taler_merchantdb_plugin.h              |  16 +--
 6 files changed, 206 insertions(+), 57 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index e367949..bb991a5 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -27,6 +27,8 @@ taler_merchant_httpd_SOURCES = \
     taler-merchant-httpd_private-delete-instances-ID.h \
   taler-merchant-httpd_private-delete-products-ID.c \
     taler-merchant-httpd_private-delete-products-ID.h \
+  taler-merchant-httpd_private-delete-orders-ID.c \
+    taler-merchant-httpd_private-delete-orders-ID.h \
   taler-merchant-httpd_private-get-instances.c \
     taler-merchant-httpd_private-get-instances.h \
   taler-merchant-httpd_private-get-instances-ID.c \
diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 90d7681..d5bb87e 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -30,6 +30,7 @@
 #include "taler-merchant-httpd_mhd.h"
 #include "taler-merchant-httpd_private-delete-instances-ID.h"
 #include "taler-merchant-httpd_private-delete-products-ID.h"
+#include "taler-merchant-httpd_private-delete-orders-ID.h"
 #include "taler-merchant-httpd_private-get-instances.h"
 #include "taler-merchant-httpd_private-get-instances-ID.h"
 #include "taler-merchant-httpd_private-get-products.h"
diff --git a/src/backend/taler-merchant-httpd_private-delete-orders-ID.c 
b/src/backend/taler-merchant-httpd_private-delete-orders-ID.c
new file mode 100644
index 0000000..cddbc07
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-delete-orders-ID.c
@@ -0,0 +1,85 @@
+/*
+  This file is part of TALER
+  (C) 2020 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 backend/taler-merchant-httpd_private-delete-orders-ID.c
+ * @brief implement DELETE /orders/$ID
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler-merchant-httpd_private-delete-orders-ID.h"
+#include <taler/taler_json_lib.h>
+
+
+/**
+ * Handle a DELETE "/orders/$ID" 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_delete_orders_ID (const struct TMH_RequestHandler *rh,
+                              struct MHD_Connection *connection,
+                              struct TMH_HandlerContext *hc)
+{
+  struct TMH_MerchantInstance *mi = hc->instance;
+  enum GNUNET_DB_QueryStatus qs;
+
+  GNUNET_assert (NULL != mi);
+  qs = TMH_db->delete_order (TMH_db->cls,
+                             mi->settings.id,
+                             hc->infix);
+  switch (qs)
+  {
+  case GNUNET_DB_STATUS_HARD_ERROR:
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                       TALER_EC_ORDERS_DELETE_DB_HARD_FAILURE,
+                                       "Transaction failed");
+  case GNUNET_DB_STATUS_SOFT_ERROR:
+    GNUNET_break (0);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                       TALER_EC_INTERNAL_INVARIANT_FAILURE,
+                                       "Serialization error for single SQL 
statement");
+  case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+    qs = TMH_db->lookup_order (TMH_db->cls,
+                               mi->settings.id,
+                               hc->infix,
+                               NULL);
+    if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+      return TALER_MHD_reply_with_error (connection,
+                                         MHD_HTTP_NOT_FOUND,
+                                         TALER_EC_ORDERS_DELETE_NO_SUCH_ORDER,
+                                         "Order unknown");
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_CONFLICT,
+                                       TALER_EC_ORDERS_DELETE_AWAITING_PAYMENT,
+                                       "Order deletion impossible, order is 
locked");
+  case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+    return TALER_MHD_reply_static (connection,
+                                   MHD_HTTP_NO_CONTENT,
+                                   NULL,
+                                   NULL,
+                                   0);
+  }
+  GNUNET_assert (0);
+  return MHD_NO;
+}
+
+
+/* end of taler-merchant-httpd_private-delete-orders-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-delete-orders-ID.h 
b/src/backend/taler-merchant-httpd_private-delete-orders-ID.h
new file mode 100644
index 0000000..e67f5e4
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_private-delete-orders-ID.h
@@ -0,0 +1,41 @@
+/*
+  This file is part of TALER
+  (C) 2019, 2020 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 backend/taler-merchant-httpd_private-delete-orders-ID.h
+ * @brief implement DELETE /orders/$ID/
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT_HTTPD_PRIVATE_DELETE_ORDERS_ID_H
+#define TALER_MERCHANT_HTTPD_PRIVATE_DELETE_ORDERS_ID_H
+
+#include "taler-merchant-httpd.h"
+
+
+/**
+ * Handle a DELETE "/orders/$ID" 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_delete_orders_ID (const struct TMH_RequestHandler *rh,
+                              struct MHD_Connection *connection,
+                              struct TMH_HandlerContext *hc);
+
+/* end of taler-merchant-httpd_private-delete-orders-ID.h */
+#endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index b529117..68e3f66 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1058,6 +1058,62 @@ postgres_delete_order (void *cls,
 }
 
 
+/**
+ * Retrieve order given its @a order_id and the @a instance_id.
+ *
+ * @param cls closure
+ * @param instance_id instance to obtain order of
+ * @param order id order id used to perform the lookup
+ * @param[out] contract_terms where to store the retrieved contract terms,
+ *             NULL to only test if the order exists
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_lookup_order (void *cls,
+                       const char *instance_id,
+                       const char *order_id,
+                       json_t **contract_terms)
+{
+  struct PostgresClosure *pg = cls;
+  json_t *j;
+  enum GNUNET_DB_QueryStatus qs;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_string (instance_id),
+    GNUNET_PQ_query_param_string (order_id),
+    GNUNET_PQ_query_param_end
+  };
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    TALER_PQ_result_spec_json ("contract_terms",
+                               &j),
+    GNUNET_PQ_result_spec_end
+  };
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Finding contract term, order_id: '%s', instance_id: '%s'.\n",
+              order_id,
+              instance_id);
+  check_connection (pg);
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                 "find_order",
+                                                 params,
+                                                 rs);
+  if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+  {
+    if (NULL != contract_terms)
+      *contract_terms = j;
+    else
+      json_decref (j);
+  }
+  else
+  {
+    /* just to be safe: NULL it */
+    if (NULL != contract_terms)
+      *contract_terms = NULL;
+  }
+  return qs;
+}
+
+
 /* ********************* OLD API ************************** */
 
 /**
@@ -1177,46 +1233,6 @@ postgres_find_contract_terms (void *cls,
 }
 
 
-/**
- * Retrieve order given its order id and the instance's merchant public key.
- *
- * @param cls closure
- * @param[out] contract_terms where to store the retrieved contract terms
- * @param order id order id used to perform the lookup
- * @param merchant_pub merchant public key that identifies the instance
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_find_order (void *cls,
-                     json_t **contract_terms,
-                     const char *order_id,
-                     const struct TALER_MerchantPublicKeyP *merchant_pub)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (order_id),
-    GNUNET_PQ_query_param_auto_from_type (merchant_pub),
-    GNUNET_PQ_query_param_end
-  };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    TALER_PQ_result_spec_json ("contract_terms",
-                               contract_terms),
-    GNUNET_PQ_result_spec_end
-  };
-
-  *contract_terms = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Finding contract term, order_id: '%s', merchant_pub: '%s'.\n",
-              order_id,
-              TALER_B2S (merchant_pub));
-  check_connection (pg);
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "find_order",
-                                                   params,
-                                                   rs);
-}
-
-
 /**
  * Insert proposal data and its hashcode into db
  *
@@ -4166,6 +4182,18 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             "   AND merchant_orders.order_id=$2"
                             "   AND pay_deadline < $3",
                             3),
+    /* for postgres_lookup_order() */
+    GNUNET_PQ_make_prepare ("lookup_order",
+                            "SELECT"
+                            " contract_terms"
+                            " FROM merchant_orders"
+                            " WHERE merchant_orders.merchant_serial="
+                            "     (SELECT merchant_serial "
+                            "        FROM merchant_instances"
+                            "        WHERE merchant_id=$1)"
+                            "   AND merchant_orders.order_id=$2",
+                            2),
+
     /* OLD API: */
 #if 0
     GNUNET_PQ_make_prepare ("insert_deposit",
@@ -4317,14 +4345,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             " order_id=$1"
                             " AND merchant_pub=$2",
                             2),
-    GNUNET_PQ_make_prepare ("find_order",
-                            "SELECT"
-                            " contract_terms"
-                            " FROM merchant_orders"
-                            " WHERE"
-                            " order_id=$1"
-                            " AND merchant_pub=$2",
-                            2),
     GNUNET_PQ_make_prepare ("find_session_info",
                             "SELECT"
                             " order_id"
@@ -4676,6 +4696,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
   plugin->update_product = &postgres_update_product;
   plugin->lock_product = &postgres_lock_product;
   plugin->delete_order = &postgres_delete_order;
+  plugin->lookup_order = &postgres_lookup_order;
 
   /* old API: */
   plugin->store_deposit = &postgres_store_deposit;
@@ -4690,7 +4711,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
   plugin->find_proof_by_wtid = &postgres_find_proof_by_wtid;
   plugin->insert_contract_terms = &postgres_insert_contract_terms;
   plugin->insert_order = &postgres_insert_order;
-  plugin->find_order = &postgres_find_order;
   plugin->find_contract_terms = &postgres_find_contract_terms;
   plugin->find_contract_terms_history = &postgres_find_contract_terms_history;
   plugin->find_contract_terms_by_date = &postgres_find_contract_terms_by_date;
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index df88210..c7ffdeb 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -630,20 +630,20 @@ struct TALER_MERCHANTDB_Plugin
 
 
   /**
-   * Retrieve order given its order id and the instance's merchant public key.
+   * Retrieve order given its @a order_id and the @a instance_id.
    *
    * @param cls closure
-   * @param[out] contract_terms where to store the retrieved contract terms
+   * @param instance_id instance to obtain order of
    * @param order id order id used to perform the lookup
-   * @param merchant_pub merchant public key that identifies the instance
+   * @param[out] contract_terms where to store the retrieved contract terms,
+   *             NULL to only test if the order exists
    * @return transaction status
    */
-  // FIXME: rename, change arguments!
   enum GNUNET_DB_QueryStatus
-  (*find_order)(void *cls,
-                json_t **contract_terms,
-                const char *order_id,
-                const struct TALER_MerchantPublicKeyP *merchant_pub);
+  (*lookup_order)(void *cls,
+                  const char *instance_id,
+                  const char *order_id,
+                  json_t **contract_terms);
 
 
   /* ****************** OLD API ******************** */

-- 
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]