merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_delete-private-products-PRODUCT_ID.c (3634B)


      1 /*
      2   This file is part of TALER
      3   (C) 2020, 2026 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 
     26 
     27 /**
     28  * Handle a DELETE "/products/$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_products_ID (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   bool force;
     43   bool not_found = false;
     44   bool locked = false;
     45 
     46   (void) rh;
     47   GNUNET_assert (NULL != mi);
     48   GNUNET_assert (NULL != hc->infix);
     49   TALER_MHD_parse_request_bool (connection,
     50                                 "force",
     51                                 false,
     52                                 &force);
     53   qs = TALER_MERCHANTDB_delete_product (TMH_db,
     54                                         mi->settings.id,
     55                                         hc->infix,
     56                                         force,
     57                                         &not_found,
     58                                         &locked);
     59   switch (qs)
     60   {
     61   case GNUNET_DB_STATUS_HARD_ERROR:
     62     return TALER_MHD_reply_with_error (
     63       connection,
     64       MHD_HTTP_INTERNAL_SERVER_ERROR,
     65       TALER_EC_GENERIC_DB_STORE_FAILED,
     66       "delete_product");
     67   case GNUNET_DB_STATUS_SOFT_ERROR:
     68     GNUNET_break (0);
     69     return TALER_MHD_reply_with_error (
     70       connection,
     71       MHD_HTTP_INTERNAL_SERVER_ERROR,
     72       TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
     73       "delete_product (soft)");
     74   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     75     GNUNET_break (0);
     76     return TALER_MHD_reply_with_error (
     77       connection,
     78       MHD_HTTP_INTERNAL_SERVER_ERROR,
     79       TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
     80       "delete_product (no result)");
     81   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     82     if (not_found)
     83       return TALER_MHD_reply_with_error (
     84         connection,
     85         MHD_HTTP_NOT_FOUND,
     86         TALER_EC_MERCHANT_GENERIC_PRODUCT_UNKNOWN,
     87         hc->infix);
     88     if (locked)
     89       return TALER_MHD_reply_with_error (
     90         connection,
     91         MHD_HTTP_CONFLICT,
     92         TALER_EC_MERCHANT_PRIVATE_DELETE_PRODUCTS_CONFLICTING_LOCK,
     93         hc->infix);
     94     return TALER_MHD_reply_static (connection,
     95                                    MHD_HTTP_NO_CONTENT,
     96                                    NULL,
     97                                    NULL,
     98                                    0);
     99   }
    100   GNUNET_break (0);
    101   return MHD_NO;
    102 }
    103 
    104 
    105 /* end of taler-merchant-httpd_delete-private-products-PRODUCT_ID.c */