merchant

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

taler-merchant-httpd_get-private-fountains.c (3837B)


      1 /*
      2   This file is part of TALER
      3   (C) 2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU Affero General Public License as
      7   published by the Free Software Foundation; either version 3,
      8   or (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not,
     17   see <http://www.gnu.org/licenses/>
     18 */
     19 
     20 /**
     21  * @file src/backend/taler-merchant-httpd_get-private-fountains.c
     22  * @brief implementing GET /private/fountains request handling
     23  * @author Bohdan Potuzhnyi
     24  */
     25 #include "platform.h"
     26 #include "taler-merchant-httpd_get-private-fountains.h"
     27 #include <taler/taler_json_lib.h>
     28 #include "merchant-database/iterate_fountains.h"
     29 
     30 
     31 /**
     32  * Add fountain details to the JSON array in @a cls.
     33  *
     34  * @param cls a `json_t *` JSON array to build
     35  * @param fountain_serial serial number used as pagination cursor
     36  * @param fountain_id public identifier of the fountain
     37  * @param description description of the fountain
     38  */
     39 static void
     40 add_fountain (void *cls,
     41               uint64_t fountain_serial,
     42               const char *fountain_id,
     43               const char *description)
     44 {
     45   json_t *pa = cls;
     46 
     47   GNUNET_assert (0 ==
     48                  json_array_append_new (
     49                    pa,
     50                    GNUNET_JSON_PACK (
     51                      GNUNET_JSON_pack_uint64 ("fountain_serial",
     52                                               fountain_serial),
     53                      GNUNET_JSON_pack_string ("fountain_id",
     54                                               fountain_id),
     55                      GNUNET_JSON_pack_string ("description",
     56                                               description))));
     57 }
     58 
     59 
     60 enum MHD_Result
     61 TMH_private_get_fountains (const struct TMH_RequestHandler *rh,
     62                            struct MHD_Connection *connection,
     63                            struct TMH_HandlerContext *hc)
     64 {
     65   struct TMH_MerchantInstance *mi = hc->instance;
     66   json_t *pa;
     67   enum GNUNET_DB_QueryStatus qs;
     68 
     69   int64_t limit = 20;
     70   uint64_t offset;
     71 
     72   TALER_MHD_parse_request_snumber (connection,
     73                                    "limit",
     74                                    &limit);
     75   offset = limit < 0 ? INT64_MAX : 0;
     76   TALER_MHD_parse_request_number (connection,
     77                                   "offset",
     78                                   &offset);
     79   if (offset > INT64_MAX)
     80     return TALER_MHD_reply_with_error (connection,
     81                                        MHD_HTTP_BAD_REQUEST,
     82                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     83                                        "offset");
     84   GNUNET_assert (NULL != mi);
     85   pa = json_array ();
     86   GNUNET_assert (NULL != pa);
     87   qs = TALER_MERCHANTDB_iterate_fountains (TMH_db,
     88                                            mi->settings.id,
     89                                            offset,
     90                                            limit,
     91                                            &add_fountain,
     92                                            pa);
     93   if (0 > qs)
     94   {
     95     GNUNET_break (0);
     96     json_decref (pa);
     97     return TALER_MHD_reply_with_error (connection,
     98                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     99                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    100                                        "iterate_fountains");
    101   }
    102   return TALER_MHD_REPLY_JSON_PACK (
    103     connection,
    104     MHD_HTTP_OK,
    105     GNUNET_JSON_pack_array_steal ("fountains",
    106                                   pa));
    107 }
    108 
    109 
    110 /* end of taler-merchant-httpd_get-private-fountains.c */