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