taler-merchant-httpd_post-private-groups.c (2951B)
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_post-private-groups.c 20 * @brief implementation of POST /private/groups 21 * @author Christian Grothoff 22 */ 23 #include "taler/platform.h" 24 #include "taler-merchant-httpd_post-private-groups.h" 25 #include <taler/taler_json_lib.h> 26 27 28 MHD_RESULT 29 TMH_private_post_groups (const struct TMH_RequestHandler *rh, 30 struct MHD_Connection *connection, 31 struct TMH_HandlerContext *hc) 32 { 33 const char *group_name; 34 const char *description; 35 enum GNUNET_DB_QueryStatus qs; 36 uint64_t group_id; 37 struct GNUNET_JSON_Specification spec[] = { 38 GNUNET_JSON_spec_string ("group_name", 39 &group_name), 40 GNUNET_JSON_spec_string ("description", 41 &description), 42 GNUNET_JSON_spec_end () 43 }; 44 45 (void) rh; 46 { 47 enum GNUNET_GenericReturnValue res; 48 49 res = TALER_MHD_parse_json_data (connection, 50 hc->request_body, 51 spec); 52 if (GNUNET_OK != res) 53 { 54 GNUNET_break_op (0); 55 return (GNUNET_NO == res) 56 ? MHD_YES 57 : MHD_NO; 58 } 59 } 60 61 qs = TMH_db->insert_product_group (TMH_db->cls, 62 hc->instance->settings.id, 63 group_name, 64 description, 65 &group_id); 66 if (qs < 0) 67 { 68 GNUNET_break (0); 69 return TALER_MHD_reply_with_error (connection, 70 MHD_HTTP_INTERNAL_SERVER_ERROR, 71 TALER_EC_GENERIC_DB_STORE_FAILED, 72 "insert_product_group"); 73 } 74 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 75 { 76 /* Zero will be returned on conflict */ 77 return TALER_MHD_reply_with_error (connection, 78 MHD_HTTP_CONFLICT, 79 TALER_EC_MERCHANT_PRIVATE_PRODUCT_GROUP_CONFLICTING_NAME, 80 group_name); 81 } 82 83 return TALER_MHD_REPLY_JSON_PACK ( 84 connection, 85 MHD_HTTP_OK, 86 GNUNET_JSON_pack_uint64 ("group_serial_id", 87 group_id)); 88 }