gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: added charity post


From: gnunet
Subject: [taler-donau] branch master updated: added charity post
Date: Sat, 06 Jan 2024 14:21:34 +0100

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

johannes-casaburi pushed a commit to branch master
in repository donau.

The following commit(s) were added to refs/heads/master by this push:
     new 4bf0721  added charity post
4bf0721 is described below

commit 4bf0721ec4dca5ae6bbb0ed8789feb7dc7b4f112
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
AuthorDate: Sat Jan 6 14:20:50 2024 +0100

    added charity post
---
 src/donau/donau-httpd_charity.h      |  54 +++++++++++++
 src/donau/donau-httpd_get-charity.c  |   2 +-
 src/donau/donau-httpd_post-charity.c | 148 +++++++++++++++++++++++++++++++++++
 src/donaudb/0002-donau_charities.sql |   3 +-
 src/donaudb/pg_insert_charity.c      |   5 +-
 5 files changed, 209 insertions(+), 3 deletions(-)

diff --git a/src/donau/donau-httpd_charity.h b/src/donau/donau-httpd_charity.h
new file mode 100644
index 0000000..2e54cf1
--- /dev/null
+++ b/src/donau/donau-httpd_charity.h
@@ -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 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 Affero General Public License for more 
details.
+
+  You should have received a copy of the GNU Affero General Public License 
along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file donau-httpd_charity.h
+ * @brief Handle /charity requests
+ * @author Johannes Casaburi
+ */
+#ifndef TALER_EXCHANGE_HTTPD_AML_DECISION_H
+#define TALER_EXCHANGE_HTTPD_AML_DECISION_H
+
+#include <microhttpd.h>
+#include "donau-httpd.h"
+
+
+/**
+ * Handle a POST "/charity" request.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_charity_post (
+  struct MHD_Connection *connection,
+  const json_t *root);
+
+
+/**
+ * Handle a GET "/charity" request.
+ *
+ * @param rc request context
+ * @param args GET arguments (should be one)
+ * @return MHD result code
+ */
+MHD_RESULT
+DH_handler_charity_get (
+  struct DH_RequestContext *rc,
+  const char *const args[]);
+
+
+#endif
diff --git a/src/donau/donau-httpd_get-charity.c 
b/src/donau/donau-httpd_get-charity.c
index 87f6d38..24f85a1 100644
--- a/src/donau/donau-httpd_get-charity.c
+++ b/src/donau/donau-httpd_get-charity.c
@@ -28,7 +28,7 @@
 #include "taler/taler_signatures.h"
 #include "donau-httpd.h"
 #include "donaudb_plugin.h"
-#include "donau-httpd_aml-decision.h"
+#include "donau-httpd_charity.h"
 #include "donau-httpd_metrics.h"
 
 
