merchant

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

update_report.c (3389B)


      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_report.c
     18  * @brief Implementation of the update_report function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "merchant-database/update_report.h"
     26 #include "helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 TALER_MERCHANTDB_update_report (struct TALER_MERCHANTDB_PostgresContext *pg,
     31                                 const char *instance_id,
     32                                 uint64_t report_id,
     33                                 const char *report_program_section,
     34                                 const char *report_description,
     35                                 const char *mime_type,
     36                                 const char *data_source,
     37                                 const char *target_address,
     38                                 struct GNUNET_TIME_Relative frequency,
     39                                 struct GNUNET_TIME_Relative frequency_shift)
     40 {
     41   struct GNUNET_TIME_Timestamp start;
     42   struct GNUNET_PQ_QueryParam params[] = {
     43     GNUNET_PQ_query_param_string (instance_id),
     44     GNUNET_PQ_query_param_uint64 (&report_id),
     45     GNUNET_PQ_query_param_string (report_program_section),
     46     GNUNET_PQ_query_param_string (report_description),
     47     GNUNET_PQ_query_param_string (mime_type),
     48     GNUNET_PQ_query_param_string (data_source),
     49     GNUNET_PQ_query_param_string (target_address),
     50     GNUNET_PQ_query_param_relative_time (&frequency),
     51     GNUNET_PQ_query_param_relative_time (&frequency_shift),
     52     GNUNET_PQ_query_param_timestamp (&start),
     53     GNUNET_PQ_query_param_end
     54   };
     55 
     56   start =
     57     GNUNET_TIME_absolute_to_timestamp (
     58       GNUNET_TIME_absolute_add (
     59         GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
     60                                          frequency),
     61         GNUNET_TIME_relative_add (frequency,
     62                                   frequency_shift)));
     63 
     64   check_connection (pg);
     65   PREPARE (pg,
     66            "update_report",
     67            "UPDATE merchant_reports SET"
     68            "  report_program_section=$3"
     69            " ,report_description=$4"
     70            " ,mime_type=$5"
     71            " ,data_source=$6"
     72            " ,target_address=$7"
     73            " ,frequency=$8"
     74            " ,frequency_shift=$9"
     75            " ,next_transmission=$10"
     76            " WHERE merchant_serial="
     77            "   (SELECT merchant_serial"
     78            "      FROM merchant_instances"
     79            "     WHERE merchant_id=$1)"
     80            "   AND report_serial=$2;");
     81   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     82                                              "update_report",
     83                                              params);
     84 }