donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

donau-httpd_charity_delete.c (2760B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2024 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 Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file donau-httpd_charity_delete.c
     18  * @brief Handle DELETE /charitys/$CHARITY_ID requests.
     19  * @author Johannes Casaburi
     20  */
     21 #include "donau_config.h"
     22 #include <gnunet/gnunet_util_lib.h>
     23 #include <gnunet/gnunet_json_lib.h>
     24 #include <jansson.h>
     25 #include <microhttpd.h>
     26 #include "taler/taler_dbevents.h"
     27 #include "taler/taler_json_lib.h"
     28 #include "taler/taler_mhd_lib.h"
     29 #include "donau-httpd_charity.h"
     30 
     31 MHD_RESULT
     32 DH_handler_charity_delete (
     33   struct DH_RequestContext *rc,
     34   const char *const args[1])
     35 {
     36   unsigned long long charity_id;
     37   char dummy;
     38 
     39   if ( (NULL == args[0]) ||
     40        (1 != sscanf (args[0],
     41                      "%llu%c",
     42                      &charity_id,
     43                      &dummy)) )
     44   {
     45     GNUNET_break_op (0);
     46     return TALER_MHD_reply_with_error (rc->connection,
     47                                        MHD_HTTP_BAD_REQUEST,
     48                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     49                                        "charity_id");
     50   }
     51 
     52   {
     53     enum GNUNET_DB_QueryStatus qs;
     54 
     55     qs = DH_plugin->do_charity_delete (DH_plugin->cls,
     56                                        (uint64_t) charity_id);
     57     switch (qs)
     58     {
     59     case GNUNET_DB_STATUS_HARD_ERROR:
     60     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     61     case GNUNET_DB_STATUS_SOFT_ERROR:
     62       GNUNET_break (0);
     63       return TALER_MHD_reply_with_error (rc->connection,
     64                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
     65                                          TALER_EC_GENERIC_DB_FETCH_FAILED,
     66                                          NULL);
     67     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     68       return TALER_MHD_reply_static (
     69         rc->connection,
     70         MHD_HTTP_NO_CONTENT,
     71         NULL,
     72         NULL,
     73         0);
     74     }
     75     return TALER_MHD_reply_with_error (rc->connection,
     76                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     77                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     78                                        NULL);
     79   }
     80 }
     81 
     82 
     83 /* end of donau-httpd_charity_delete.c */