taler-merchant-httpd_private-get-accounts.c (2923B)
1 /* 2 This file is part of TALER 3 (C) 2022 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 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 taler-merchant-httpd_private-get-accounts.c 18 * @brief implement GET /accounts 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "taler-merchant-httpd_private-get-accounts.h" 23 #include <taler/taler_json_lib.h> 24 25 26 /** 27 * Add account details to our JSON array. 28 * 29 * @param cls a `json_t *` JSON array to build 30 * @param merchant_priv private key of the merchant instance 31 * @param ad details about the account 32 */ 33 static void 34 add_account (void *cls, 35 const struct TALER_MerchantPrivateKeyP *merchant_priv, 36 const struct TALER_MERCHANTDB_AccountDetails *ad) 37 { 38 json_t *pa = cls; 39 40 (void) merchant_priv; 41 GNUNET_assert (0 == 42 json_array_append_new ( 43 pa, 44 GNUNET_JSON_PACK ( 45 GNUNET_JSON_pack_bool ("active", 46 ad->active), 47 TALER_JSON_pack_full_payto ("payto_uri", 48 ad->payto_uri), 49 GNUNET_JSON_pack_data_auto ("h_wire", 50 &ad->h_wire)))); 51 } 52 53 54 MHD_RESULT 55 TMH_private_get_accounts (const struct TMH_RequestHandler *rh, 56 struct MHD_Connection *connection, 57 struct TMH_HandlerContext *hc) 58 { 59 json_t *pa; 60 enum GNUNET_DB_QueryStatus qs; 61 62 pa = json_array (); 63 GNUNET_assert (NULL != pa); 64 qs = TMH_db->select_accounts (TMH_db->cls, 65 hc->instance->settings.id, 66 &add_account, 67 pa); 68 if (0 > qs) 69 { 70 GNUNET_break (0); 71 json_decref (pa); 72 return TALER_MHD_reply_with_error (connection, 73 MHD_HTTP_INTERNAL_SERVER_ERROR, 74 TALER_EC_GENERIC_DB_FETCH_FAILED, 75 NULL); 76 } 77 return TALER_MHD_REPLY_JSON_PACK (connection, 78 MHD_HTTP_OK, 79 GNUNET_JSON_pack_array_steal ("accounts", 80 pa)); 81 } 82 83 84 /* end of taler-merchant-httpd_private-get-accounts.c */