comparison scid/crud.h @ 33:1d0ddf9e6efd

misc: general documentation
author David Demelier <markand@malikania.fr>
date Thu, 04 Aug 2022 16:47:10 +0200
parents 081e1c258e64
children 71cd8447e3a4
comparison
equal deleted inserted replaced
32:081e1c258e64 33:1d0ddf9e6efd
17 */ 17 */
18 18
19 #ifndef SCID_CRUD_H 19 #ifndef SCID_CRUD_H
20 #define SCID_CRUD_H 20 #define SCID_CRUD_H
21 21
22 /**
23 * \file crud.h
24 * \brief Convenient helpers for API pages.
25 *
26 * This module uses the database to fetch or insert data and finally show the
27 * result as HTTP response.
28 *
29 * This module logs message with tag `crud`.
30 */
31
22 #include <jansson.h> 32 #include <jansson.h>
23 33
24 struct kreq; 34 struct kreq;
25 35
36 /**
37 * Decode the JSON input and insert them using the appropriate database
38 * function provided.
39 *
40 * \pre r != NULL
41 * \pre saver != NULL
42 * \pre topic != NULL
43 * \param r the request
44 * \param saver the function to save in database
45 * \param topic the log topic for diagnostic
46 */
26 void 47 void
27 crud_insert(struct kreq *, int (*)(json_t *), const char *); 48 crud_insert(struct kreq *r, int (*saver)(json_t *), const char *topic);
28 49
50 /**
51 * Convert the JSON provided value.
52 *
53 * For convenience, if the document is NULL (which happen if the database
54 * access failed) it will send a HTTP 500 error. Otherwise it is listed and
55 * free'd.
56 *
57 * \pre r != NULL
58 * \param r the request
59 * \param doc the document to send (maybe NULL)
60 * \warning The document will be destroyed using json_decref.
61 */
29 void 62 void
30 crud_list(struct kreq *, json_t *); 63 crud_list(struct kreq *r, json_t *doc);
31 64
32 #endif /* !SCID_CRUD_H */ 65 #endif /* !SCID_CRUD_H */