LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_historic-reserve-summary-get.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 26 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 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             : 
      18             : #include "platform.h"
      19             : #include <gnunet/gnunet_util_lib.h>
      20             : #include <gnunet/gnunet_json_lib.h>
      21             : #include <jansson.h>
      22             : #include <microhttpd.h>
      23             : #include <pthread.h>
      24             : #include "taler_json_lib.h"
      25             : #include "taler_mhd_lib.h"
      26             : #include "taler-auditor-httpd.h"
      27             : #include "taler-auditor-httpd_historic-reserve-summary-get.h"
      28             : 
      29             : /**
      30             :  * Add historic-reserve-summary to the list.
      31             :  *
      32             :  * @param[in,out] cls a `json_t *` array to extend
      33             :  * @param serial_id location of the @a dc in the database
      34             :  * @param start_time beginning of aggregated time interval
      35             :  * @param end_time end of aggregated time interval
      36             :  * @param reserve_profits total profits made
      37             :  *
      38             :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      39             : */
      40             : static enum GNUNET_GenericReturnValue
      41           0 : process_historic_reserve_summary (
      42             :   void *cls,
      43             :   uint64_t serial_id,
      44             :   struct GNUNET_TIME_Timestamp start_time,
      45             :   struct GNUNET_TIME_Timestamp end_time,
      46             :   const struct TALER_Amount *reserve_profits)
      47             : {
      48           0 :   json_t *list = cls;
      49             :   json_t *obj;
      50             : 
      51           0 :   obj = GNUNET_JSON_PACK (
      52             :     GNUNET_JSON_pack_int64 ("row_id",
      53             :                             serial_id),
      54             :     TALER_JSON_pack_time_abs_human ("start_date",
      55             :                                     start_time.abs_time),
      56             :     TALER_JSON_pack_time_abs_human ("end_date",
      57             :                                     end_time.abs_time),
      58             :     TALER_JSON_pack_amount ("reserve_profits",
      59             :                             reserve_profits)
      60             :     );
      61           0 :   GNUNET_break (0 ==
      62             :                 json_array_append_new (list,
      63             :                                        obj));
      64           0 :   return GNUNET_OK;
      65             : }
      66             : 
      67             : 
      68             : MHD_RESULT
      69           0 : TAH_HISTORIC_RESERVE_SUMMARY_handler_get (
      70             :   struct TAH_RequestHandler *rh,
      71             :   struct MHD_Connection *connection,
      72             :   void **connection_cls,
      73             :   const char *upload_data,
      74             :   size_t *upload_data_size,
      75             :   const char *const args[])
      76             : {
      77             :   json_t *ja;
      78             :   enum GNUNET_DB_QueryStatus qs;
      79           0 :   int64_t limit = -20;
      80             :   uint64_t offset;
      81             : 
      82             :   (void) rh;
      83             :   (void) connection_cls;
      84             :   (void) upload_data;
      85             :   (void) upload_data_size;
      86           0 :   if (GNUNET_SYSERR ==
      87           0 :       TAH_plugin->preflight (TAH_plugin->cls))
      88             :   {
      89           0 :     GNUNET_break (0);
      90           0 :     return TALER_MHD_reply_with_error (
      91             :       connection,
      92             :       MHD_HTTP_INTERNAL_SERVER_ERROR,
      93             :       TALER_EC_GENERIC_DB_SETUP_FAILED,
      94             :       NULL);
      95             :   }
      96           0 :   TALER_MHD_parse_request_snumber (connection,
      97             :                                    "limit",
      98             :                                    &limit);
      99           0 :   if (limit < 0)
     100           0 :     offset = INT64_MAX;
     101             :   else
     102           0 :     offset = 0;
     103           0 :   TALER_MHD_parse_request_number (connection,
     104             :                                   "offset",
     105             :                                   &offset);
     106           0 :   ja = json_array ();
     107           0 :   GNUNET_break (NULL != ja);
     108           0 :   qs = TAH_plugin->select_historic_reserve_revenue (
     109           0 :     TAH_plugin->cls,
     110             :     limit,
     111             :     offset,
     112             :     &process_historic_reserve_summary,
     113             :     ja);
     114             : 
     115           0 :   if (0 > qs)
     116             :   {
     117           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     118           0 :     json_decref (ja);
     119           0 :     TALER_LOG_WARNING (
     120             :       "Failed to handle GET /historic-reserve-summary");
     121           0 :     return TALER_MHD_reply_with_error (
     122             :       connection,
     123             :       MHD_HTTP_INTERNAL_SERVER_ERROR,
     124             :       TALER_EC_GENERIC_DB_FETCH_FAILED,
     125             :       "select_historic_reserve_revenue");
     126             :   }
     127           0 :   return TALER_MHD_REPLY_JSON_PACK (
     128             :     connection,
     129             :     MHD_HTTP_OK,
     130             :     GNUNET_JSON_pack_array_steal (
     131             :       "historic-reserve-summary",
     132             :       ja));
     133             : }

Generated by: LCOV version 1.16