gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 02/03: template post, get, patch and delete


From: gnunet
Subject: [taler-merchant] 02/03: template post, get, patch and delete
Date: Tue, 22 Nov 2022 14:14:59 +0100

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

priscilla-huang pushed a commit to branch master
in repository merchant.

commit c00762ce8297fbb4ea9590a0fb7e014adb9d8dcf
Author: priscilla <priscilla.huang@efrei.net>
AuthorDate: Tue Nov 22 08:07:11 2022 -0500

    template post, get, patch and delete
---
 src/backend/taler-merchant-httpd_helper.c          | 44 +++++++++++++++++++++-
 src/backend/taler-merchant-httpd_helper.h          | 12 ++++++
 .../taler-merchant-httpd_private-post-templates.c  |  6 +--
 3 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_helper.c 
b/src/backend/taler-merchant-httpd_helper.c
index 595b82cf..a5de1781 100644
--- a/src/backend/taler-merchant-httpd_helper.c
+++ b/src/backend/taler-merchant-httpd_helper.c
@@ -88,7 +88,6 @@ TMH_payto_uri_array_valid (const json_t *payto_uris)
   return payto_ok;
 }
 
-
 bool
 TMH_location_object_valid (const json_t *location)
 {
@@ -316,6 +315,49 @@ TMH_image_data_url_valid (const char *image_data_url)
   return true;
 }
 
+bool
+TMH_template_contract_valid (const json_t *template_contract)
+{
+  const char *summary;
+  struct TALER_Amount amount = { .value = 0};
+  uint32_t minimum_age = 0;
+  struct GNUNET_TIME_Relative pay_duration= { 0 };
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("summary",
+                               &summary),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_amount ("amount",
+                              TMH_currency,
+                              &amount),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_uint32 ("minimum_age",
+                               &minimum_age),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_relative_time ("pay_duration",
+                                     &pay_duration),
+      NULL),
+    GNUNET_JSON_spec_end ()
+  };
+  const char *ename;
+  unsigned int eline;
+
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (template_contract,
+                         spec,
+                         &ename,
+                         &eline))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Invalid template_contract for field %s\n",
+                ename);
+    return false;
+  }
+  return true;
+}
 
 bool
 TMH_taxes_array_valid (const json_t *taxes)
diff --git a/src/backend/taler-merchant-httpd_helper.h 
b/src/backend/taler-merchant-httpd_helper.h
index 659bddc2..dae9caaf 100644
--- a/src/backend/taler-merchant-httpd_helper.h
+++ b/src/backend/taler-merchant-httpd_helper.h
@@ -87,6 +87,18 @@ bool
 TMH_image_data_url_valid (const char *image_data_url);
 
 
+/**
+ * Check if @a template_contract is a valid template_contract  object in the 
sense of Taler's API
+ * definition.
+ *
+ * @param template_contract object to check
+ * @return true if @a template_location is an object
+ *         representing a template_location.
+ */
+bool
+TMH_template_contract_valid (const json_t *template_contract);
+
+
 /**
  * Setup new wire method for the given @ payto_uri.
  *
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c 
b/src/backend/taler-merchant-httpd_private-post-templates.c
index 1e6206bb..a2112486 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-templates.c
@@ -46,11 +46,11 @@ templates_equal (const struct 
TALER_MERCHANTDB_TemplateDetails *t1,
                 const struct TALER_MERCHANTDB_TemplateDetails *t2)
 {
   return ( (0 == strcmp (t1->template_description,
-                         t2->tempate_description)) &&
+                         t2->template_description)) &&
            (0 == strcmp (t1->image,
                          t2->image)) &&
-           (1 == json_equal (p1->template_contract,
-                             p2->template_contract));
+           (1 == json_equal (t1->template_contract,
+                             t2->template_contract)));
 }
 
 

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