Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2022 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_get-private-templates-TEMPLATE_ID.c
18 : * @brief implement GET /templates/$ID
19 : * @author Priscilla HUANG
20 : */
21 : #include "platform.h"
22 : #include "taler-merchant-httpd_get-private-templates-TEMPLATE_ID.h"
23 : #include <taler/taler_json_lib.h>
24 : #include "merchant-database/get_template.h"
25 :
26 :
27 : enum MHD_Result
28 10 : TMH_private_get_templates_ID (
29 : const struct TMH_RequestHandler *rh,
30 : struct MHD_Connection *connection,
31 : struct TMH_HandlerContext *hc)
32 : {
33 10 : struct TMH_MerchantInstance *mi = hc->instance;
34 10 : struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
35 : enum GNUNET_DB_QueryStatus qs;
36 :
37 10 : GNUNET_assert (NULL != mi);
38 10 : qs = TALER_MERCHANTDB_get_template (TMH_db,
39 10 : mi->settings.id,
40 10 : hc->infix,
41 : &tp);
42 10 : if (0 > qs)
43 : {
44 0 : GNUNET_break (0);
45 0 : return TALER_MHD_reply_with_error (
46 : connection,
47 : MHD_HTTP_INTERNAL_SERVER_ERROR,
48 : TALER_EC_GENERIC_DB_FETCH_FAILED,
49 : "get_template");
50 : }
51 10 : if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
52 : {
53 2 : return TALER_MHD_reply_with_error (
54 : connection,
55 : MHD_HTTP_NOT_FOUND,
56 : TALER_EC_MERCHANT_GENERIC_TEMPLATE_UNKNOWN,
57 2 : hc->infix);
58 : }
59 : {
60 : enum MHD_Result ret;
61 :
62 8 : ret = TALER_MHD_REPLY_JSON_PACK (
63 : connection,
64 : MHD_HTTP_OK,
65 : GNUNET_JSON_pack_allow_null (
66 : GNUNET_JSON_pack_object_incref ("editable_defaults",
67 : tp.editable_defaults)),
68 : GNUNET_JSON_pack_string ("template_description",
69 : tp.template_description),
70 : GNUNET_JSON_pack_allow_null (
71 : GNUNET_JSON_pack_string ("otp_id",
72 : tp.otp_id)),
73 : GNUNET_JSON_pack_object_incref ("template_contract",
74 : tp.template_contract));
75 8 : TALER_MERCHANTDB_template_details_free (&tp);
76 8 : return ret;
77 : }
78 : }
79 :
80 :
81 : /* end of taler-merchant-httpd_get-private-templates-TEMPLATE_ID.c */
|