taler-merchant-httpd_delete-private-categories-CATEGORY_ID.c (3510B)
1 /* 2 This file is part of TALER 3 (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 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 src/backend/taler-merchant-httpd_delete-private-categories-CATEGORY_ID.c 18 * @brief implement DELETE /private/categories/$ID 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "taler-merchant-httpd_delete-private-categories-CATEGORY_ID.h" 23 #include <taler/taler_json_lib.h> 24 #include "merchant-database/delete_category.h" 25 26 27 /** 28 * Handle a DELETE "/categories/$ID" request. 29 * 30 * @param rh context of the handler 31 * @param connection the MHD connection to handle 32 * @param[in,out] hc context with further information about the request 33 * @return MHD result code 34 */ 35 enum MHD_Result 36 TMH_private_delete_categories_ID ( 37 const struct TMH_RequestHandler *rh, 38 struct MHD_Connection *connection, 39 struct TMH_HandlerContext *hc) 40 { 41 struct TMH_MerchantInstance *mi = hc->instance; 42 enum GNUNET_DB_QueryStatus qs; 43 unsigned long long cnum; 44 char dummy; 45 46 (void) rh; 47 GNUNET_assert (NULL != mi); 48 GNUNET_assert (NULL != hc->infix); 49 if (1 != sscanf (hc->infix, 50 "%llu%c", 51 &cnum, 52 &dummy)) 53 { 54 GNUNET_break_op (0); 55 return TALER_MHD_reply_with_error (connection, 56 MHD_HTTP_BAD_REQUEST, 57 TALER_EC_GENERIC_PARAMETER_MALFORMED, 58 "category_id must be a number"); 59 } 60 qs = TALER_MERCHANTDB_delete_category (TMH_db, 61 mi->settings.id, 62 cnum); 63 switch (qs) 64 { 65 case GNUNET_DB_STATUS_HARD_ERROR: 66 return TALER_MHD_reply_with_error (connection, 67 MHD_HTTP_INTERNAL_SERVER_ERROR, 68 TALER_EC_GENERIC_DB_STORE_FAILED, 69 "delete_category"); 70 case GNUNET_DB_STATUS_SOFT_ERROR: 71 GNUNET_break (0); 72 return TALER_MHD_reply_with_error (connection, 73 MHD_HTTP_INTERNAL_SERVER_ERROR, 74 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 75 "delete_category"); 76 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 77 return TALER_MHD_reply_with_error (connection, 78 MHD_HTTP_NOT_FOUND, 79 TALER_EC_MERCHANT_GENERIC_CATEGORY_UNKNOWN, 80 hc->infix); 81 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 82 return TALER_MHD_reply_static (connection, 83 MHD_HTTP_NO_CONTENT, 84 NULL, 85 NULL, 86 0); 87 } 88 GNUNET_assert (0); 89 return MHD_NO; 90 } 91 92 93 /* end of taler-merchant-httpd_delete-private-categories-CATEGORY_ID.c */