summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2023-11-27 07:24:10 +0100
committerChristian Grothoff <grothoff@gnunet.org>2023-12-23 00:08:57 +0800
commit0699871850011f41dedda515cc3438ec54791f89 (patch)
tree9f5439bcf3297c6db0d18bf87cf0a1e209376269 /src/backend
parent094327bc906cdeced19a52c86dc0725aad773997 (diff)
downloadmerchant-0699871850011f41dedda515cc3438ec54791f89.tar.gz
merchant-0699871850011f41dedda515cc3438ec54791f89.tar.bz2
merchant-0699871850011f41dedda515cc3438ec54791f89.zip
list, update, delete token families
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_private-delete-token-families-SLUG.c2
-rw-r--r--src/backend/taler-merchant-httpd_private-get-token-families-SLUG.c4
-rw-r--r--src/backend/taler-merchant-httpd_private-get-token-families.c24
-rw-r--r--src/backend/taler-merchant-httpd_private-patch-token-families-SLUG.c1
-rw-r--r--src/backend/taler-merchant-httpd_private-post-token-families.c17
5 files changed, 33 insertions, 15 deletions
diff --git a/src/backend/taler-merchant-httpd_private-delete-token-families-SLUG.c b/src/backend/taler-merchant-httpd_private-delete-token-families-SLUG.c
index 3418b795..de7b6471 100644
--- a/src/backend/taler-merchant-httpd_private-delete-token-families-SLUG.c
+++ b/src/backend/taler-merchant-httpd_private-delete-token-families-SLUG.c
@@ -20,6 +20,7 @@
*/
#include "platform.h"
#include "taler-merchant-httpd_private-delete-token-families-SLUG.h"
+#include <gnunet/gnunet_db_lib.h>
#include <taler/taler_json_lib.h>
@@ -58,6 +59,7 @@ TMH_private_delete_token_families_SLUG (const struct TMH_RequestHandler *rh,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
"delete_token_family (soft)");
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
return TALER_MHD_reply_static (connection,
MHD_HTTP_NO_CONTENT,
diff --git a/src/backend/taler-merchant-httpd_private-get-token-families-SLUG.c b/src/backend/taler-merchant-httpd_private-get-token-families-SLUG.c
index d31884da..b7c8ab4d 100644
--- a/src/backend/taler-merchant-httpd_private-get-token-families-SLUG.c
+++ b/src/backend/taler-merchant-httpd_private-get-token-families-SLUG.c
@@ -60,7 +60,6 @@ TMH_private_get_tokenfamilies_SLUG (const struct TMH_RequestHandler *rh,
TALER_EC_MERCHANT_GENERIC_PRODUCT_UNKNOWN,
hc->infix);
}
- // TODO: Why is this block here? Limiting variable lifetime?
{
char *kind = NULL;
if (TALER_MERCHANTDB_TFK_Subscription == details.kind)
@@ -92,10 +91,11 @@ TMH_private_get_tokenfamilies_SLUG (const struct TMH_RequestHandler *rh,
GNUNET_JSON_pack_timestamp ("valid_before", details.valid_before),
GNUNET_JSON_pack_time_rel ("duration", details.duration),
GNUNET_JSON_pack_string ("kind", kind)
- );
+ );
GNUNET_free (details.name);
GNUNET_free (details.description);
+ GNUNET_free (kind);
return result;
}
}
diff --git a/src/backend/taler-merchant-httpd_private-get-token-families.c b/src/backend/taler-merchant-httpd_private-get-token-families.c
index 031edd90..003e2966 100644
--- a/src/backend/taler-merchant-httpd_private-get-token-families.c
+++ b/src/backend/taler-merchant-httpd_private-get-token-families.c
@@ -29,26 +29,28 @@
* @param cls a `json_t *` JSON array to build
* @param slug slug of the token family
* @param name name of the token family
- * @param start_time start time of the token family's validity period
- * @param expiration end time of the token family's validity period
+ * @param valid_after start time of the token family's validity period
+ * @param valid_before end time of the token family's validity period
*/
static void
add_token_family (void *cls,
const char *slug,
const char *name,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp expiration)
+ struct GNUNET_TIME_Timestamp valid_after,
+ struct GNUNET_TIME_Timestamp valid_before,
+ const char *kind)
{
json_t *pa = cls;
GNUNET_assert (0 ==
- json_array_append_new (
- pa,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("slug", slug),
- GNUNET_JSON_pack_string ("name", name),
- GNUNET_JSON_pack_timestamp ("start_time", start_time),
- GNUNET_JSON_pack_timestamp ("expiration", expiration))));
+ json_array_append_new (
+ pa,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("slug", slug),
+ GNUNET_JSON_pack_string ("name", name),
+ GNUNET_JSON_pack_timestamp ("valid_after", valid_after),
+ GNUNET_JSON_pack_timestamp ("valid_before", valid_before),
+ GNUNET_JSON_pack_string ("kind", kind))));
}
diff --git a/src/backend/taler-merchant-httpd_private-patch-token-families-SLUG.c b/src/backend/taler-merchant-httpd_private-patch-token-families-SLUG.c
index a5fef59d..8d34b2ff 100644
--- a/src/backend/taler-merchant-httpd_private-patch-token-families-SLUG.c
+++ b/src/backend/taler-merchant-httpd_private-patch-token-families-SLUG.c
@@ -49,7 +49,6 @@ TMH_private_patch_token_family_SLUG (const struct TMH_RequestHandler *rh,
struct TMH_MerchantInstance *mi = hc->instance;
const char *slug = hc->infix;
struct TALER_MERCHANTDB_TokenFamilyDetails details = {0};
- int64_t total_stock;
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("name",
diff --git a/src/backend/taler-merchant-httpd_private-post-token-families.c b/src/backend/taler-merchant-httpd_private-post-token-families.c
index 6ff25942..6bf048f9 100644
--- a/src/backend/taler-merchant-httpd_private-post-token-families.c
+++ b/src/backend/taler-merchant-httpd_private-post-token-families.c
@@ -73,6 +73,7 @@ TMH_private_post_token_families (const struct TMH_RequestHandler *rh,
{
struct TMH_MerchantInstance *mi = hc->instance;
struct TALER_MERCHANTDB_TokenFamilyDetails details = { 0 };
+ const char *kind = NULL;
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("slug",
@@ -85,7 +86,7 @@ TMH_private_post_token_families (const struct TMH_RequestHandler *rh,
GNUNET_JSON_spec_json ("description_i18n",
&details.description_i18n),
NULL),
- GNUNET_JSON_spec_uint32("kind", &details.kind),
+ GNUNET_JSON_spec_string("kind", &kind),
GNUNET_JSON_spec_timestamp ("valid_after",
&details.valid_after),
GNUNET_JSON_spec_timestamp ("valid_before",
@@ -111,6 +112,20 @@ TMH_private_post_token_families (const struct TMH_RequestHandler *rh,
}
}
+
+ if (strcmp(kind, "discount") == 0)
+ details.kind = TALER_MERCHANTDB_TFK_Discount;
+ else if (strcmp(kind, "subscription") == 0)
+ details.kind = TALER_MERCHANTDB_TFK_Subscription;
+ else
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "kind");
+ }
+
if (NULL == details.description_i18n)
details.description_i18n = json_object ();