commit bfb45fd3f165cfd3cde6b9d1e1103f29179e493f
parent d5e3574e32ac64555512f60dab2277ed5aa16ba7
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date: Thu, 11 Jan 2024 00:08:15 +0100
Merge remote-tracking branch 'refs/remotes/origin/master'
Diffstat:
4 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c
@@ -52,7 +52,7 @@
* Above what request latency do we start to log?
*/
#define WARN_LATENCY GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MILLISECONDS, 500)
+ GNUNET_TIME_UNIT_MILLISECONDS, 500)
/**
* Are clients allowed to request /keys for times other than the
@@ -451,6 +451,12 @@ handle_mhd_request (void *cls,
.method = MHD_HTTP_METHOD_GET,
.handler.get = &DH_handler_charities_get
},
+ /* POST charities */
+ {
+ .url = "charities",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &DH_handler_charity_post
+ },
/**
etc
diff --git a/src/donau/donau-httpd_charity.h b/src/donau/donau-httpd_charity.h
@@ -33,9 +33,10 @@
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_charity_post (
- struct MHD_Connection *connection,
- const json_t *root);
+DH_handler_charity_post (
+ struct DH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[]);
/**
diff --git a/src/donau/donau-httpd_post-charity.c b/src/donau/donau-httpd_post-charity.c
@@ -38,15 +38,12 @@
*/
struct InsertCharityContext
{
- /**
- * Charity name
- */
+ const struct DONAU_CharityPublicKeyP *charity_pub;
const char *charity_name;
-
- /**
- * Charity URL
- */
const char *charity_url;
+ struct TALER_Amount *max_per_year;
+ struct TALER_Amount *receipts_to_date;
+ uint64_t current_year;
};
@@ -75,8 +72,12 @@ insert_charity (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = DH_plugin->insert_charity (DH_plugin->cls,
+ icc->charity_pub,
icc->charity_name,
- icc->charity_url);
+ icc->charity_url,
+ icc->max_per_year,
+ icc->receipts_to_date,
+ icc->current_year);
if (qs <= 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
@@ -96,24 +97,34 @@ insert_charity (void *cls,
MHD_RESULT
-DH_handler_charity_post (
- struct MHD_Connection *connection,
- const json_t *root)
+DH_handler_charity_post (struct DH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[])
{
struct InsertCharityContext icc;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("charity_url",
- &icc.charity_url),
+ GNUNET_JSON_spec_fixed_auto ("charity_pub",
+ &icc.charity_pub),
GNUNET_JSON_spec_string ("charity_name",
&icc.charity_name),
+ GNUNET_JSON_spec_string ("charity_url",
+ &icc.charity_url),
+ TALER_JSON_spec_amount ("max_per_year",
+ DH_currency,
+ icc.max_per_year),
+ TALER_JSON_spec_amount ("receipts_to_date",
+ DH_currency,
+ icc.receipts_to_date),
+ GNUNET_JSON_spec_uint64 ("current_year",
+ &icc.current_year),
GNUNET_JSON_spec_end ()
};
{
enum GNUNET_GenericReturnValue res;
- res = TALER_MHD_parse_json_data (connection,
+ res = TALER_MHD_parse_json_data (rc->connection,
root,
spec);
if (GNUNET_SYSERR == res)
@@ -129,7 +140,7 @@ DH_handler_charity_post (
MHD_RESULT mhd_ret;
if (GNUNET_OK !=
- DH_DB_run_transaction (connection,
+ DH_DB_run_transaction (rc->connection,
"insert_charity",
DH_MT_REQUEST_OTHER,
&mhd_ret,
@@ -140,7 +151,7 @@ DH_handler_charity_post (
}
}
return TALER_MHD_reply_static (
- connection,
+ rc->connection,
MHD_HTTP_NO_CONTENT,
NULL,
NULL,
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
@@ -379,8 +379,12 @@ struct DONAUDB_Plugin
enum GNUNET_DB_QueryStatus
(*insert_charity)(
void *cls,
+ const struct DONAU_CharityPublicKeyP *charity_pub,
const char *charity_name,
- const char *charity_url);
+ const char *charity_url,
+ struct TALER_Amount *max_per_year,
+ struct TALER_Amount *receipts_to_date,
+ uint64_t current_year);
};