From 7325a8629ebd718fe3546fc4105ffeeacd83232a Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Tue, 29 Jun 2021 17:19:15 +0200 Subject: #915 Add POST /task/add method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the possibility to create a task with procedures and other tasks integrated as steps. Note: "steps" parameter is optional and "steps" array object order defines execution order. Request: POST /task/add { "center": "1", "name": "task", "description": "My task", "steps": [ { "procedure": 4 }, { "task": 1 }, { "procedure": 24 } ] } Response: 200 OK This commit also add task case to procedure's step processing. Otherwise, gcc prints the following warning: src/rest.c: In function ‘og_procedure_add_steps’: src/rest.c:4089:17: warning: enumeration value ‘OG_STEP_TASK’ not handled in switch [-Wswitch] 4089 | switch (step->type) { | ^~~~~~ --- src/json.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/json.c') diff --git a/src/json.c b/src/json.c index d693051..c7ae761 100644 --- a/src/json.c +++ b/src/json.c @@ -187,6 +187,28 @@ static int og_json_parse_procedure_call(json_t *element, int position, return err; } +static int og_json_parse_task_call(json_t *element, int position, + struct og_procedure *task) +{ + struct og_procedure_step *step; + uint32_t err = 0; + const char *key; + json_t *value; + + step = &task->steps[task->num_steps++]; + step->type = OG_STEP_TASK; + step->position = position; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "task")) + err = og_json_parse_uint64(value, &step->procedure.id); + else + return -1; + } + + return err; +} + int og_json_parse_procedure(json_t *element, struct og_procedure *proc) { unsigned int i; @@ -203,6 +225,8 @@ int og_json_parse_procedure(json_t *element, struct og_procedure *proc) err = og_json_parse_procedure_cmd(item, i, proc); else if (json_object_get(item, "procedure")) err = og_json_parse_procedure_call(item, i, proc); + else if (json_object_get(item, "task")) + err = og_json_parse_task_call(item, i, proc); else err = -1; -- cgit v1.2.3-18-g5258