diff options
author | Michael McVady <femtonaut@gmail.com> | 2024-01-13 15:26:49 -0600 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2024-01-13 15:26:49 -0600 |
commit | 48ccb9949c85c7a9c9b896c3e50d66aefeaca701 (patch) | |
tree | ffe68f13cbad90eefadb25543cc838c9c9feefef /src/clog.c | |
parent | 193279017ac7da417f72c2073372204fd881ef70 (diff) |
Fold search into index
Diffstat (limited to 'src/clog.c')
-rw-r--r-- | src/clog.c | 85 |
1 files changed, 17 insertions, 68 deletions
@@ -212,15 +212,25 @@ int redirect(struct http_request *req) { } int get_index(struct http_request *req) { - struct entry_query eq; - + int err = 0; size_t i = 0; - + const char *query = NULL; + struct entry_query eq; struct kore_buf *content = NULL; content = kore_buf_alloc(0); - entry_query_init(&eq, NULL, NULL); + http_populate_get(req); + + err = http_argument_get_string(req, "query", &query); + if (err == KORE_RESULT_OK) { + kore_log(LOG_INFO, "query string: '%s'", query); + } + else { + query = NULL; + } + + entry_query_init(&eq, NULL, query); (void) sql_select(&eq); if (eq.status != QUERY_STATUS_OK) { @@ -231,6 +241,9 @@ int get_index(struct http_request *req) { // Write header. kore_buf_append(content, asset_header_html, asset_len_header_html); + // Write search form. + kore_buf_append(content, asset_search_html, asset_len_search_html); + // Write table header. kore_buf_append(content, asset_table_header_html, asset_len_table_header_html); @@ -439,70 +452,6 @@ out: ; return KORE_RESULT_OK; } - -int search_entries(struct http_request *req) { - int err = 0; - - size_t i = 0; - - char *query = NULL; - - struct entry_query eq; - - struct kore_buf *content = NULL; - - content = kore_buf_alloc(0); - - http_populate_get(req); - - err = http_argument_get_string(req, "query", &query); - if (err == KORE_RESULT_OK) { - kore_log(LOG_INFO, "query string: '%s'", query); - } - - entry_query_init(&eq, NULL, query); - - (void) sql_select(&eq); - if (eq.status != QUERY_STATUS_OK) { - http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); - goto out; - } - - // Write header. - kore_buf_append(content, asset_header_html, asset_len_header_html); - - // Write search form. - kore_buf_append(content, asset_search_html, asset_len_search_html); - - if (eq.num_entries > 0) { - // Write table header. - kore_buf_append(content, asset_table_header_html, asset_len_table_header_html); - - // Iterate over entries and render them. - for (i = 0; i < eq.num_entries; i++) { - // Append rendered MD entry. - kore_buf_appendf( - content, - (const char *) asset_table_row_html, - eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at - ); - } - - // Write table footer. - kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html); - } - - http_ok_resp(req, HTTP_STATUS_OK, content); - -out: ; - - entry_query_cleanup(&eq); - - kore_free(content); - - return KORE_RESULT_OK; -} - int sql_select(struct entry_query *eq) { int err = KORE_RESULT_OK; |