diff options
author | Sebastian <sebasjm@gmail.com> | 2024-08-01 12:16:03 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-08-01 12:16:03 -0300 |
commit | 13885d5a8d3d759b9183819a5d8138253c18cb20 (patch) | |
tree | a1734a20880715de65b0f6162db747337fdfcd37 /src/backenddb | |
parent | 873b48b5aabe28acbf0aeb274cd946fc1207b894 (diff) |
fix get category details
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/merchantdb_helper.c | 25 | ||||
-rw-r--r-- | src/backenddb/pg_select_category.c | 73 | ||||
-rw-r--r-- | src/backenddb/pg_select_category.h | 7 |
3 files changed, 89 insertions, 16 deletions
diff --git a/src/backenddb/merchantdb_helper.c b/src/backenddb/merchantdb_helper.c index 72b1c9a7..4397fb36 100644 --- a/src/backenddb/merchantdb_helper.c +++ b/src/backenddb/merchantdb_helper.c @@ -88,18 +88,19 @@ TALER_MERCHANTDB_category_details_free ( { GNUNET_free (cd->category_name); json_decref (cd->category_name_i18n); - for (unsigned int i = 0; i<cd->num_products; i++) - { - struct TALER_MERCHANTDB_ProductSummary *ps - = &cd->products[i]; - - GNUNET_free (ps->product_id); - GNUNET_free (ps->description); - json_decref (ps->description_i18n); - } - GNUNET_array_grow (cd->products, - cd->num_products, - 0); + // FIXME: also return product details + // for (unsigned int i = 0; i<cd->num_products; i++) + // { + // const char* *ps + // = &cd->products[i]; + + // GNUNET_free (ps); + // // GNUNET_free (ps->description); + // // json_decref (ps->description_i18n); + // } + // GNUNET_array_grow (cd->products, + // cd->num_products, + // 0); } diff --git a/src/backenddb/pg_select_category.c b/src/backenddb/pg_select_category.c index c20d7bb7..74e69a0b 100644 --- a/src/backenddb/pg_select_category.c +++ b/src/backenddb/pg_select_category.c @@ -30,8 +30,75 @@ enum GNUNET_DB_QueryStatus TMH_PG_select_category (void *cls, const char *instance_id, uint64_t category_id, - struct TALER_MERCHANTDB_CategoryDetails *cd) + struct TALER_MERCHANTDB_CategoryDetails *cd, + size_t *num_products, + const char* **products) { - GNUNET_break (0); // FIXME - return GNUNET_DB_STATUS_HARD_ERROR; + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_uint64 (&category_id), + GNUNET_PQ_query_param_end + }; + + if (NULL == cd) + { + struct GNUNET_PQ_ResultSpec rs_null[] = { + GNUNET_PQ_result_spec_end + }; + + check_connection (pg); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "select_category", + params, + rs_null); + } + else + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("category_name", + &cd->category_name), + TALER_PQ_result_spec_json ("category_name_i18n", + &cd->category_name_i18n), + GNUNET_PQ_result_spec_array_string (pg->conn, + "products", + num_products, + products), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "select_category", + "SELECT" + " category_name" + ",category_name_i18n" + ",t.product_array AS products" + " FROM merchant_categories mc" + " JOIN merchant_instances inst" + " USING (merchant_serial)" + ",LATERAL (" + " SELECT ARRAY (" + " SELECT " + " mi.product_id AS product_id" + // FIXME: also return product details (or NOT) + // " ,mi.description AS description" + // " ,mi.description_i18n AS description_i18n" + " FROM merchant_product_categories mpc" + " JOIN merchant_inventory mi" + " USING (product_serial)" + " WHERE mpc.category_serial = mc.category_serial" + " ) AS product_array" + " ) t" + " WHERE inst.merchant_id=$1" + " AND mc.category_serial=$2"); + + + check_connection (pg); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "select_category", + params, + rs); + + } } diff --git a/src/backenddb/pg_select_category.h b/src/backenddb/pg_select_category.h index 9eeb14aa..3b6e458b 100644 --- a/src/backenddb/pg_select_category.h +++ b/src/backenddb/pg_select_category.h @@ -34,12 +34,17 @@ * @param category_id category to update * @param[out] cd set to the category details on success, can be NULL * (in that case we only want to check if the category exists) + * @param[out] num_products set to length of @a products array + * @param[out] products set to array of products the + * category is in, caller must free() it. * @return database result code */ enum GNUNET_DB_QueryStatus TMH_PG_select_category (void *cls, const char *instance_id, uint64_t category_id, - struct TALER_MERCHANTDB_CategoryDetails *cd); + struct TALER_MERCHANTDB_CategoryDetails *cd, + size_t *num_products, + const char* **products); #endif |