gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: added get charities


From: gnunet
Subject: [taler-donau] branch master updated: added get charities
Date: Sat, 06 Jan 2024 16:25:14 +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 d094616  added get charities
d094616 is described below

commit d094616fc290711cb1316bb924262c179b840412
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
AuthorDate: Sat Jan 6 16:23:30 2024 +0100

    added get charities
---
 ...d_get-charity.c => donau-httpd_get-charities.c} | 100 ++++++++++-----------
 src/donau/donau-httpd_get-charity.c                |  10 +--
 src/donau/donau-httpd_post-charity.c               |  20 ++---
 src/include/donaudb_plugin.h                       |  81 ++++++++++++++---
 4 files changed, 133 insertions(+), 78 deletions(-)

diff --git a/src/donau/donau-httpd_get-charity.c 
b/src/donau/donau-httpd_get-charities.c
similarity index 54%
copy from src/donau/donau-httpd_get-charity.c
copy to src/donau/donau-httpd_get-charities.c
index 24f85a1..8fd523e 100644
--- a/src/donau/donau-httpd_get-charity.c
+++ b/src/donau/donau-httpd_get-charities.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2023 Taler Systems SA
+  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
@@ -14,8 +14,8 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
- * @file donau-httpd_charity-get.c
- * @brief Return summary information about AML decision
+ * @file donau-httpd_get-charities.c
+ * @brief Return charities
  * @author Johannes Casaburi
  */
 #include "platform.h"
@@ -29,30 +29,42 @@
 #include "donau-httpd.h"
 #include "donaudb_plugin.h"
 #include "donau-httpd_charity.h"
-#include "donau-httpd_metrics.h"
+// #include "taler-exchange-httpd_metrics.h"
 
 
 /**
- * Maximum number of records we return per request.
+ * Maximum number of charities we return per request.
  */
 #define MAX_RECORDS 1024
 
+/**
+ * Return charities information.
+ *
+ * @param cls closure
+ */
+static void
+charities_cb (void *cls)
+{
+  json_t *charities = cls;
+
+  GNUNET_assert (
+    0 ==
+    json_array_append (
+      charities,
+      GNUNET_JSON_PACK (
+        GNUNET_JSON_pack_string ("url",
+                                 charity_url),
+        GNUNET_JSON_pack_string ("name",
+                                 charity_name)
+        )));
+}
+
+
 MHD_RESULT
