aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2024-03-24 18:44:56 -0500
committerMichael McVady <femtonaut@gmail.com>2024-03-24 18:44:56 -0500
commit15b65f02c7b9bfd691835cf0392e3b958626ed89 (patch)
tree07b59fbd3aff1f74dc29cb7506c07d9215888c2f
parent98f09fa36fac0048ce2096cf3dddd7e7e1aa1b68 (diff)
Add delete
-rw-r--r--src/clog.c16
1 files changed, 10 insertions, 6 deletions
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;