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