aboutsummaryrefslogtreecommitdiff
path: root/src/clog.c
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2024-03-24 18:37:24 -0500
committerMichael McVady <femtonaut@gmail.com>2024-03-24 18:37:24 -0500
commit98f09fa36fac0048ce2096cf3dddd7e7e1aa1b68 (patch)
tree887533a28630e65ba42af30138c0b59d06bcad45 /src/clog.c
parent63f6938ea309303351a6b69d1c9092fceb58b95c (diff)
Add delete
Diffstat (limited to 'src/clog.c')
-rw-r--r--src/clog.c77
1 files changed, 53 insertions, 24 deletions
diff --git a/src/clog.c b/src/clog.c
index 507b425..7687dff 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -70,6 +70,7 @@ int redirect(struct http_request *req);
int get_index(struct http_request *req);
int get_entry(struct http_request *req);
+int delete_entry(struct http_request *req);
int edit_entry(struct http_request *req);
int update_entry(struct http_request *req);
int get_new_entry_form(struct http_request *req);
@@ -329,6 +330,34 @@ out: ;
return KORE_RESULT_OK;
}
+int delete_entry(struct http_request *req) {
+ int err = 0;
+
+ char *id = NULL;
+
+ id = kore_strdup(req->path + strlen("/entries/"));
+ id[strlen(id) - strlen("/delete")] = '\0';
+
+ // Check for valid resource UUID
+ kore_log(LOG_DEBUG, "Resource id /entries/%s.", id);
+ err = validate_uuid(eq.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);
+
+ http_ok_resp(req, HTTP_STATUS_OK, content);
+
+out: ;
+ kore_free(id);
+
+ return KORE_RESULT_OK;
+}
+
+
int edit_entry(struct http_request *req) {
int err = 0;
@@ -622,36 +651,36 @@ out: ;
return err;
}
-// int sql_delete_entry(const char *id) {
-// int err = KORE_RESULT_OK;
+int sql_delete_entry(const char *id) {
+ int err = KORE_RESULT_OK;
-// struct kore_pgsql sql;
-// kore_pgsql_init(&sql);
+ struct kore_pgsql sql;
+ kore_pgsql_init(&sql);
-// err = kore_pgsql_setup(&sql, database, KORE_PGSQL_SYNC);
-// if (err == KORE_RESULT_ERROR) {
-// kore_pgsql_logerror(&sql);
-// goto out;
-// }
+ err = kore_pgsql_setup(&sql, database, KORE_PGSQL_SYNC);
+ if (err == KORE_RESULT_ERROR) {
+ kore_pgsql_logerror(&sql);
+ goto out;
+ }
-// err = kore_pgsql_query_params(
-// &sql,
-// q_delete_entry,
-// 0,
-// 1,
-// KORE_PGSQL_PARAM_TEXT(id)
-// );
-// if (err == KORE_RESULT_ERROR) {
-// kore_pgsql_logerror(&sql);
-// goto out;
-// }
+ err = kore_pgsql_query_params(
+ &sql,
+ q_delete_entry,
+ 0,
+ 1,
+ KORE_PGSQL_PARAM_TEXT(id)
+ );
+ if (err == KORE_RESULT_ERROR) {
+ kore_pgsql_logerror(&sql);
+ goto out;
+ }
-// out: ;
+out: ;
-// kore_pgsql_cleanup(&sql);
+ kore_pgsql_cleanup(&sql);
-// return err;
-// }
+ return err;
+}
static int render_md(const char *in, struct kore_buf *out) {
// Not a kore err.