LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-templates.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 14 78.6 %
Date: 2025-06-23 16:22:09 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2022 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU Affero General Public License as published by the Free Software
       7             :   Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file taler-merchant-httpd_private-get-templates.c
      18             :  * @brief implement GET /templates
      19             :  * @author Priscilla HUANG
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler-merchant-httpd_private-get-templates.h"
      23             : 
      24             : 
      25             : /**
      26             :  * Add template details to our JSON array.
      27             :  *
      28             :  * @param cls a `json_t *` JSON array to build
      29             :  * @param template_id ID of the template
      30             :  * @param template_description human-readable description for the template
      31             :  */
      32             : static void
      33           2 : add_template (void *cls,
      34             :               const char *template_id,
      35             :               const char *template_description)
      36             : {
      37           2 :   json_t *pa = cls;
      38             : 
      39           2 :   GNUNET_assert (0 ==
      40             :                  json_array_append_new (
      41             :                    pa,
      42             :                    GNUNET_JSON_PACK (
      43             :                      GNUNET_JSON_pack_string ("template_id", template_id),
      44             :                      GNUNET_JSON_pack_string ("template_description",
      45             :                                               template_description))));
      46           2 : }
      47             : 
      48             : 
      49             : MHD_RESULT
      50           4 : TMH_private_get_templates (const struct TMH_RequestHandler *rh,
      51             :                            struct MHD_Connection *connection,
      52             :                            struct TMH_HandlerContext *hc)
      53             : {
      54             :   json_t *pa;
      55             :   enum GNUNET_DB_QueryStatus qs;
      56             : 
      57           4 :   pa = json_array ();
      58           4 :   GNUNET_assert (NULL != pa);
      59           4 :   qs = TMH_db->lookup_templates (TMH_db->cls,
      60           4 :                                  hc->instance->settings.id,
      61             :                                  &add_template,
      62             :                                  pa);
      63           4 :   if (0 > qs)
      64             :   {
      65           0 :     GNUNET_break (0);
      66           0 :     json_decref (pa);
      67           0 :     return TALER_MHD_reply_with_error (connection,
      68             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      69             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      70             :                                        NULL);
      71             :   }
      72           4 :   return TALER_MHD_REPLY_JSON_PACK (connection,
      73             :                                     MHD_HTTP_OK,
      74             :                                     GNUNET_JSON_pack_array_steal ("templates",
      75             :                                                                   pa));
      76             : }
      77             : 
      78             : 
      79             : /* end of taler-merchant-httpd_private-get-templates.c */

Generated by: LCOV version 1.16