diff options
author | priscilla <priscilla.huang@efrei.net> | 2022-11-16 10:33:02 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2022-11-16 10:33:02 -0500 |
commit | df0e9fd8702e0dc133c61b836571b10c04da80a8 (patch) | |
tree | 138ac400b9ece836b428ccef43ee17b8752969a0 | |
parent | dd78f3d2c4c3862344cde18c633a92e798ab24dd (diff) | |
download | merchant-df0e9fd8702e0dc133c61b836571b10c04da80a8.tar.gz merchant-df0e9fd8702e0dc133c61b836571b10c04da80a8.tar.bz2 merchant-df0e9fd8702e0dc133c61b836571b10c04da80a8.zip |
template API
-rw-r--r-- | src/backenddb/merchant-0001.sql | 24 | ||||
-rw-r--r-- | src/backenddb/merchant-0004.sql | 177 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 6 |
3 files changed, 159 insertions, 48 deletions
diff --git a/src/backenddb/merchant-0001.sql b/src/backenddb/merchant-0001.sql index a74306d1..5a8fda00 100644 --- a/src/backenddb/merchant-0001.sql +++ b/src/backenddb/merchant-0001.sql @@ -599,5 +599,29 @@ COMMENT ON COLUMN merchant_kyc.exchange_url IS 'Which exchange base URL is this KYC status valid for'; +---------------------------Template------------------------------ + + +CREATE TABLE IF NOT EXISTS merchant_template + (template_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY + ,merchant_serial BIGINT NOT NULL + REFERENCES merchant_instances (merchant_serial) ON DELETE CASCADE + ,template_id VARCHAR NOT NULL + ,template_description VARCHAR NOT NULL + ,image BYTEA + ,template_contract VARCHAR NOT NULL -- in JSON format + ,UNIQUE (merchant_serial, template_id) + ); +COMMENT ON TABLE merchant_template + IS 'template used by the merchant (may be incomplete, frontend can override)'; +COMMENT ON COLUMN merchant_template.template_description + IS 'Human-readable template description'; +COMMENT ON COLUMN merchant_template.image + IS 'NOT NULL, but can be 0 bytes; must contain an ImageDataUrl'; +COMMENT ON COLUMN merchant_template.template_contract + IS 'The template contract will contains some additional information.' + + + -- Complete transaction COMMIT; 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) diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index ca977c76..979b7eaa 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -6815,6 +6815,12 @@ postgres_insert_pickup_blind_signature ( } + + + + + + /** * Establish connection to the database. * |