donau-httpd_delete-charities-CHARITY_ID.c (2884B)
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 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 details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file donau-httpd_delete-charities-CHARITY_ID.c 18 * @brief Handle DELETE /charitys/$CHARITY_ID requests. 19 * @author Johannes Casaburi 20 */ 21 #include "donau_config.h" 22 #include <gnunet/gnunet_util_lib.h> 23 #include <gnunet/gnunet_json_lib.h> 24 #include <gnunet/gnunet_db_lib.h> 25 #include <jansson.h> 26 #include <microhttpd.h> 27 #include "taler/taler_dbevents.h" 28 #include "taler/taler_json_lib.h" 29 #include "taler/taler_mhd_lib.h" 30 #include "donau-httpd_delete-charities-CHARITY_ID.h" 31 #include "donau-database/do_charity_delete.h" 32 33 34 enum MHD_Result 35 DH_handler_delete_charities ( 36 struct DH_RequestContext *rc, 37 const char *const args[1]) 38 { 39 unsigned long long charity_id; 40 char dummy; 41 42 if ( (NULL == args[0]) || 43 (1 != sscanf (args[0], 44 "%llu%c", 45 &charity_id, 46 &dummy)) ) 47 { 48 GNUNET_break_op (0); 49 return TALER_MHD_reply_with_error (rc->connection, 50 MHD_HTTP_BAD_REQUEST, 51 TALER_EC_GENERIC_PARAMETER_MALFORMED, 52 "charity_id"); 53 } 54 55 { 56 enum GNUNET_DB_QueryStatus qs; 57 58 qs = DONAUDB_do_charity_delete (DH_context, 59 (uint64_t) charity_id); 60 switch (qs) 61 { 62 case GNUNET_DB_STATUS_HARD_ERROR: 63 case GNUNET_DB_STATUS_SOFT_ERROR: 64 GNUNET_break (0); 65 return TALER_MHD_reply_with_error (rc->connection, 66 MHD_HTTP_INTERNAL_SERVER_ERROR, 67 TALER_EC_GENERIC_DB_FETCH_FAILED, 68 NULL); 69 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 70 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 71 return TALER_MHD_reply_static ( 72 rc->connection, 73 MHD_HTTP_NO_CONTENT, 74 NULL, 75 NULL, 76 0); 77 } 78 return TALER_MHD_reply_with_error (rc->connection, 79 MHD_HTTP_INTERNAL_SERVER_ERROR, 80 TALER_EC_GENERIC_DB_FETCH_FAILED, 81 NULL); 82 } 83 } 84 85 86 /* end of donau-httpd_delete-charities-CHARITY_ID.c */