LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-patch-categories-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 34 0
Test Date: 2025-11-06 19:31:41 Functions: 0.0 % 1 0

            Line data    Source code
       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
       6              :   it under the terms of the GNU Affero General Public License as
       7              :   published by the Free Software Foundation; either version 3,
       8              :   or (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful, but
      11              :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not,
      17              :   see <http://www.gnu.org/licenses/>
      18              : */
      19              : 
      20              : /**
      21              :  * @file taler-merchant-httpd_private-patch-categories-ID.c
      22              :  * @brief implementing PATCH /categories/$ID request handling
      23              :  * @author Christian Grothoff
      24              :  */
      25              : #include "platform.h"
      26              : #include "taler-merchant-httpd_private-patch-categories-ID.h"
      27              : #include "taler-merchant-httpd_helper.h"
      28              : #include <taler/taler_json_lib.h>
      29              : 
      30              : 
      31              : MHD_RESULT
      32            0 : TMH_private_patch_categories_ID (const struct TMH_RequestHandler *rh,
      33              :                                  struct MHD_Connection *connection,
      34              :                                  struct TMH_HandlerContext *hc)
      35              : {
      36            0 :   struct TMH_MerchantInstance *mi = hc->instance;
      37              :   unsigned long long cnum;
      38              :   char dummy;
      39              :   const char *category_name;
      40              :   const json_t *category_name_i18n;
      41              :   struct GNUNET_JSON_Specification spec[] = {
      42            0 :     GNUNET_JSON_spec_string ("name",
      43              :                              &category_name),
      44            0 :     GNUNET_JSON_spec_object_const ("name_i18n",
      45              :                                    &category_name_i18n),
      46            0 :     GNUNET_JSON_spec_end ()
      47              :   };
      48              :   enum GNUNET_DB_QueryStatus qs;
      49              : 
      50            0 :   GNUNET_assert (NULL != mi);
      51            0 :   GNUNET_assert (NULL != hc->infix);
      52            0 :   if (1 != sscanf (hc->infix,
      53              :                    "%llu%c",
      54              :                    &cnum,
      55              :                    &dummy))
      56              :   {
      57            0 :     GNUNET_break_op (0);
      58            0 :     return TALER_MHD_reply_with_error (connection,
      59              :                                        MHD_HTTP_BAD_REQUEST,
      60              :                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
      61              :                                        "category_id must be a number");
      62              :   }
      63              : 
      64              :   {
      65              :     enum GNUNET_GenericReturnValue res;
      66              : 
      67            0 :     res = TALER_MHD_parse_json_data (connection,
      68            0 :                                      hc->request_body,
      69              :                                      spec);
      70            0 :     if (GNUNET_OK != res)
      71              :       return (GNUNET_NO == res)
      72              :              ? MHD_YES
      73            0 :              : MHD_NO;
      74              :   }
      75              : 
      76            0 :   qs = TMH_db->update_category (TMH_db->cls,
      77            0 :                                 mi->settings.id,
      78              :                                 cnum,
      79              :                                 category_name,
      80              :                                 category_name_i18n);
      81              :   {
      82            0 :     MHD_RESULT ret = MHD_NO;
      83              : 
      84            0 :     switch (qs)
      85              :     {
      86            0 :     case GNUNET_DB_STATUS_HARD_ERROR:
      87            0 :       GNUNET_break (0);
      88            0 :       ret = TALER_MHD_reply_with_error (connection,
      89              :                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
      90              :                                         TALER_EC_GENERIC_DB_STORE_FAILED,
      91              :                                         "update_category");
      92            0 :       break;
      93            0 :     case GNUNET_DB_STATUS_SOFT_ERROR:
      94            0 :       GNUNET_break (0);
      95            0 :       ret = TALER_MHD_reply_with_error (connection,
      96              :                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
      97              :                                         TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      98              :                                         "unexpected serialization problem");
      99            0 :       break;
     100            0 :     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     101            0 :       ret = TALER_MHD_reply_with_error (connection,
     102              :                                         MHD_HTTP_NOT_FOUND,
     103              :                                         TALER_EC_MERCHANT_GENERIC_CATEGORY_UNKNOWN,
     104              :                                         category_name);
     105            0 :       break;
     106            0 :     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     107            0 :       ret = TALER_MHD_reply_static (connection,
     108              :                                     MHD_HTTP_NO_CONTENT,
     109              :                                     NULL,
     110              :                                     NULL,
     111              :                                     0);
     112            0 :       break;
     113              :     }
     114            0 :     GNUNET_JSON_parse_free (spec);
     115            0 :     return ret;
     116              :   }
     117              : }
     118              : 
     119              : 
     120              : /* end of taler-merchant-httpd_private-patch-categories-ID.c */
        

Generated by: LCOV version 2.0-1