merchant

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

taler-merchant-httpd_patch-private-groups-GROUP_ID.c (3915B)


      1 /*
      2   This file is part of TALER
      3   (C) 2025 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 Affero General Public License for more
     12   details.
     13 
     14   You should have received a copy of the GNU Affero General Public License
     15   along with TALER; see the file COPYING.  If not, see
     16   <http://www.gnu.org/licenses/>
     17 */
     18 /**
     19  * @file src/backend/taler-merchant-httpd_patch-private-groups-GROUP_ID.c
     20  * @brief implementation of PATCH /private/groups/$GROUP_ID
     21  * @author Christian Grothoff
     22  */
     23 #include "platform.h"
     24 #include "taler-merchant-httpd_patch-private-groups-GROUP_ID.h"
     25 #include <taler/taler_json_lib.h>
     26 #include "merchant-database/update_product_group.h"
     27 
     28 
     29 enum MHD_Result
     30 TMH_private_patch_group (const struct TMH_RequestHandler *rh,
     31                          struct MHD_Connection *connection,
     32                          struct TMH_HandlerContext *hc)
     33 {
     34   const char *group_id_str = hc->infix;
     35   unsigned long long group_id;
     36   const char *group_name;
     37   const char *description;
     38   enum GNUNET_DB_QueryStatus qs;
     39   bool conflict;
     40   char dummy;
     41   struct GNUNET_JSON_Specification spec[] = {
     42     GNUNET_JSON_spec_string ("group_name",
     43                              &group_name),
     44     GNUNET_JSON_spec_string ("description",
     45                              &description),
     46     GNUNET_JSON_spec_end ()
     47   };
     48 
     49   (void) rh;
     50   if (1 != sscanf (group_id_str,
     51                    "%llu%c",
     52                    &group_id,
     53                    &dummy))
     54   {
     55     GNUNET_break_op (0);
     56     return TALER_MHD_reply_with_error (connection,
     57                                        MHD_HTTP_BAD_REQUEST,
     58                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     59                                        "group_id");
     60   }
     61 
     62   {
     63     enum GNUNET_GenericReturnValue res;
     64 
     65     res = TALER_MHD_parse_json_data (connection,
     66                                      hc->request_body,
     67                                      spec);
     68     if (GNUNET_OK != res)
     69     {
     70       GNUNET_break_op (0);
     71       return (GNUNET_NO == res)
     72              ? MHD_YES
     73              : MHD_NO;
     74     }
     75   }
     76 
     77   qs = TALER_MERCHANTDB_update_product_group (TMH_db,
     78                                               hc->instance->settings.id,
     79                                               (uint64_t) group_id,
     80                                               group_name,
     81                                               description,
     82                                               &conflict);
     83 
     84   if (qs < 0)
     85   {
     86     GNUNET_break (0);
     87     return TALER_MHD_reply_with_error (connection,
     88                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     89                                        TALER_EC_GENERIC_DB_STORE_FAILED,
     90                                        "update_product_group");
     91   }
     92   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     93   {
     94     return TALER_MHD_reply_with_error (connection,
     95                                        MHD_HTTP_NOT_FOUND,
     96                                        TALER_EC_MERCHANT_GENERIC_PRODUCT_GROUP_UNKNOWN,
     97                                        group_id_str);
     98   }
     99   if (conflict)
    100   {
    101     return TALER_MHD_reply_with_error (connection,
    102                                        MHD_HTTP_CONFLICT,
    103                                        TALER_EC_MERCHANT_PRIVATE_PRODUCT_GROUP_CONFLICTING_NAME,
    104                                        group_name);
    105   }
    106   return TALER_MHD_reply_static (connection,
    107                                  MHD_HTTP_NO_CONTENT,
    108                                  NULL,
    109                                  NULL,
    110                                  0);
    111 }