Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2021 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 General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file src/backend/taler-merchant-httpd_delete-private-transfers-TID.c
18 : * @brief implement DELETE /transfers/$ID
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include "taler-merchant-httpd_delete-private-transfers-TID.h"
23 : #include <taler/taler_json_lib.h>
24 : #include "merchant-database/get_exists_transfer.h"
25 : #include "merchant-database/delete_transfer.h"
26 :
27 :
28 : enum MHD_Result
29 4 : TMH_private_delete_transfers_ID (const struct TMH_RequestHandler *rh,
30 : struct MHD_Connection *connection,
31 : struct TMH_HandlerContext *hc)
32 : {
33 4 : struct TMH_MerchantInstance *mi = hc->instance;
34 : enum GNUNET_DB_QueryStatus qs;
35 : unsigned long long serial;
36 : char dummy;
37 :
38 : (void) rh;
39 4 : GNUNET_assert (NULL != mi);
40 4 : if (1 !=
41 4 : sscanf (hc->infix,
42 : "%llu%c",
43 : &serial,
44 : &dummy))
45 : {
46 0 : return TALER_MHD_reply_with_error (connection,
47 : MHD_HTTP_BAD_REQUEST,
48 : TALER_EC_GENERIC_PARAMETER_MALFORMED,
49 0 : hc->infix);
50 : }
51 4 : qs = TALER_MERCHANTDB_delete_transfer (TMH_db,
52 4 : mi->settings.id,
53 : serial);
54 4 : switch (qs)
55 : {
56 0 : case GNUNET_DB_STATUS_HARD_ERROR:
57 0 : return TALER_MHD_reply_with_error (connection,
58 : MHD_HTTP_INTERNAL_SERVER_ERROR,
59 : TALER_EC_GENERIC_DB_STORE_FAILED,
60 : "delete_transfer");
61 0 : case GNUNET_DB_STATUS_SOFT_ERROR:
62 0 : GNUNET_break (0);
63 0 : return TALER_MHD_reply_with_error (connection,
64 : MHD_HTTP_INTERNAL_SERVER_ERROR,
65 : TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
66 : "delete_transfer");
67 1 : case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
68 1 : qs = TALER_MERCHANTDB_get_exists_transfer (TMH_db,
69 1 : mi->settings.id,
70 : serial);
71 1 : if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
72 1 : return TALER_MHD_reply_with_error (connection,
73 : MHD_HTTP_NOT_FOUND,
74 : TALER_EC_MERCHANT_GENERIC_TRANSFER_UNKNOWN,
75 1 : hc->infix);
76 0 : return TALER_MHD_reply_with_error (connection,
77 : MHD_HTTP_CONFLICT,
78 : TALER_EC_MERCHANT_PRIVATE_DELETE_TRANSFERS_ALREADY_CONFIRMED,
79 0 : hc->infix);
80 3 : case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
81 3 : return TALER_MHD_reply_static (connection,
82 : MHD_HTTP_NO_CONTENT,
83 : NULL,
84 : NULL,
85 : 0);
86 : }
87 0 : GNUNET_assert (0);
88 : return MHD_NO;
89 : }
90 :
91 :
92 : /* end of taler-merchant-httpd_delete-private-transfers-TID.c */
|