LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-delete-products-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 30 24
Test Date: 2025-10-31 14:20:14 Functions: 100.0 % 1 1

            Line data    Source code
       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 taler-merchant-httpd_private-delete-products-ID.c
      18              :  * @brief implement DELETE /products/$ID
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include "taler-merchant-httpd_private-delete-products-ID.h"
      23              : #include <taler/taler_json_lib.h>
      24              : 
      25              : 
      26              : /**
      27              :  * Handle a DELETE "/products/$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            6 : TMH_private_delete_products_ID (const struct TMH_RequestHandler *rh,
      36              :                                 struct MHD_Connection *connection,
      37              :                                 struct TMH_HandlerContext *hc)
      38              : {
      39            6 :   struct TMH_MerchantInstance *mi = hc->instance;
      40              :   enum GNUNET_DB_QueryStatus qs;
      41              : 
      42              :   (void) rh;
      43            6 :   GNUNET_assert (NULL != mi);
      44            6 :   GNUNET_assert (NULL != hc->infix);
      45            6 :   qs = TMH_db->delete_product (TMH_db->cls,
      46            6 :                                mi->settings.id,
      47            6 :                                hc->infix);
      48            6 :   switch (qs)
      49              :   {
      50            0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      51            0 :     return TALER_MHD_reply_with_error (connection,
      52              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      53              :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
      54              :                                        "delete_product");
      55            0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      56            0 :     GNUNET_break (0);
      57            0 :     return TALER_MHD_reply_with_error (connection,
      58              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      59              :                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      60              :                                        "delete_product (soft)");
      61            4 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      62              :     {
      63            4 :       size_t num_categories = 0;
      64            4 :       uint64_t *categories = NULL;
      65              : 
      66              :       /* check if deletion must have failed because of locks by
      67              :          checking if the product exists */
      68            4 :       qs = TMH_db->lookup_product (TMH_db->cls,
      69            4 :                                    mi->settings.id,
      70            4 :                                    hc->infix,
      71              :                                    NULL,
      72              :                                    &num_categories,
      73              :                                    &categories);
      74            4 :       if (GNUNET_DB_STATUS_HARD_ERROR == qs)
      75            2 :         return TALER_MHD_reply_with_error (connection,
      76              :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
      77              :                                            TALER_EC_GENERIC_DB_STORE_FAILED,
      78              :                                            "lookup_product");
      79            4 :       if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      80            2 :         return TALER_MHD_reply_with_error (connection,
      81              :                                            MHD_HTTP_NOT_FOUND,
      82              :                                            TALER_EC_MERCHANT_GENERIC_PRODUCT_UNKNOWN,
      83            2 :                                            hc->infix);
      84            2 :       GNUNET_free (categories);
      85              :     }
      86            2 :     return TALER_MHD_reply_with_error (
      87              :       connection,
      88              :       MHD_HTTP_CONFLICT,
      89              :       TALER_EC_MERCHANT_PRIVATE_DELETE_PRODUCTS_CONFLICTING_LOCK,
      90            2 :       hc->infix);
      91            2 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
      92            2 :     return TALER_MHD_reply_static (connection,
      93              :                                    MHD_HTTP_NO_CONTENT,
      94              :                                    NULL,
      95              :                                    NULL,
      96              :                                    0);
      97              :   }
      98            0 :   GNUNET_assert (0);
      99              :   return MHD_NO;
     100              : }
     101              : 
     102              : 
     103              : /* end of taler-merchant-httpd_private-delete-products-ID.c */
        

Generated by: LCOV version 2.0-1