aboutsummaryrefslogtreecommitdiff
path: root/src/clog.c
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2023-01-05 13:24:00 -0600
committerMichael McVady <femtonaut@gmail.com>2023-01-05 13:24:00 -0600
commite4ca47cc71bb64d724db3479406d381edc9661bc (patch)
treeee16e0ce93bd5960c004adc8ee5a21c601a3f2ae /src/clog.c
parentbd5a43e25909e43c6bc313cbfa2c5e4b9d1ebc70 (diff)
Add toy endpoint to insert data into sql
Diffstat (limited to 'src/clog.c')
-rw-r--r--src/clog.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/clog.c b/src/clog.c
index e15b1ee..edd9f2a 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -56,6 +56,8 @@ int posts(struct http_request *req);
int render_posts(struct http_request *req, const char *resource);
int render_posts_query(struct post_request *post_req);
+int toy(struct http_request *req);
+
static void process_md_output(const MD_CHAR *, MD_SIZE size, void *);
static int render_md(const char *, struct kore_buf *);
@@ -212,7 +214,7 @@ render_posts_query(struct post_request *post_req) {
err = validate_uuid(post_req->resource);
if (err == KORE_RESULT_ERROR) {
post_req->resp_status = HTTP_STATUS_NOT_FOUND;
- kore_log(LOG_ERR, "Invalid post id %s.", post_req->resource);
+ kore_log(LOG_ERR, "Invalid post UUID %s.", post_req->resource);
goto out;
}
}
@@ -267,6 +269,8 @@ render_posts_query(struct post_request *post_req) {
);
} else { // post_req->type == HTML
rows = kore_pgsql_ntuples(&sql);
+ // FIXME: add test for this:
+ // if (post_req->resource && rows == 0) {
if (rows == 0) {
post_req->resp_status = HTTP_STATUS_NOT_FOUND;
goto out;
@@ -311,6 +315,45 @@ out: ;
return KORE_RESULT_OK;
}
+int
+toy(struct http_request *req) {
+ int err = 0;
+
+ int status = HTTP_STATUS_OK;
+
+ struct kore_pgsql sql;
+
+ kore_pgsql_init(&sql);
+
+ err = kore_pgsql_setup(&sql, database, KORE_PGSQL_SYNC);
+ if (err == KORE_RESULT_ERROR) {
+ status = HTTP_STATUS_INTERNAL_ERROR;
+ kore_pgsql_logerror(&sql);
+ goto out;
+ }
+
+ // Query a post.
+ err = kore_pgsql_query(
+ &sql,
+ "INSERT INTO posts (id, title, body) VALUES ('00000000-0000-0000-0000-000000000000', 'title', 'body');"
+ // 'af5bbaec-8d2b-11ed-9bf3-db5637a87ac5'
+ );
+
+ if (err == KORE_RESULT_ERROR) {
+ status = HTTP_STATUS_INTERNAL_ERROR;
+ kore_pgsql_logerror(&sql);
+ goto out;
+ }
+
+out: ;
+
+ kore_pgsql_cleanup(&sql);
+
+ http_response(req, status, NULL, 0);
+
+ return KORE_RESULT_OK;
+}
+
static int
render_md(const char *in, struct kore_buf *out) {
int err = 0;