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

            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-UNIT.c
      18              :  * @brief implement GET /private/units/$UNIT
      19              :  * @author Bohdan Potuzhnyi
      20              :  */
      21              : #include "platform.h"
      22              : #include "taler-merchant-httpd_get-private-units-UNIT.h"
      23              : #include "merchant-database/get_unit.h"
      24              : 
      25              : 
      26              : enum MHD_Result
      27           10 : TMH_private_get_units_ID (const struct TMH_RequestHandler *rh,
      28              :                           struct MHD_Connection *connection,
      29              :                           struct TMH_HandlerContext *hc)
      30              : {
      31           10 :   struct TALER_MERCHANTDB_UnitDetails ud = { 0 };
      32              :   enum GNUNET_DB_QueryStatus qs;
      33              :   enum MHD_Result ret;
      34              : 
      35              :   (void) rh;
      36           10 :   GNUNET_assert (NULL != hc->infix);
      37           10 :   qs = TALER_MERCHANTDB_get_unit (TMH_db,
      38           10 :                                   hc->instance->settings.id,
      39           10 :                                   hc->infix,
      40              :                                   &ud);
      41           10 :   switch (qs)
      42              :   {
      43            8 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
      44            8 :     break;
      45            2 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      46            2 :     return TALER_MHD_reply_with_error (connection,
      47              :                                        MHD_HTTP_NOT_FOUND,
      48              :                                        TALER_EC_MERCHANT_GENERIC_UNIT_UNKNOWN,
      49            2 :                                        hc->infix);
      50            0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      51              :   case GNUNET_DB_STATUS_HARD_ERROR:
      52            0 :     GNUNET_break (0);
      53            0 :     return TALER_MHD_reply_with_error (connection,
      54              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      55              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      56              :                                        "unit");
      57              :   }
      58              : 
      59            8 :   ret = TALER_MHD_REPLY_JSON_PACK (connection,
      60              :                                    MHD_HTTP_OK,
      61              :                                    GNUNET_JSON_pack_uint64 ("unit_serial",
      62              :                                                             ud.unit_serial),
      63              :                                    GNUNET_JSON_pack_string ("unit",
      64              :                                                             ud.unit),
      65              :                                    GNUNET_JSON_pack_string ("unit_name_long",
      66              :                                                             ud.unit_name_long),
      67              :                                    GNUNET_JSON_pack_object_incref (
      68              :                                      "unit_name_long_i18n",
      69              :                                      ud.unit_name_long_i18n),
      70              :                                    GNUNET_JSON_pack_string ("unit_name_short",
      71              :                                                             ud.unit_name_short),
      72              :                                    GNUNET_JSON_pack_object_incref (
      73              :                                      "unit_name_short_i18n",
      74              :                                      ud.unit_name_short_i18n),
      75              :                                    GNUNET_JSON_pack_bool ("unit_allow_fraction",
      76              :                                                           ud.unit_allow_fraction
      77              :                                                           ),
      78              :                                    GNUNET_JSON_pack_uint64 (
      79              :                                      "unit_precision_level",
      80              :                                      ud.unit_precision_level),
      81              :                                    GNUNET_JSON_pack_bool ("unit_active",
      82              :                                                           ud.unit_active),
      83              :                                    GNUNET_JSON_pack_bool ("unit_builtin",
      84              :                                                           ud.unit_builtin));
      85            8 :   TALER_MERCHANTDB_unit_details_free (&ud);
      86            8 :   return ret;
      87              : }
      88              : 
      89              : 
      90              : /* end of taler-merchant-httpd_get-private-units-UNIT.c */
        

Generated by: LCOV version 2.0-1