summaryrefslogtreecommitdiff
path: root/src/backenddb/merchant-0004.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/backenddb/merchant-0004.sql')
-rw-r--r--src/backenddb/merchant-0004.sql177
1 files changed, 129 insertions, 48 deletions
diff --git a/src/backenddb/merchant-0004.sql b/src/backenddb/merchant-0004.sql
index f77a693a..8e8574e9 100644
--- a/src/backenddb/merchant-0004.sql
+++ b/src/backenddb/merchant-0004.sql
@@ -51,7 +51,6 @@ COMMENT ON COLUMN merchant_template.template_contract
IS 'The template contract will contains some additional information.'
-
-- C CODE
@@ -85,7 +84,7 @@ postgres_delete_template (void *cls,
}
/**
- * Insert details about a particular product.
+ * Insert details about a particular template.
*
* @param cls closure
* @param instance_id instance to insert product for
@@ -105,7 +104,7 @@ postgres_insert_template (void *cls,
GNUNET_PQ_query_param_string (template_id),
GNUNET_PQ_query_param_string (pd->template_description),
GNUNET_PQ_query_param_string (pd->image),
- GNUNET_PQ_query_param [],
+ GNUNET_PQ_query_param_string (pd->template_contract),
GNUNET_PQ_query_param_end
};
@@ -135,7 +134,7 @@ postgres_insert_template (void *cls,
*/
static enum GNUNET_DB_QueryStatus
-postgres_update_product (void *cls,
+postgres_update_template (void *cls,
const char *instance_id,
const char *template_id,
const struct TALER_MERCHANTDB_TemplateDetails *pd)
@@ -146,8 +145,7 @@ postgres_update_product (void *cls,
GNUNET_PQ_query_param_string (template_id),
GNUNET_PQ_query_param_string (pd->template_description),
GNUNET_PQ_query_param_string (pd->image),
- TALER_PQ_query_param_amount (&pd->amount),
- GNUNET_PQ_query_param param2[],
+ GNUNET_PQ_query_param_string (pd->template_contract),
GNUNET_PQ_query_param_end
};
@@ -163,27 +161,6 @@ postgres_update_product (void *cls,
-{
- struct PostgresClosure *pg = cls2;
- struct GNUNET_PQ_QueryParam param2[] = {
- TALER_PQ_query_param_amount (&pd->amount),
- GNUNET_PQ_query_param_string (pd->summary),
- GNUNET_PQ_query_param_relativetime (&pd->pay_duration),
- GNUNET_PQ_query_param_uint32 (&pd->minimum_age),
-
- };
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "update_template",
- params);
-}
-
-
-
/**
* Context used for postgres_lookup_template().
@@ -228,6 +205,8 @@ lookup_templates_cb (void *cls,
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_string ("template_id",
&template_id),
+ GNUNET_PQ_result_spec_string ("template_description",
+ &template_description),
GNUNET_PQ_result_spec_end
};
@@ -258,7 +237,7 @@ lookup_templates_cb (void *cls,
static enum GNUNET_DB_QueryStatus
postgres_lookup_templates (void *cls,
const char *instance_id,
- TALER_MERCHANTDB_ProductsCallback cb,
+ TALER_MERCHANTDB_TemplateCallback cb,
void *cb_cls)
{
struct PostgresClosure *pg = cls;
@@ -301,7 +280,7 @@ static enum GNUNET_DB_QueryStatus
postgres_lookup_template (void *cls,
const char *instance_id,
const char *template_id,
- struct TALER_MERCHANTDB_EtemplateDetails *pd)
+ struct TALER_MERCHANTDB_TemplateDetails *pd)
{
struct PostgresClosure *pg = cls;
struct GNUNET_PQ_QueryParam params[] = {
@@ -329,7 +308,8 @@ postgres_lookup_template (void *cls,
&pd->template_description),
GNUNET_PQ_result_spec_string ("image",
&pd->image),
- GNUNET_PQ_ResultSpec rs2[],
+ GNUNET_PQ_result_spec_string ("template_contract",
+ &pd->template_contract),
GNUNET_PQ_result_spec_end
};
@@ -338,26 +318,127 @@ postgres_lookup_template (void *cls,
"lookup_template",
params,
rs);
- struct GNUNET_PQ_ResultSpec rs2[] = {
- GNUNET_PQ_result_spec_string ("Summary",
- &pd->summary),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &pd->amount),
- GNUNET_PQ_result_spec_uint64 ("minimum_age",
- &pd->minimum_age),
- GNUNET_PQ_result_spec_relativetime ("pay_duration",
- &pd->pay_duration),
- GNUNET_PQ_result_spec_end
-
- };
-
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_template",
- params,
- rs);
}
}
+------------------------------API--------------------------------
+
+/**
+ * Typically called by `lookup_templates`.
+ *
+ * @param cls a `json_t *` JSON array to build
+ * @param template_id ID of the template
+ */
+typedef void
+(*TALER_MERCHANTDB_TemplatesCallback)(void *cls,
+ const char *template_id,
+ const char *template_description);
+
+
+/**
+ * Details about a template.
+ */
+struct TALER_MERCHANTDB_TemplateDetails
+{
+ /**
+ * Description of the template.
+ */
+ const char *template_description;
+
+ /**
+ * Base64-encoded product image, or NULL.
+ */
+ const char *image;
+
+ /**
+ * In this template contract, we can have additional information.
+ */
+ const json_t *template_contract;
+};
+
+
+
+/**
+ * Lookup all of the templates the given instance has configured.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup template for
+ * @param cb function to call on all template found
+ * @param cb_cls closure for @a cb
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+(*lookup_templates) (void *cls,
+ const char *instance_id,
+ TALER_MERCHANTDB_TemplateCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Lookup details about a particular template.
+ *
+ * @param cls closure
+ * @param instance_id instance to lookup template for
+ * @param template_id template to lookup
+ * @param[out] pd set to the template details on success, can be NULL
+ * (in that case we only want to check if the template exists)
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+(*lookup_template) (void *cls,
+ const char *instance_id,
+ const char *template_id,
+ struct TALER_MERCHANTDB_TemplateDetails *pd);
+
+/**
+ * Delete information about a template.
+ *
+ * @param cls closure
+ * @param instance_id instance to delete product of
+ * @param template_id template to delete
+ * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ * if template unknow.
+ */
+enum GNUNET_DB_QueryStatus
+(*delete_template) (void *cls,
+ const char *instance_id,
+ const char *template_id);
+
+
+
+/**
+ * Insert details about a particular template.
+ *
+ * @param cls closure
+ * @param instance_id instance to insert template for
+ * @param template_id template identifier of template to insert
+ * @param pd the template details to insert
+ * @return database result code
+ */
+enum GNUNET_DB_QueryStatus
+(*insert_template) (void *cls,
+ const char *instance_id,
+ const char *template_id,
+ const struct TALER_MERCHANTDB_TemplateDetails *pd);
+
+
+
+/**
+ * Update details about a particular template.
+ *
+ * @param cls closure
+ * @param instance_id instance to update template for
+ * @param template_id template to update
+ * @param pd update to the template details on success, can be NULL
+ * (in that case we only want to check if the template exists)
+ * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
+ * does not yet exist.
+ */
+
+enum GNUNET_DB_QueryStatus
+(*update_template) (void *cls,
+ const char *instance_id,
+ const char *template_id,
+ const struct TALER_MERCHANTDB_TemplateDetails *pd)