aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-get-categories-ID.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-05-25 23:02:19 +0200
committerChristian Grothoff <christian@grothoff.org>2024-05-25 23:02:19 +0200
commit8d13ea6b82c39f9c68b9abf2ec70d221eef4ab74 (patch)
tree627d2a0059a1c7e28d6bf956d502ae9267ca6afa /src/backend/taler-merchant-httpd_private-get-categories-ID.c
parent3da8f0416e8a3f449db34d54dd4c3f359471bb7e (diff)
-more work on categories
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-categories-ID.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-categories-ID.c90
1 files changed, 49 insertions, 41 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-categories-ID.c b/src/backend/taler-merchant-httpd_private-get-categories-ID.c
index bebe087f..02ef3495 100644
--- a/src/backend/taler-merchant-httpd_private-get-categories-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-categories-ID.c
@@ -38,35 +38,36 @@ TMH_private_get_categories_ID (
struct TMH_HandlerContext *hc)
{
struct TMH_MerchantInstance *mi = hc->instance;
- struct TALER_MERCHANTDB_OtpDeviceDetails tp = { 0 };
enum GNUNET_DB_QueryStatus qs;
- uint64_t faketime_s
- = GNUNET_TIME_timestamp_to_s (GNUNET_TIME_timestamp_get ());
- struct GNUNET_TIME_Timestamp my_time;
- struct TALER_Amount price;
+ unsigned long long cnum;
+ char dummy;
+ struct TALER_MERCHANTDB_CategoryDetails cd;
- TALER_MHD_parse_request_number (connection,
- "faketime",
- &faketime_s);
- memset (&price,
- 0,
- sizeof (price));
- TALER_MHD_parse_request_amount (connection,
- "price",
- &price);
- my_time = GNUNET_TIME_timestamp_from_s (faketime_s);
GNUNET_assert (NULL != mi);
- qs = TMH_db->select_otp (TMH_db->cls,
- mi->settings.id,
- hc->infix,
- &tp);
+ GNUNET_assert (NULL != hc->infix);
+ if (1 != sscanf (hc->infix,
+ "%llu%c",
+ &cnum,
+ &dummy))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "category_id must be a number");
+ }
+
+ qs = TMH_db->select_category (TMH_db->cls,
+ mi->settings.id,
+ cnum,
+ &cd);
if (0 > qs)
{
GNUNET_break (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
- "select_otp");
+ "select_category");
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
{
@@ -77,32 +78,39 @@ TMH_private_get_categories_ID (
}
{
MHD_RESULT ret;
- char *pos_confirmation;
+ json_t *products;
+
+ products = json_array ();
+ GNUNET_assert (NULL != products);
+ for (unsigned int i = 0; i<cd.num_products; i++)
+ {
+ const struct TALER_MERCHANTDB_ProductSummary *product
+ = &cd.products[i];
+ json_t *jprod;
+
+ jprod = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("product_id",
+ product->product_id),
+ GNUNET_JSON_pack_string ("description",
+ product->description),
+ GNUNET_JSON_pack_object_steal ("description_i18n",
+ product->description_i18n));
+ GNUNET_assert (0 ==
+ json_array_append_new (products,
+ jprod));
+ }
- pos_confirmation = (NULL == tp.otp_key)
- ? NULL
- : TALER_build_pos_confirmation (tp.otp_key,
- tp.otp_algorithm,
- &price,
- my_time);
- /* Note: we deliberately (by design) do not return the otp_key */
ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- GNUNET_JSON_pack_string ("device_description",
- tp.otp_description),
+ GNUNET_JSON_pack_string ("name",
+ cd.category_name),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_string ("otp_code",
- pos_confirmation)),
- GNUNET_JSON_pack_uint64 ("otp_timestamp",
- faketime_s),
- GNUNET_JSON_pack_uint64 ("otp_algorithm",
- tp.otp_algorithm),
- GNUNET_JSON_pack_uint64 ("otp_ctr",
- tp.otp_ctr));
- GNUNET_free (pos_confirmation);
- GNUNET_free (tp.otp_description);
- GNUNET_free (tp.otp_key);
+ GNUNET_JSON_pack_object_incref ("name_i18n",
+ cd.category_name_i18n)),
+ GNUNET_JSON_pack_array_steal ("products",
+ products));
+ TALER_MERCHANTDB_category_details_free (&cd);
return ret;
}
}