Line data Source code
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 merchant/backend/taler-merchant-httpd_private-patch-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_private-patch-group-ID.h"
25 : #include <taler/taler_json_lib.h>
26 :
27 :
28 : MHD_RESULT
29 0 : TMH_private_patch_group (const struct TMH_RequestHandler *rh,
30 : struct MHD_Connection *connection,
31 : struct TMH_HandlerContext *hc)
32 : {
33 0 : 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 0 : GNUNET_JSON_spec_string ("group_name",
42 : &group_name),
43 0 : GNUNET_JSON_spec_string ("description",
44 : &description),
45 0 : GNUNET_JSON_spec_end ()
46 : };
47 :
48 : (void) rh;
49 0 : if (1 != sscanf (group_id_str,
50 : "%llu%c",
51 : &group_id,
52 : &dummy))
53 : {
54 0 : GNUNET_break_op (0);
55 0 : 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 0 : res = TALER_MHD_parse_json_data (connection,
65 0 : hc->request_body,
66 : spec);
67 0 : if (GNUNET_OK != res)
68 : {
69 0 : GNUNET_break_op (0);
70 : return (GNUNET_NO == res)
71 : ? MHD_YES
72 0 : : MHD_NO;
73 : }
74 : }
75 :
76 0 : qs = TMH_db->update_product_group (TMH_db->cls,
77 0 : hc->instance->settings.id,
78 : (uint64_t) group_id,
79 : group_name,
80 : description,
81 : &conflict);
82 :
83 0 : if (qs < 0)
84 : {
85 0 : GNUNET_break (0);
86 0 : 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 0 : if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
92 : {
93 0 : 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 0 : if (conflict)
99 : {
100 0 : 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 0 : return TALER_MHD_reply_static (connection,
106 : MHD_HTTP_NO_CONTENT,
107 : NULL,
108 : NULL,
109 : 0);
110 : }
|