merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_get-private-units-UNIT.c (4124B)


      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/select_unit.h"
     24 
     25 
     26 enum MHD_Result
     27 TMH_private_get_units_ID (const struct TMH_RequestHandler *rh,
     28                           struct MHD_Connection *connection,
     29                           struct TMH_HandlerContext *hc)
     30 {
     31   struct TALER_MERCHANTDB_UnitDetails ud = { 0 };
     32   enum GNUNET_DB_QueryStatus qs;
     33   enum MHD_Result ret;
     34 
     35   (void) rh;
     36   GNUNET_assert (NULL != hc->infix);
     37   qs = TALER_MERCHANTDB_select_unit (TMH_db,
     38                                      hc->instance->settings.id,
     39                                      hc->infix,
     40                                      &ud);
     41   switch (qs)
     42   {
     43   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     44     break;
     45   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     46     return TALER_MHD_reply_with_error (connection,
     47                                        MHD_HTTP_NOT_FOUND,
     48                                        TALER_EC_MERCHANT_GENERIC_UNIT_UNKNOWN,
     49                                        hc->infix);
     50   case GNUNET_DB_STATUS_SOFT_ERROR:
     51   case GNUNET_DB_STATUS_HARD_ERROR:
     52     GNUNET_break (0);
     53     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   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   TALER_MERCHANTDB_unit_details_free (&ud);
     86   return ret;
     87 }
     88 
     89 
     90 /* end of taler-merchant-httpd_get-private-units-UNIT.c */