fakebank_bank_get_accounts.c (2745B)
1 /* 2 This file is part of TALER 3 (C) 2016-2023 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 as 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, 11 but 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 * @file bank-lib/fakebank_bank_get_accounts.c 21 * @brief implements the Taler Bank API "GET /accounts/" handler 22 * @author Christian Grothoff <christian@grothoff.org> 23 */ 24 #include <pthread.h> 25 #include "taler/taler_fakebank_lib.h" 26 #include "taler/taler_bank_service.h" 27 #include "taler/taler_mhd_lib.h" 28 #include <gnunet/gnunet_mhd_compat.h> 29 #include "fakebank.h" 30 #include "fakebank_bank_get_accounts.h" 31 #include "fakebank_common_lookup.h" 32 33 /** 34 * Handle GET /accounts/${account_name} request of the Taler bank API. 35 * 36 * @param h the handle 37 * @param connection the connection 38 * @param account_name name of the account 39 * @return MHD result code 40 */ 41 MHD_RESULT 42 TALER_FAKEBANK_bank_get_accounts_ (struct TALER_FAKEBANK_Handle *h, 43 struct MHD_Connection *connection, 44 const char *account_name) 45 { 46 struct Account *acc; 47 48 GNUNET_assert (0 == 49 pthread_mutex_lock (&h->big_lock)); 50 acc = TALER_FAKEBANK_lookup_account_ (h, 51 account_name, 52 NULL); 53 if (NULL == acc) 54 { 55 GNUNET_assert (0 == 56 pthread_mutex_unlock (&h->big_lock)); 57 return TALER_MHD_reply_with_error (connection, 58 MHD_HTTP_NOT_FOUND, 59 TALER_EC_BANK_UNKNOWN_ACCOUNT, 60 account_name); 61 } 62 63 GNUNET_assert (0 == 64 pthread_mutex_unlock (&h->big_lock)); 65 return TALER_MHD_REPLY_JSON_PACK ( 66 connection, 67 MHD_HTTP_OK, 68 GNUNET_JSON_pack_string ("payto_uri", 69 acc->payto_uri), 70 GNUNET_JSON_pack_object_steal ( 71 "balance", 72 GNUNET_JSON_PACK ( 73 GNUNET_JSON_pack_string ("credit_debit_indicator", 74 acc->is_negative 75 ? "debit" 76 : "credit"), 77 TALER_JSON_pack_amount ("amount", 78 &acc->balance)))); 79 }