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

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2025 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-units.c
      18              :  * @brief implement GET /private/units
      19              :  * @author Bohdan Potuzhnyi
      20              :  */
      21              : #include "platform.h"
      22              : #include "taler-merchant-httpd_get-private-units.h"
      23              : #include "merchant-database/iterate_units.h"
      24              : 
      25              : 
      26              : static void
      27          148 : add_unit (void *cls,
      28              :           uint64_t unit_serial,
      29              :           const struct TALER_MERCHANTDB_UnitDetails *ud)
      30              : {
      31          148 :   json_t *ua = cls;
      32              : 
      33          148 :   GNUNET_assert (
      34              :     0 ==
      35              :     json_array_append_new (
      36              :       ua,
      37              :       GNUNET_JSON_PACK (
      38              :         GNUNET_JSON_pack_uint64 ("unit_serial",
      39              :                                  unit_serial),
      40              :         GNUNET_JSON_pack_string ("unit",
      41              :                                  ud->unit),
      42              :         GNUNET_JSON_pack_string ("unit_name_long",
      43              :                                  ud->unit_name_long),
      44              :         GNUNET_JSON_pack_object_incref ("unit_name_long_i18n",
      45              :                                         (json_t *) ud->unit_name_long_i18n),
      46              :         GNUNET_JSON_pack_string ("unit_name_short",
      47              :                                  ud->unit_name_short),
      48              :         GNUNET_JSON_pack_object_incref ("unit_name_short_i18n",
      49              :                                         (json_t *) ud->unit_name_short_i18n),
      50              :         GNUNET_JSON_pack_bool ("unit_allow_fraction",
      51              :                                ud->unit_allow_fraction),
      52              :         GNUNET_JSON_pack_uint64 ("unit_precision_level",
      53              :                                  ud->unit_precision_level),
      54              :         GNUNET_JSON_pack_bool ("unit_active",
      55              :                                ud->unit_active),
      56              :         GNUNET_JSON_pack_bool ("unit_builtin",
      57              :                                ud->unit_builtin))));
      58          148 : }
      59              : 
      60              : 
      61              : enum MHD_Result
      62            4 : TMH_private_get_units (const struct TMH_RequestHandler *rh,
      63              :                        struct MHD_Connection *connection,
      64              :                        struct TMH_HandlerContext *hc)
      65              : {
      66              :   json_t *ua;
      67              :   enum GNUNET_DB_QueryStatus qs;
      68              : 
      69              :   (void) rh;
      70            4 :   ua = json_array ();
      71            4 :   GNUNET_assert (NULL != ua);
      72            4 :   qs = TALER_MERCHANTDB_iterate_units (TMH_db,
      73            4 :                                        hc->instance->settings.id,
      74              :                                        &add_unit,
      75              :                                        ua);
      76            4 :   if (0 > qs)
      77              :   {
      78            0 :     GNUNET_break (0);
      79            0 :     json_decref (ua);
      80            0 :     return TALER_MHD_reply_with_error (connection,
      81              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      82              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      83              :                                        NULL);
      84              :   }
      85            4 :   return TALER_MHD_REPLY_JSON_PACK (connection,
      86              :                                     MHD_HTTP_OK,
      87              :                                     GNUNET_JSON_pack_array_steal ("units",
      88              :                                                                   ua));
      89              : }
      90              : 
      91              : 
      92              : /* end of taler-merchant-httpd_get-private-units.c */
        

Generated by: LCOV version 2.0-1