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-report-ID.c
20 : * @brief implementation of PATCH /private/reports/$REPORT_ID
21 : * @author Christian Grothoff
22 : */
23 : #include "platform.h"
24 : #include "taler-merchant-httpd_private-patch-report-ID.h"
25 : #include <taler/taler_json_lib.h>
26 : #include <taler/taler_dbevents.h>
27 :
28 : MHD_RESULT
29 0 : TMH_private_patch_report (const struct TMH_RequestHandler *rh,
30 : struct MHD_Connection *connection,
31 : struct TMH_HandlerContext *hc)
32 : {
33 0 : const char *report_id_str = hc->infix;
34 : unsigned long long report_id;
35 : const char *description;
36 : const char *program_section;
37 : const char *mime_type;
38 : const char *data_source;
39 : const char *target_address;
40 : struct GNUNET_TIME_Relative frequency;
41 : struct GNUNET_TIME_Relative frequency_shift;
42 : enum GNUNET_DB_QueryStatus qs;
43 : struct GNUNET_JSON_Specification spec[] = {
44 0 : GNUNET_JSON_spec_string ("description",
45 : &description),
46 0 : GNUNET_JSON_spec_string ("program_section",
47 : &program_section),
48 0 : GNUNET_JSON_spec_string ("mime_type",
49 : &mime_type),
50 0 : GNUNET_JSON_spec_string ("data_source",
51 : &data_source),
52 0 : GNUNET_JSON_spec_string ("target_address",
53 : &target_address),
54 0 : GNUNET_JSON_spec_relative_time ("report_frequency",
55 : &frequency),
56 0 : GNUNET_JSON_spec_relative_time ("report_frequency_shift",
57 : &frequency_shift),
58 0 : GNUNET_JSON_spec_end ()
59 : };
60 :
61 : (void) rh;
62 : {
63 : char dummy;
64 :
65 0 : if (1 != sscanf (report_id_str,
66 : "%llu%c",
67 : &report_id,
68 : &dummy))
69 : {
70 0 : GNUNET_break_op (0);
71 0 : return TALER_MHD_reply_with_error (connection,
72 : MHD_HTTP_BAD_REQUEST,
73 : TALER_EC_GENERIC_PARAMETER_MALFORMED,
74 : "report_id");
75 : }
76 : }
77 :
78 : {
79 : enum GNUNET_GenericReturnValue res;
80 :
81 0 : res = TALER_MHD_parse_json_data (connection,
82 0 : hc->request_body,
83 : spec);
84 0 : if (GNUNET_OK != res)
85 : {
86 0 : GNUNET_break_op (0);
87 : return (GNUNET_NO == res)
88 : ? MHD_YES
89 0 : : MHD_NO;
90 : }
91 : }
92 :
93 0 : qs = TMH_db->update_report (TMH_db->cls,
94 0 : hc->instance->settings.id,
95 : report_id,
96 : program_section,
97 : description,
98 : mime_type,
99 : data_source,
100 : target_address,
101 : frequency,
102 : frequency_shift);
103 0 : if (qs < 0)
104 : {
105 0 : GNUNET_break (0);
106 0 : return TALER_MHD_reply_with_error (connection,
107 : MHD_HTTP_INTERNAL_SERVER_ERROR,
108 : TALER_EC_GENERIC_DB_STORE_FAILED,
109 : "update_report");
110 : }
111 0 : if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
112 : {
113 0 : return TALER_MHD_reply_with_error (connection,
114 : MHD_HTTP_NOT_FOUND,
115 : TALER_EC_MERCHANT_GENERIC_REPORT_UNKNOWN,
116 : report_id_str);
117 : }
118 :
119 : /* FIXME-Optimization: Trigger MERCHANT_REPORT_UPDATE event inside of UPDATE transaction */
120 : {
121 0 : struct GNUNET_DB_EventHeaderP ev = {
122 0 : .size = htons (sizeof (ev)),
123 0 : .type = htons (TALER_DBEVENT_MERCHANT_REPORT_UPDATE)
124 : };
125 :
126 0 : TMH_db->event_notify (TMH_db->cls,
127 : &ev,
128 : NULL,
129 : 0);
130 : }
131 :
132 0 : return TALER_MHD_reply_static (connection,
133 : MHD_HTTP_NO_CONTENT,
134 : NULL,
135 : NULL,
136 : 0);
137 : }
|