taler-merchant-httpd_get-private-pots-POT_ID.c (3409B)
1 /* 2 This file is part of TALER 3 (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 Affero 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 Affero General Public License for more 12 details. 13 14 You should have received a copy of the GNU Affero General Public License 15 along with TALER; see the file COPYING. If not, see 16 <http://www.gnu.org/licenses/> 17 */ 18 /** 19 * @file src/backend/taler-merchant-httpd_get-private-pots-POT_ID.c 20 * @brief implementation of GET /private/pots/$POT_ID 21 * @author Christian Grothoff 22 */ 23 #include "platform.h" 24 #include "taler-merchant-httpd_get-private-pots-POT_ID.h" 25 #include <taler/taler_json_lib.h> 26 #include "merchant-database/select_money_pot.h" 27 28 29 enum MHD_Result 30 TMH_private_get_pot (const struct TMH_RequestHandler *rh, 31 struct MHD_Connection *connection, 32 struct TMH_HandlerContext *hc) 33 { 34 const char *pot_id_str = hc->infix; 35 unsigned long long pot_id; 36 char *pot_name; 37 char *description; 38 size_t pot_total_len; 39 struct TALER_Amount *pot_totals; 40 enum GNUNET_DB_QueryStatus qs; 41 char dummy; 42 43 (void) rh; 44 if (1 != sscanf (pot_id_str, 45 "%llu%c", 46 &pot_id, 47 &dummy)) 48 { 49 GNUNET_break_op (0); 50 return TALER_MHD_reply_with_error (connection, 51 MHD_HTTP_BAD_REQUEST, 52 TALER_EC_GENERIC_PARAMETER_MALFORMED, 53 "pot_id"); 54 } 55 qs = TALER_MERCHANTDB_select_money_pot (TMH_db, 56 hc->instance->settings.id, 57 pot_id, 58 &pot_name, 59 &description, 60 &pot_total_len, 61 &pot_totals); 62 63 if (qs < 0) 64 { 65 GNUNET_break (0); 66 return TALER_MHD_reply_with_error (connection, 67 MHD_HTTP_INTERNAL_SERVER_ERROR, 68 TALER_EC_GENERIC_DB_FETCH_FAILED, 69 "select_money_pot"); 70 } 71 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 72 { 73 return TALER_MHD_reply_with_error ( 74 connection, 75 MHD_HTTP_NOT_FOUND, 76 TALER_EC_MERCHANT_GENERIC_MONEY_POT_UNKNOWN, 77 pot_id_str); 78 } 79 80 { 81 enum MHD_Result ret; 82 83 ret = TALER_MHD_REPLY_JSON_PACK ( 84 connection, 85 MHD_HTTP_OK, 86 GNUNET_JSON_pack_string ("description", 87 description), 88 GNUNET_JSON_pack_string ("pot_name", 89 pot_name), 90 (0 == pot_total_len) 91 ? GNUNET_JSON_pack_array_steal ("pot_totals", 92 json_array ()) 93 : TALER_JSON_pack_amount_array ("pot_totals", 94 pot_total_len, 95 pot_totals)); 96 GNUNET_free (pot_totals); 97 GNUNET_free (pot_name); 98 GNUNET_free (description); 99 return ret; 100 } 101 }