LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-products-ID.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 18 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2019, 2020, 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 taler-merchant-httpd_private-get-products-ID.c
      18             :  * @brief implement GET /products/$ID
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler-merchant-httpd_private-get-products-ID.h"
      23             : #include <taler/taler_json_lib.h>
      24             : 
      25             : 
      26             : /**
      27             :  * Handle a GET "/products/$ID" request.
      28             :  *
      29             :  * @param rh context of the handler
      30             :  * @param connection the MHD connection to handle
      31             :  * @param[in,out] hc context with further information about the request
      32             :  * @return MHD result code
      33             :  */
      34             : MHD_RESULT
      35           0 : TMH_private_get_products_ID (const struct TMH_RequestHandler *rh,
      36             :                              struct MHD_Connection *connection,
      37             :                              struct TMH_HandlerContext *hc)
      38             : {
      39           0 :   struct TMH_MerchantInstance *mi = hc->instance;
      40           0 :   struct TALER_MERCHANTDB_ProductDetails pd = { 0 };
      41             :   enum GNUNET_DB_QueryStatus qs;
      42             : 
      43           0 :   GNUNET_assert (NULL != mi);
      44           0 :   qs = TMH_db->lookup_product (TMH_db->cls,
      45           0 :                                mi->settings.id,
      46           0 :                                hc->infix,
      47             :                                &pd);
      48           0 :   if (0 > qs)
      49             :   {
      50           0 :     GNUNET_break (0);
      51           0 :     return TALER_MHD_reply_with_error (connection,
      52             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      53             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      54             :                                        "lookup_product");
      55             :   }
      56           0 :   if (0 == qs)
      57             :   {
      58           0 :     return TALER_MHD_reply_with_error (connection,
      59             :                                        MHD_HTTP_NOT_FOUND,
      60             :                                        TALER_EC_MERCHANT_GENERIC_PRODUCT_UNKNOWN,
      61           0 :                                        hc->infix);
      62             :   }
      63             :   {
      64             :     MHD_RESULT ret;
      65             : 
      66           0 :     ret = TALER_MHD_REPLY_JSON_PACK (
      67             :       connection,
      68             :       MHD_HTTP_OK,
      69             :       GNUNET_JSON_pack_string ("description",
      70             :                                pd.description),
      71             :       GNUNET_JSON_pack_object_steal ("description_i18n",
      72             :                                      pd.description_i18n),
      73             :       GNUNET_JSON_pack_string ("unit",
      74             :                                pd.unit),
      75             :       TALER_JSON_pack_amount ("price",
      76             :                               &pd.price),
      77             :       GNUNET_JSON_pack_string ("image",
      78             :                                pd.image),
      79             :       GNUNET_JSON_pack_array_steal ("taxes",
      80             :                                     pd.taxes),
      81             :       GNUNET_JSON_pack_int64 ("total_stock",
      82             :                               (INT64_MAX == pd.total_stock)
      83             :                               ? -1LL
      84             :                               : pd.total_stock),
      85             :       GNUNET_JSON_pack_uint64 ("total_sold",
      86             :                                pd.total_sold),
      87             :       GNUNET_JSON_pack_uint64 ("total_lost",
      88             :                                pd.total_lost),
      89             :       GNUNET_JSON_pack_object_steal ("address",
      90             :                                      pd.address),
      91             :       GNUNET_JSON_pack_allow_null (
      92             :         GNUNET_JSON_pack_timestamp ("next_restock",
      93             :                                     (pd.next_restock))),
      94             :       GNUNET_JSON_pack_uint64 ("minimum_age",
      95             :                                pd.minimum_age));
      96           0 :     GNUNET_free (pd.description);
      97           0 :     GNUNET_free (pd.image);
      98           0 :     GNUNET_free (pd.unit);
      99           0 :     return ret;
     100             :   }
     101             : }
     102             : 
     103             : 
     104             : /* end of taler-merchant-httpd_private-get-products-ID.c */

Generated by: LCOV version 1.14