LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_get-private-categories.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 14 0
Test Date: 2026-09-04 23:42:01 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2024 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 src/backend/taler-merchant-httpd_get-private-categories.c
      18              :  * @brief implement GET /categories
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include "taler-merchant-httpd_get-private-categories.h"
      23              : #include "merchant-database/iterate_categories.h"
      24              : 
      25              : 
      26              : /**
      27              :  * Add category details to our JSON array.
      28              :  *
      29              :  * @param cls a `json_t *` JSON array to build
      30              :  * @param category_id ID of the category
      31              :  * @param category_name name of the category
      32              :  * @param category_name_i18n translations of the @a category_name
      33              :  * @param product_count number of products in the category
      34              :  */
      35              : static void
      36            0 : add_category (void *cls,
      37              :               uint64_t category_id,
      38              :               const char *category_name,
      39              :               const json_t *category_name_i18n,
      40              :               uint64_t product_count)
      41              : {
      42            0 :   json_t *pa = cls;
      43              : 
      44            0 :   GNUNET_assert (
      45              :     0 ==
      46              :     json_array_append_new (
      47              :       pa,
      48              :       GNUNET_JSON_PACK (
      49              :         GNUNET_JSON_pack_uint64 (
      50              :           "category_id",
      51              :           category_id),
      52              :         GNUNET_JSON_pack_string (
      53              :           "name",
      54              :           category_name),
      55              :         GNUNET_JSON_pack_object_incref (
      56              :           "name_i18n",
      57              :           (json_t *) category_name_i18n),
      58              :         GNUNET_JSON_pack_uint64 (
      59              :           "product_count",
      60              :           product_count))));
      61            0 : }
      62              : 
      63              : 
      64              : enum MHD_Result
      65            0 : TMH_private_get_categories (const struct TMH_RequestHandler *rh,
      66              :                             struct MHD_Connection *connection,
      67              :                             struct TMH_HandlerContext *hc)
      68              : {
      69              :   json_t *pa;
      70              :   enum GNUNET_DB_QueryStatus qs;
      71              : 
      72            0 :   pa = json_array ();
      73            0 :   GNUNET_assert (NULL != pa);
      74            0 :   qs = TALER_MERCHANTDB_iterate_categories (TMH_db,
      75            0 :                                             hc->instance->settings.id,
      76              :                                             &add_category,
      77              :                                             pa);
      78            0 :   if (0 > qs)
      79              :   {
      80            0 :     GNUNET_break (0);
      81            0 :     json_decref (pa);
      82            0 :     return TALER_MHD_reply_with_error (connection,
      83              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      84              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      85              :                                        NULL);
      86              :   }
      87            0 :   return TALER_MHD_REPLY_JSON_PACK (connection,
      88              :                                     MHD_HTTP_OK,
      89              :                                     GNUNET_JSON_pack_array_steal ("categories",
      90              :                                                                   pa));
      91              : }
      92              : 
      93              : 
      94              : /* end of taler-merchant-httpd_get-private-categories.c */
        

Generated by: LCOV version 2.0-1