LCOV - code coverage report
Current view: top level - backenddb - pg_insert_product.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 27 100.0 %
Date: 2025-06-23 16:22:09 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 2022-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 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 backenddb/pg_insert_product.c
      18             :  * @brief Implementation of the insert_product function for Postgres
      19             :  * @author Christian Grothoff
      20             :  * @author Iván Ávalos
      21             :  */
      22             : #include "platform.h"
      23             : #include <taler/taler_error_codes.h>
      24             : #include <taler/taler_dbevents.h>
      25             : #include <taler/taler_pq_lib.h>
      26             : #include "pg_insert_product.h"
      27             : #include "pg_helper.h"
      28             : 
      29             : enum GNUNET_DB_QueryStatus
      30          16 : TMH_PG_insert_product (void *cls,
      31             :                        const char *instance_id,
      32             :                        const char *product_id,
      33             :                        const struct TALER_MERCHANTDB_ProductDetails *pd,
      34             :                        size_t num_cats,
      35             :                        const uint64_t *cats,
      36             :                        bool *no_instance,
      37             :                        bool *conflict,
      38             :                        ssize_t *no_cat)
      39             : {
      40          16 :   struct PostgresClosure *pg = cls;
      41          16 :   struct GNUNET_PQ_QueryParam params[] = {
      42          16 :     GNUNET_PQ_query_param_string (instance_id),
      43          16 :     GNUNET_PQ_query_param_string (product_id),
      44          16 :     GNUNET_PQ_query_param_string (pd->description),
      45          16 :     TALER_PQ_query_param_json (pd->description_i18n),
      46          16 :     GNUNET_PQ_query_param_string (pd->unit),
      47          16 :     GNUNET_PQ_query_param_string (pd->image),
      48          16 :     TALER_PQ_query_param_json (pd->taxes),
      49          16 :     TALER_PQ_query_param_amount_with_currency (pg->conn,
      50             :                                                &pd->price),
      51          16 :     GNUNET_PQ_query_param_uint64 (&pd->total_stock),
      52          16 :     TALER_PQ_query_param_json (pd->address),
      53          16 :     GNUNET_PQ_query_param_timestamp (&pd->next_restock),
      54          16 :     GNUNET_PQ_query_param_uint32 (&pd->minimum_age),
      55          16 :     GNUNET_PQ_query_param_array_uint64 (num_cats,
      56             :                                         cats,
      57             :                                         pg->conn),
      58             :     GNUNET_PQ_query_param_end
      59             :   };
      60             :   uint64_t ncat;
      61          16 :   bool cats_found = true;
      62          16 :   struct GNUNET_PQ_ResultSpec rs[] = {
      63          16 :     GNUNET_PQ_result_spec_bool ("conflict",
      64             :                                 conflict),
      65          16 :     GNUNET_PQ_result_spec_bool ("no_instance",
      66             :                                 no_instance),
      67          16 :     GNUNET_PQ_result_spec_allow_null (
      68             :       GNUNET_PQ_result_spec_uint64 ("no_cat",
      69             :                                     &ncat),
      70             :       &cats_found),
      71             :     GNUNET_PQ_result_spec_end
      72             :   };
      73             :   enum GNUNET_DB_QueryStatus qs;
      74             : 
      75          16 :   check_connection (pg);
      76          16 :   PREPARE (pg,
      77             :            "insert_product",
      78             :            "SELECT"
      79             :            " out_conflict AS conflict"
      80             :            ",out_no_cat AS no_cat"
      81             :            ",out_no_instance AS no_instance"
      82             :            " FROM merchant_do_insert_product"
      83             :            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);");
      84          16 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      85             :                                                  "insert_product",
      86             :                                                  params,
      87             :                                                  rs);
      88          16 :   GNUNET_PQ_cleanup_query_params_closures (params);
      89          16 :   *no_cat = (cats_found) ? -1 : (ssize_t) ncat;
      90          16 :   return qs;
      91             : }

Generated by: LCOV version 1.16