diff options
author | priscilla <priscilla.huang@efrei.net> | 2022-11-21 07:18:48 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2022-11-21 07:18:48 -0500 |
commit | 0fa22bbcb5cb52edf6bcb75c70a2d1f9356f6b9c (patch) | |
tree | 03804012027eadcfa6311843d4a9277f7f4332f6 /src/backend/taler-merchant-httpd_private-get-templates.c | |
parent | cadd4ae3c9e59dbe153622cb9a142795f318e651 (diff) | |
download | merchant-0fa22bbcb5cb52edf6bcb75c70a2d1f9356f6b9c.tar.gz merchant-0fa22bbcb5cb52edf6bcb75c70a2d1f9356f6b9c.tar.bz2 merchant-0fa22bbcb5cb52edf6bcb75c70a2d1f9356f6b9c.zip |
templates
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-templates.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-templates.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-templates.c b/src/backend/taler-merchant-httpd_private-get-templates.c new file mode 100644 index 00000000..20cd0cdc --- /dev/null +++ b/src/backend/taler-merchant-httpd_private-get-templates.c @@ -0,0 +1,76 @@ +/* + This file is part of TALER + (C) 2019, 2020, 2021 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file taler-merchant-httpd_private-get-templates.c + * @brief implement GET /templates + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler-merchant-httpd_private-get-templates.h" + + +/** + * Add template details to our JSON array. + * + * @param cls a `json_t *` JSON array to build + * @param template_id ID of the template + */ +static void +add_template (void *cls, + const char *template_id) +{ + json_t *pa = cls; + + GNUNET_assert (0 == + json_array_append_new ( + pa, + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("template_id", + template_id)))); +} + + +MHD_RESULT +TMH_private_get_templates (const struct TMH_RequestHandler *rh, + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) +{ + json_t *pa; + enum GNUNET_DB_QueryStatus qs; + + pa = json_array (); + GNUNET_assert (NULL != pa); + qs = TMH_db->lookup_templates (TMH_db->cls, + hc->instance->settings.id, + &add_template, + pa); + if (0 > qs) + { + GNUNET_break (0); + json_decref (pa); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + } + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("templates", + pa)); +} + + +/* end of taler-merchant-httpd_private-get-templates.c */ |