LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-products.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 11 14 78.6 %
Date: 2021-08-30 06:54:17 Functions: 2 2 100.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.c
      18             :  * @brief implement GET /products
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler-merchant-httpd_private-get-products.h"
      23             : 
      24             : 
      25             : /**
      26             :  * Add product details to our JSON array.
      27             :  *
      28             :  * @param cls a `json_t *` JSON array to build
      29             :  * @param product_id ID of the product
      30             :  */
      31             : static void
      32           1 : add_product (void *cls,
      33             :              const char *product_id)
      34             : {
      35           1 :   json_t *pa = cls;
      36             : 
      37           1 :   GNUNET_assert (0 ==
      38             :                  json_array_append_new (
      39             :                    pa,
      40             :                    GNUNET_JSON_PACK (
      41             :                      GNUNET_JSON_pack_string ("product_id",
      42             :                                               product_id))));
      43           1 : }
      44             : 
      45             : 
      46             : /**
      47             :  * Handle a GET "/private/products" request.
      48             :  *
      49             :  * @param rh context of the handler
      50             :  * @param connection the MHD connection to handle
      51             :  * @param[in,out] hc context with further information about the request
      52             :  * @return MHD result code
      53             :  */
      54             : MHD_RESULT
      55           5 : TMH_private_get_products (const struct TMH_RequestHandler *rh,
      56             :                           struct MHD_Connection *connection,
      57             :                           struct TMH_HandlerContext *hc)
      58             : {
      59             :   json_t *pa;
      60             :   enum GNUNET_DB_QueryStatus qs;
      61             : 
      62           5 :   pa = json_array ();
      63           5 :   GNUNET_assert (NULL != pa);
      64           5 :   qs = TMH_db->lookup_products (TMH_db->cls,
      65           5 :                                 hc->instance->settings.id,
      66             :                                 &add_product,
      67             :                                 pa);
      68           5 :   if (0 > qs)
      69             :   {
      70           0 :     GNUNET_break (0);
      71           0 :     json_decref (pa);
      72           0 :     return TALER_MHD_reply_with_error (connection,
      73             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      74             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      75             :                                        NULL);
      76             :   }
      77           5 :   return TALER_MHD_REPLY_JSON_PACK (connection,
      78             :                                     MHD_HTTP_OK,
      79             :                                     GNUNET_JSON_pack_array_steal ("products",
      80             :                                                                   pa));
      81             : }
      82             : 
      83             : 
      84             : /* end of taler-merchant-httpd_private-get-products.c */

Generated by: LCOV version 1.14