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