merchant

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

update_unit.c (3433B)


      1 /*
      2    This file is part of TALER
      3    Copyright (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 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/backenddb/update_unit.c
     18  * @brief Implementation of the update_unit function for Postgres
     19  * @author Bohdan Potuzhnyi
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_pq_lib.h>
     23 #include "merchant-database/update_unit.h"
     24 #include "helper.h"
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_MERCHANTDB_update_unit (
     29   struct TALER_MERCHANTDB_PostgresContext *pg,
     30   const char *instance_id,
     31   const char *unit_id,
     32   const char *unit_name_long,
     33   const json_t *unit_name_long_i18n,
     34   const char *unit_name_short,
     35   const json_t *unit_name_short_i18n,
     36   const bool *unit_allow_fraction,
     37   const uint32_t *unit_precision_level,
     38   const bool *unit_active,
     39   bool *no_unit,
     40   bool *builtin_conflict)
     41 {
     42   struct GNUNET_PQ_QueryParam params[] = {
     43     GNUNET_PQ_query_param_string (unit_id),
     44     (NULL == unit_name_long)
     45     ? GNUNET_PQ_query_param_null ()
     46     : GNUNET_PQ_query_param_string (unit_name_long),
     47     (NULL == unit_name_long_i18n)
     48     ? GNUNET_PQ_query_param_null ()
     49     : TALER_PQ_query_param_json ((json_t *) unit_name_long_i18n),
     50     (NULL == unit_name_short)
     51     ? GNUNET_PQ_query_param_null ()
     52     : GNUNET_PQ_query_param_string (unit_name_short),
     53     (NULL == unit_name_short_i18n)
     54     ? GNUNET_PQ_query_param_null ()
     55     : TALER_PQ_query_param_json ((json_t *) unit_name_short_i18n),
     56     (NULL == unit_allow_fraction)
     57     ? GNUNET_PQ_query_param_null ()
     58     : GNUNET_PQ_query_param_bool (*unit_allow_fraction),
     59     (NULL == unit_precision_level)
     60     ? GNUNET_PQ_query_param_null ()
     61     : GNUNET_PQ_query_param_uint32 ((uint32_t *) unit_precision_level),
     62     (NULL == unit_active)
     63     ? GNUNET_PQ_query_param_null ()
     64     : GNUNET_PQ_query_param_bool (*unit_active),
     65     GNUNET_PQ_query_param_end
     66   };
     67   struct GNUNET_PQ_ResultSpec rs[] = {
     68     GNUNET_PQ_result_spec_bool ("out_no_unit",
     69                                 no_unit),
     70     GNUNET_PQ_result_spec_bool ("out_builtin_conflict",
     71                                 builtin_conflict),
     72     GNUNET_PQ_result_spec_end
     73   };
     74   enum GNUNET_DB_QueryStatus qs;
     75 
     76   GNUNET_assert (NULL != pg->current_merchant_id);
     77   GNUNET_assert (0 == strcmp (instance_id,
     78                               pg->current_merchant_id));
     79   check_connection (pg);
     80   TMH_PQ_prepare_anon (pg,
     81                        "SELECT"
     82                        " out_no_unit"
     83                        " ,out_builtin_conflict"
     84                        " FROM merchant_do_update_unit"
     85                        "($1,$2,$3,$4,$5,$6,$7,$8);");
     86   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     87                                                  "",
     88                                                  params,
     89                                                  rs);
     90   GNUNET_PQ_cleanup_query_params_closures (params);
     91   return qs;
     92 }