summaryrefslogtreecommitdiffstats
path: root/src/json.c
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-06-29 17:19:15 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2021-07-01 09:20:46 +0200
commit7325a8629ebd718fe3546fc4105ffeeacd83232a (patch)
tree79084e6676389025885bb114bbd33f74bd59eb60 /src/json.c
parenta496da17ea042244ec97e50a96ed64e5bda6e000 (diff)
#915 Add POST /task/add method
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) { | ^~~~~~
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c24
1 files changed, 24 insertions, 0 deletions
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;