taler-merchant-httpd_delete-private-products-PRODUCT_ID.c (4254B)
1 /* 2 This file is part of TALER 3 (C) 2020 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-products-PRODUCT_ID.c 18 * @brief implement DELETE /products/$ID 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "taler-merchant-httpd_delete-private-products-PRODUCT_ID.h" 23 #include <taler/taler_json_lib.h> 24 #include "merchant-database/delete_product.h" 25 #include "merchant-database/lookup_product.h" 26 27 28 /** 29 * Handle a DELETE "/products/$ID" request. 30 * 31 * @param rh context of the handler 32 * @param connection the MHD connection to handle 33 * @param[in,out] hc context with further information about the request 34 * @return MHD result code 35 */ 36 enum MHD_Result 37 TMH_private_delete_products_ID (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 44 (void) rh; 45 GNUNET_assert (NULL != mi); 46 GNUNET_assert (NULL != hc->infix); 47 qs = TALER_MERCHANTDB_delete_product (TMH_db, 48 mi->settings.id, 49 hc->infix); 50 switch (qs) 51 { 52 case GNUNET_DB_STATUS_HARD_ERROR: 53 return TALER_MHD_reply_with_error (connection, 54 MHD_HTTP_INTERNAL_SERVER_ERROR, 55 TALER_EC_GENERIC_DB_STORE_FAILED, 56 "delete_product"); 57 case GNUNET_DB_STATUS_SOFT_ERROR: 58 GNUNET_break (0); 59 return TALER_MHD_reply_with_error (connection, 60 MHD_HTTP_INTERNAL_SERVER_ERROR, 61 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 62 "delete_product (soft)"); 63 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 64 { 65 size_t num_categories = 0; 66 uint64_t *categories = NULL; 67 68 /* check if deletion must have failed because of locks by 69 checking if the product exists */ 70 qs = TALER_MERCHANTDB_lookup_product (TMH_db, 71 mi->settings.id, 72 hc->infix, 73 NULL, 74 &num_categories, 75 &categories); 76 if (GNUNET_DB_STATUS_HARD_ERROR == qs) 77 return TALER_MHD_reply_with_error (connection, 78 MHD_HTTP_INTERNAL_SERVER_ERROR, 79 TALER_EC_GENERIC_DB_STORE_FAILED, 80 "lookup_product"); 81 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 82 return TALER_MHD_reply_with_error (connection, 83 MHD_HTTP_NOT_FOUND, 84 TALER_EC_MERCHANT_GENERIC_PRODUCT_UNKNOWN, 85 hc->infix); 86 GNUNET_free (categories); 87 } 88 return TALER_MHD_reply_with_error ( 89 connection, 90 MHD_HTTP_CONFLICT, 91 TALER_EC_MERCHANT_PRIVATE_DELETE_PRODUCTS_CONFLICTING_LOCK, 92 hc->infix); 93 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 94 return TALER_MHD_reply_static (connection, 95 MHD_HTTP_NO_CONTENT, 96 NULL, 97 NULL, 98 0); 99 } 100 GNUNET_assert (0); 101 return MHD_NO; 102 } 103 104 105 /* end of taler-merchant-httpd_delete-private-products-PRODUCT_ID.c */