From 15b65f02c7b9bfd691835cf0392e3b958626ed89 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Sun, 24 Mar 2024 18:44:56 -0500 Subject: Add delete --- src/clog.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/clog.c') diff --git a/src/clog.c b/src/clog.c index 7687dff..d226495 100644 --- a/src/clog.c +++ b/src/clog.c @@ -76,10 +76,9 @@ int update_entry(struct http_request *req); int get_new_entry_form(struct http_request *req); int save_new_entry(struct http_request *req); +int sql_delete(const char *id); int sql_select(struct entry_query *eq); int sql_update(const char *id, const char *title, const char *body); -// int sql_delete(const char *id); -// int sql_insert(const char *id, const char *title, const char *body); static void process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf); static int render_md(const char *in, struct kore_buf *out); @@ -340,16 +339,21 @@ int delete_entry(struct http_request *req) { // Check for valid resource UUID kore_log(LOG_DEBUG, "Resource id /entries/%s.", id); - err = validate_uuid(eq.id); + err = validate_uuid(id); if (err == KORE_RESULT_ERROR) { kore_log(LOG_ERR, "Invalid entry id %s.", id); http_err_resp(req, HTTP_STATUS_NOT_FOUND); goto out; } - int err = sql_delete_entry(id); + // TODO: handle HTTP 404 + err = sql_delete(id); + if (err == KORE_RESULT_ERROR) { + http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); + goto out; + } - http_ok_resp(req, HTTP_STATUS_OK, content); + http_err_resp(req, HTTP_STATUS_OK); out: ; kore_free(id); @@ -651,7 +655,7 @@ out: ; return err; } -int sql_delete_entry(const char *id) { +int sql_delete(const char *id) { int err = KORE_RESULT_OK; struct kore_pgsql sql; -- cgit v1.2.3