Updated the task view and backend to handle more like a routine

This commit is contained in:
2026-03-08 22:10:46 -04:00
parent 4161ff9513
commit 9d3a277f45
14 changed files with 405 additions and 147 deletions

View File

@@ -1,5 +1,6 @@
// POST /api/tasks — Create a new task
// Body: {"user_id":1, "title":"...", "due_date":1741369200}
// Body: {"user_id":1, "title":"...", "due_date":1741369200, "period":0,
// "recurrence":0}
#include "cJSON.h"
#include "esp_http_server.h"
@@ -31,19 +32,26 @@ internal esp_err_t api_tasks_post_handler(httpd_req_t *req)
cJSON *user_id_item = cJSON_GetObjectItem(body, "user_id");
cJSON *title_item = cJSON_GetObjectItem(body, "title");
cJSON *due_date_item = cJSON_GetObjectItem(body, "due_date");
cJSON *period_item = cJSON_GetObjectItem(body, "period");
cJSON *recurrence_item = cJSON_GetObjectItem(body, "recurrence");
if (!cJSON_IsNumber(user_id_item) || !cJSON_IsString(title_item) ||
!cJSON_IsNumber(due_date_item))
if (!cJSON_IsNumber(user_id_item) || !cJSON_IsString(title_item))
{
cJSON_Delete(body);
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST,
"Missing user_id, title, or due_date");
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Missing user_id or title");
return ESP_FAIL;
}
int64 due_date =
cJSON_IsNumber(due_date_item) ? (int64)due_date_item->valuedouble : 0;
uint8 period = cJSON_IsNumber(period_item) ? (uint8)period_item->valueint
: (uint8)PERIOD_MORNING;
uint8 recurrence =
cJSON_IsNumber(recurrence_item) ? (uint8)recurrence_item->valueint : 0;
task_t *task =
add_task((uint8)user_id_item->valueint, title_item->valuestring,
(int64)due_date_item->valuedouble);
add_task((uint8)user_id_item->valueint, title_item->valuestring, due_date,
period, recurrence);
cJSON_Delete(body);
if (!task)
@@ -58,6 +66,8 @@ internal esp_err_t api_tasks_post_handler(httpd_req_t *req)
cJSON_AddNumberToObject(resp, "user_id", task->user_id);
cJSON_AddStringToObject(resp, "title", task->title);
cJSON_AddNumberToObject(resp, "due_date", (double)task->due_date);
cJSON_AddNumberToObject(resp, "period", task->period);
cJSON_AddNumberToObject(resp, "recurrence", task->recurrence);
cJSON_AddBoolToObject(resp, "completed", task->completed);
const char *json = cJSON_PrintUnformatted(resp);