commit 8097a08ab24e9b705a01c520df7b0aca852ef057
parent d0193143677cbc1ca1111be1b3f4177ada5b1f04
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date: Wed, 1 May 2024 14:59:59 +0200
Merge remote-tracking branch 'refs/remotes/origin/master'
Diffstat:
4 files changed, 43 insertions(+), 114 deletions(-)
diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c
@@ -152,6 +152,7 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc,
if (NULL == (dk = DH_keys_donation_unit_by_hash (
&irc.donation_receipts[i].h_donation_unit_pub)))
{
+ GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_DONAU_GENERIC_KEYS_MISSING,
@@ -197,15 +198,8 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc,
"donation_receipts");
}
- // FIXME
- // Fetch donation receipts and join with donation units to get amount
- // then create donation statement
-
- // FIXME
- // Send back DS
-
- return MHD_HTTP_OK;
+ return MHD_HTTP_CREATED;
}
-/* end of donau-httpd_post-submit-receipts.c */
-\ No newline at end of file
+/* end of donau-httpd_post-submit-receipts.c */
diff --git a/src/donaudb/pg_iterate_submitted_receipts.c b/src/donaudb/pg_iterate_submitted_receipts.c
@@ -27,79 +27,13 @@
#include "donaudb_plugin.h"
#include "donau_pq_lib.h"
-/**
- * Closure for #get_submitted_receipts_cb().
- */
-struct IterateSubmittedReceiptsContext
-{
- /**
- * Function to call per result.
- */
- DONAUDB_IterateSubmittedReceiptsCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
-};
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-iterate_submitted_receipts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct IterateSubmittedReceiptsContext *ctx = cls;
- struct PostgresClosure *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_Amount value;
- enum GNUNET_GenericReturnValue iret;
-
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("value",
- &value),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
-
- iret = ctx->cb (ctx->cb_cls,
- &value);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != iret)
- break;
- }
-}
-
enum GNUNET_DB_QueryStatus
DH_PG_iterate_submitted_receipts (
void *cls,
const uint64_t donation_year,
const struct DONAU_HashDonorTaxId *h_donor_tax_id,
- DONAUDB_IterateSubmittedReceiptsCallback cb,
- void *cb_cls)
+ struct TALER_Amount *total_donations)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -107,23 +41,37 @@ DH_PG_iterate_submitted_receipts (
GNUNET_PQ_query_param_auto_from_type (&h_donor_tax_id),
GNUNET_PQ_query_param_end
};
- struct IterateSubmittedReceiptsContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
+ uint64_t value;
+ uint64_t fraction;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("value",
+ &value),
+ GNUNET_PQ_result_spec_uint64 ("fraction",
+ &fraction),
+ GNUNET_PQ_result_spec_end
};
+ enum GNUNET_DB_QueryStatus qs;
PREPARE (pg,
"lookup_submitted_receipts",
"SELECT "
- " value"
+ " CAST(SUM((ref.amount_with_fee).val) AS INT8) AS value"
+ ",CAST(SUM(CAST((value.amount_with_fee).frac AS INT8)) AS INT8) AS fraction"
" FROM receipts_submitted"
" JOIN donation_units USING (donation_unit_pub)"
" WHERE donation_year=$1"
" AND h_tax_number=$2");
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "iterate_submitted_receipts",
- params,
- &iterate_submitted_receipts_cb,
- &ctx);
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "iterate_submitted_receipts",
+ params,
+ rs);
+ if (qs < 0)
+ return qs;
+ value += fraction / TALER_AMOUNT_FRAC_BASE;
+ fraction %= TALER_AMOUNT_FRAC_BASE;
+ TALER_amount_set_zero (pg->currency,
+ total_donations);
+ total_donations->value = value;
+ total_donations->fraction = fraction;
+ return qs;
}
diff --git a/src/donaudb/pg_iterate_submitted_receipts.h b/src/donaudb/pg_iterate_submitted_receipts.h
@@ -38,7 +38,6 @@ DH_PG_iterate_submitted_receipts (
void *cls,
const uint64_t donation_year,
const struct DONAU_HashDonorTaxId *h_donor_tax_id,
- DONAUDB_IterateSubmittedReceiptsCallback cb,
- void *cb_cls);
+ struct TALER_Amount *total_donations);
#endif
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
@@ -150,16 +150,6 @@ typedef void
struct DONAUDB_SignkeyMetaData *meta);
/**
- * Return value of submitted donation receipts.
- *
- * @param cls closure
- */
-typedef enum GNUNET_GenericReturnValue
-(*DONAUDB_IterateSubmittedReceiptsCallback)(
- void *cls,
- struct TALER_Amount *value);
-
-/**
* Return donation units.
*
* @param cls closure
@@ -544,28 +534,27 @@ struct DONAUDB_Plugin
uint64_t donation_year);
/**
- * Iterate submitted donation receipt.
- *
- * @param cls closure
- * @param value
- * @return database transaction status
- */
+ * Iterate submitted donation receipt.
+ *
+ * @param cls closure
+ * @param value
+ * @return database transaction status
+ */
enum GNUNET_DB_QueryStatus
(*iterate_submitted_receipts)(
void *cls,
const uint64_t donation_year,
const struct DONAU_HashDonorTaxId *h_donor_tax_id,
- DONAUDB_IterateSubmittedReceiptsCallback cb,
- void *cb_cls);
+ struct TALER_Amount *total_donations);
/**
- * Lookup issued receipts from the charity.
- *
- * @param cls closure
- * @param h_receipts the hash over the blinded unique identifiers
- * @param meta meta data about an issued request
- * @return transaction status code
- */
+ * Lookup issued receipts from the charity.
+ *
+ * @param cls closure
+ * @param h_receipts the hash over the blinded unique identifiers
+ * @param meta meta data about an issued request
+ * @return transaction status code
+ */
enum GNUNET_DB_QueryStatus
(*lookup_issued_receipts)(
void *cls,