diff --git a/src/donau/donau-httpd_post-charity.c 
b/src/donau/donau-httpd_post-charity.c
new file mode 100644
index 0000000..d5e9742
--- /dev/null
+++ b/src/donau/donau-httpd_post-charity.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 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 Affero General Public License for more 
details.
+
+  You should have received a copy of the GNU Affero General Public License 
along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_aml-decision.c
+ * @brief Handle request about an AML decision.
+ * @author Johannes Casaburi
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler/taler-exchange-httpd_responses.h"
+
+
+/**
+ * Closure for #insert_charity()
+ */
+struct DecisionContext
+{
+  /**
+   * Charity name
+   */
+  const char *charity_name;
+
+  /**
+   * Charity URL
+   */
+  const char *charity_url;
+
+};
+
+
+/**
+ * Function implementing AML decision database transaction.
+ *
+ * Runs the transaction logic; IF it returns a non-error code, the
+ * transaction logic MUST NOT queue a MHD response.  IF it returns an hard
+ * error, the transaction logic MUST queue a MHD response and set @a mhd_ret.
+ * IF it returns the soft error code, the function MAY be called again to
+ * retry and MUST not queue a MHD response.
+ *
+ * @param cls closure with a `struct DecisionContext`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ *             if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+insert_charity (void *cls,
+                struct MHD_Connection *connection,
+                MHD_RESULT *mhd_ret)
+{
+  struct DecisionContext *dc = cls;
+  enum GNUNET_DB_QueryStatus qs;
+
+  qs = TEH_plugin->insert_charity (DH_plugin->cls,
+                                   dc->charity_name,
+                                   dc->charity_url);
+  if (qs <= 0)
+  {
+    if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
+    {
+      GNUNET_break (0);
+      *mhd_ret = TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                             TALER_EC_GENERIC_DB_STORE_FAILED,
+                                             "insert_charity");
+      return GNUNET_DB_STATUS_HARD_ERROR;
+    }
+    return qs;
+  }
+
+  return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+MHD_RESULT
+DH_handler_charity_post (
+  struct MHD_Connection *connection,
+  const json_t *root)
+{
+  struct DecisionContext dc;
+
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_array_const ("charity_url",
+                                  &dc.charity_url),
+    GNUNET_JSON_spec_array_const ("charity_name",
+                                  &dc.charity_name),
+    GNUNET_JSON_spec_end ()
+  };
+
+  {
+    enum GNUNET_GenericReturnValue res;
+
+    res = TALER_MHD_parse_json_data (connection,
+                                     root,
+                                     spec);
+    if (GNUNET_SYSERR == res)
+      return MHD_NO; /* hard failure */
+    if (GNUNET_NO == res)
+    {
+      GNUNET_break_op (0);
+      return MHD_YES; /* failure */
+    }
+  }
+
+  {
+    MHD_RESULT mhd_ret;
+
+    if (GNUNET_OK !=
+        DH_DB_run_transaction (connection,
+                               "insert_charity",
+                               TEH_MT_REQUEST_OTHER,
+                               &mhd_ret,
+                               &insert_charity,
+                               &dc))
+    {
+      return mhd_ret;
+    }
+  }
+  return TALER_MHD_reply_static (
+    connection,
+    MHD_HTTP_NO_CONTENT,
+    NULL,
+    NULL,
+    0);
+}
+
+
+/* end of taler-exchange-httpd_aml-decision.c */
diff --git a/src/donaudb/0002-donau_charities.sql 
b/src/donaudb/0002-donau_charities.sql
index ef4dee2..fe11117 100644
--- a/src/donaudb/0002-donau_charities.sql
+++ b/src/donaudb/0002-donau_charities.sql
@@ -16,8 +16,9 @@
 
 CREATE TABLE charities
   (charity_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
-  ,charity_name TEXT NOT NULL
   ,charity_pub BYTEA PRIMARY KEY CHECK (LENGTH(donau_pub)=32)
+  ,charity_name TEXT NOT NULL
+  ,charity_url TEXT NOT NULL
   ,max_per_year taler_amount NOT NULL
   ,receipts_to_date taler_amount NOT NULL DEFAULT (0,0)
   ,current_year INT8 NOT NULL
diff --git a/src/donaudb/pg_insert_charity.c b/src/donaudb/pg_insert_charity.c
index ab968b9..0c2d783 100644
--- a/src/donaudb/pg_insert_charity.c
+++ b/src/donaudb/pg_insert_charity.c
@@ -30,6 +30,7 @@ DH_PG_insert_charity (void *cls,
                       const struct DONAU_CharityPublicKeyP *charity_pub,
                       const char *charity_url,
                       const char *charity_name,
+                      struct TALER_Amount *max_per_year,
                       struct TALER_Amount *receipts_to_date,
                       uint64_t current_year)
 {
@@ -38,6 +39,7 @@ DH_PG_insert_charity (void *cls,
     GNUNET_PQ_query_param_auto_from_type (charity_pub),
     GNUNET_PQ_query_param_string (charity_name),
     GNUNET_PQ_query_param_string (charity_url),
+    TALER_PQ_query_param_amount (max_per_year),
     TALER_PQ_query_param_amount (receipts_to_date),
     GNUNET_PQ_query_param_uint64 (&current_year),
     GNUNET_PQ_query_param_end
@@ -49,10 +51,11 @@ DH_PG_insert_charity (void *cls,
            "(charity_pub"
            ",charity_name"
            ",charity_url"
+           ",max_per_year"
            ",receipts_to_date"
            ",current_year"
            ") VALUES "
-           "($1, $2, $3, $4, $5);");
+           "($1, $2, $3, $4, $5, $6);");
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "insert_charity",
                                              params);

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