-DH_handler_charity_get (
-  struct DH_RequestContext *rc,
+DH_handler_charities_get (
+  struct TEH_RequestContext *rc,
   const char *const args[])
 {
-  unsigned long long charity_id;
-
-  if ( (NULL == args[0]) ||
-       (1 != sscanf (args[0], "%llu", &charity_id)))
-  {
-    GNUNET_break_op (0);
-    return TALER_MHD_reply_with_error (rc->connection,
-                                       MHD_HTTP_BAD_REQUEST,
-                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
-                                       "charity_id");
-  }
 
   if (NULL != args[1])
   {
@@ -64,55 +76,41 @@ DH_handler_charity_get (
   }
 
   {
-    char *charity_url;
-    char *charity_name;
+    json_t *charities;
     enum GNUNET_DB_QueryStatus qs;
-    bool none = false;
-    MHD_RESULT result;
 
-    GNUNET_assert (NULL != charity_info);
-    qs = DH_plugin->select_charity_info (DH_plugin->cls,
-                                         charity_id,
-                                         &charity_url,
-                                         &charity_name);
+    charities = json_array ();
+    GNUNET_assert (NULL != charities);
+    qs = DH_plugin->get_charities (DH_plugin->cls,
+                                   &charities_cb,
+                                   charities);
     switch (qs)
     {
     case GNUNET_DB_STATUS_HARD_ERROR:
     case GNUNET_DB_STATUS_SOFT_ERROR:
+      json_decref (charities);
       GNUNET_break (0);
       return TALER_MHD_reply_with_error (rc->connection,
                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
                                          TALER_EC_GENERIC_DB_FETCH_FAILED,
                                          NULL);
     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-      if (none)
-      {
-        return TALER_MHD_reply_static (
-          rc->connection,
-          MHD_HTTP_NO_CONTENT,
-          NULL,
-          NULL,
-          0);
-      }
-      break;
+      return TALER_MHD_reply_static (
+        rc->connection,
+        MHD_HTTP_NO_CONTENT,
+        NULL,
+        NULL,
+        0);
     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
       break;
     }
-
-    result = TALER_MHD_REPLY_JSON_PACK (
-      connection,
-      http_status,
-      TALER_MHD_PACK_EC (ec),
-      GNUNET_JSON_pack_string ("url",
-                               charity_url),
-      GNUNET_JSON_pack_string ("name",
-                               charity_name));
-
-    GNUNET_free (charity_url);
-    GNUNET_free (charity_name);
-    return result;
+    return TALER_MHD_REPLY_JSON_PACK (
+      rc->connection,
+      MHD_HTTP_OK,
+      GNUNET_JSON_pack_array_steal ("charities",
+                                    charities));
   }
 }
 
 
-/* end of donau-httpd_aml-decision_get.c */
+/* end of donau-httpd_get-charities.c */
diff --git a/src/donau/donau-httpd_get-charity.c 
b/src/donau/donau-httpd_get-charity.c
index 24f85a1..24798e8 100644
--- a/src/donau/donau-httpd_get-charity.c
+++ b/src/donau/donau-httpd_get-charity.c
@@ -29,7 +29,7 @@
 #include "donau-httpd.h"
 #include "donaudb_plugin.h"
 #include "donau-httpd_charity.h"
-#include "donau-httpd_metrics.h"
+// #include "donau-httpd_metrics.h"
 
 
 /**
@@ -71,10 +71,10 @@ DH_handler_charity_get (
     MHD_RESULT result;
 
     GNUNET_assert (NULL != charity_info);
-    qs = DH_plugin->select_charity_info (DH_plugin->cls,
-                                         charity_id,
-                                         &charity_url,
-                                         &charity_name);
+    qs = DH_plugin->get_charity (DH_plugin->cls,
+                                 charity_id,
+                                 &charity_url,
+                                 &charity_name);
     switch (qs)
     {
     case GNUNET_DB_STATUS_HARD_ERROR:
diff --git a/src/donau/donau-httpd_post-charity.c 
b/src/donau/donau-httpd_post-charity.c
index c97f81e..99008a4 100644
--- a/src/donau/donau-httpd_post-charity.c
+++ b/src/donau/donau-httpd_post-charity.c
@@ -14,8 +14,8 @@
   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.
+ * @file donau-httpd_post-charity.c
+ * @brief Handle request to insert a charity.
  * @author Johannes Casaburi
  */
 #include "platform.h"
@@ -24,9 +24,9 @@
 #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_json_lib.h"
+#include "taler/taler_mhd_lib.h"
+#include "taler/taler_signatures.h"
 #include "taler/taler-exchange-httpd_responses.h"
 
 
@@ -49,7 +49,7 @@ struct InsertCharityContext
 
 
 /**
- * Function implementing AML decision database transaction.
+ * Function implementing insert charity 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
@@ -71,9 +71,9 @@ insert_charity (void *cls,
   struct InsertCharityContext *icc = cls;
   enum GNUNET_DB_QueryStatus qs;
 
-  qs = TEH_plugin->insert_charity (DH_plugin->cls,
-                                   icc->charity_name,
-                                   icc->charity_url);
+  qs = DH_plugin->insert_charity (DH_plugin->cls,
+                                  icc->charity_name,
+                                  icc->charity_url);
   if (qs <= 0)
   {
     if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
@@ -145,4 +145,4 @@ DH_handler_charity_post (
 }
 
 
-/* end of taler-exchange-httpd_aml-decision.c */
+/* end of donau-httpd_post-charity.c */
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
index c06d6a5..37c48c6 100644
--- a/src/include/donaudb_plugin.h
+++ b/src/include/donaudb_plugin.h
@@ -123,6 +123,19 @@ typedef void
   const struct DONAUDB_SignkeyMetaData *meta);
 
 
+/**
+ * Return charities.
+ *
+ * @param cls closure
+ * @param charity_url
+ * @param charity_name
+ */
+typedef void
+(*DONAUDB_GetCharitiesCallback)(
+  void *cls,
+  const char *charity_name,
+  const char *charity_url);
+
 /**
  * @brief The plugin API, returned from the plugin's "init" function.
  * The argument given to "init" is simply a configuration handle.
@@ -149,7 +162,7 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
    */
   enum GNUNET_GenericReturnValue
-  (*drop_tables)(void *cls);
+    (*drop_tables)(void *cls);
 
   /**
    * Create the necessary tables if they are not present
@@ -162,9 +175,9 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
    */
   enum GNUNET_GenericReturnValue
-  (*create_tables)(void *cls,
-                   bool support_partitions,
-                   uint32_t num_partitions);
+    (*create_tables)(void *cls,
+                     bool support_partitions,
+                     uint32_t num_partitions);
 
 
   /**
@@ -176,8 +189,8 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK on success
    */
   enum GNUNET_GenericReturnValue
-  (*start)(void *cls,
-           const char *name);
+    (*start)(void *cls,
+             const char *name);
 
 
   /**
@@ -189,8 +202,8 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK on success
    */
   enum GNUNET_GenericReturnValue
-  (*start_read_committed)(void *cls,
-                          const char *name);
+    (*start_read_committed)(void *cls,
+                            const char *name);
 
   /**
    * Start a READ ONLY serializable transaction.
@@ -201,8 +214,8 @@ struct DONAUDB_Plugin
    * @return #GNUNET_OK on success
    */
   enum GNUNET_GenericReturnValue
-  (*start_read_only)(void *cls,
-                     const char *name);
+    (*start_read_only)(void *cls,
+                       const char *name);
 
 
   /**
@@ -212,7 +225,7 @@ struct DONAUDB_Plugin
    * @return transaction status
    */
   enum GNUNET_DB_QueryStatus
-  (*commit)(void *cls);
+    (*commit)(void *cls);
 
 
   /**
@@ -226,7 +239,7 @@ struct DONAUDB_Plugin
    *         #GNUNET_SYSERR on hard errors
    */
   enum GNUNET_GenericReturnValue
-  (*preflight)(void *cls);
+    (*preflight)(void *cls);
 
 
   /**
@@ -281,6 +294,50 @@ struct DONAUDB_Plugin
                   const void *extra,
                   size_t extra_size);
 
+  /**
+   * Get charity.
+   *
+   * @param cls closure
+   * @param charity_id
+   * @param charity_url
+   * @param charity_name
+   * @return database transaction status
+   */
+  enum GNUNET_DB_QueryStatus
+    (*get_charity)(
+    void *cls,
+    unsigned long long charity_id,
+    const char *charity_url,
+    const char *charity_name);
+
+/**
+   * Get charities.
+   *
+   * @param cls closure
+   * @param cb callback to invoke on each match
+   * @param cb_cls closure for @a cb
+   * @return database transaction status
+   */
+  enum GNUNET_DB_QueryStatus
+    (*get_charities)(
+    void *cls,
+    DONAUDB_GetCharitiesCallback cb,
+    void *cb_cls);
+
+  /**
+   * Insert Charity
+   *
+   * @param cls closure
+   * @param charity_name
+   * @param charity_url
+   * @return database transaction status
+   */
+  enum GNUNET_DB_QueryStatus
+    (*insert_charity)(
+    void *cls,
+    const char *charity_name,
+    const char *charity_url);
+
 };
 
 

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