taler-merchant-httpd_patch-private-groups-GROUP_ID.c (3803B)
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 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 "taler/platform.h" 24 #include "taler-merchant-httpd_patch-private-groups-GROUP_ID.h" 25 #include <taler/taler_json_lib.h> 26 27 28 MHD_RESULT 29 TMH_private_patch_group (const struct TMH_RequestHandler *rh, 30 struct MHD_Connection *connection, 31 struct TMH_HandlerContext *hc) 32 { 33 const char *group_id_str = hc->infix; 34 unsigned long long group_id; 35 const char *group_name; 36 const char *description; 37 enum GNUNET_DB_QueryStatus qs; 38 bool conflict; 39 char dummy; 40 struct GNUNET_JSON_Specification spec[] = { 41 GNUNET_JSON_spec_string ("group_name", 42 &group_name), 43 GNUNET_JSON_spec_string ("description", 44 &description), 45 GNUNET_JSON_spec_end () 46 }; 47 48 (void) rh; 49 if (1 != sscanf (group_id_str, 50 "%llu%c", 51 &group_id, 52 &dummy)) 53 { 54 GNUNET_break_op (0); 55 return TALER_MHD_reply_with_error (connection, 56 MHD_HTTP_BAD_REQUEST, 57 TALER_EC_GENERIC_PARAMETER_MALFORMED, 58 "group_id"); 59 } 60 61 { 62 enum GNUNET_GenericReturnValue res; 63 64 res = TALER_MHD_parse_json_data (connection, 65 hc->request_body, 66 spec); 67 if (GNUNET_OK != res) 68 { 69 GNUNET_break_op (0); 70 return (GNUNET_NO == res) 71 ? MHD_YES 72 : MHD_NO; 73 } 74 } 75 76 qs = TMH_db->update_product_group (TMH_db->cls, 77 hc->instance->settings.id, 78 (uint64_t) group_id, 79 group_name, 80 description, 81 &conflict); 82 83 if (qs < 0) 84 { 85 GNUNET_break (0); 86 return TALER_MHD_reply_with_error (connection, 87 MHD_HTTP_INTERNAL_SERVER_ERROR, 88 TALER_EC_GENERIC_DB_STORE_FAILED, 89 "update_product_group"); 90 } 91 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 92 { 93 return TALER_MHD_reply_with_error (connection, 94 MHD_HTTP_NOT_FOUND, 95 TALER_EC_MERCHANT_GENERIC_PRODUCT_GROUP_UNKNOWN, 96 group_id_str); 97 } 98 if (conflict) 99 { 100 return TALER_MHD_reply_with_error (connection, 101 MHD_HTTP_CONFLICT, 102 TALER_EC_MERCHANT_PRIVATE_PRODUCT_GROUP_CONFLICTING_NAME, 103 group_name); 104 } 105 return TALER_MHD_reply_static (connection, 106 MHD_HTTP_NO_CONTENT, 107 NULL, 108 NULL, 109 0); 110 }