summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2020-05-06 18:12:28 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-06-02 12:32:36 +0200
commit4ddd66071883ebb175d5310c3ff206319073ecad (patch)
treed96023c85ce9e0e265c27d2e85b619a6d186ad99
parent9da3f878a2cd127a1beeeae97889d1d691125e89 (diff)
#942 add type to POST /schedule/create
Moreover, add og_task_schedule_create() function.
-rw-r--r--admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c
index 3e4091e1..dbc48ae8 100644
--- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c
+++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c
@@ -3953,10 +3953,33 @@ static int og_dbi_schedule_get_json(struct og_dbi *dbi, json_t *root,
static struct ev_loop *og_loop;
-static int og_cmd_schedule_create(json_t *element, struct og_msg_params *params)
+static int og_task_schedule_create(struct og_msg_params *params)
{
uint32_t schedule_id;
struct og_dbi *dbi;
+ int err;
+
+ dbi = og_dbi_open(&dbi_config);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
+ __func__, __LINE__);
+ return -1;
+ }
+
+ err = og_dbi_schedule_create(dbi, params, &schedule_id);
+ if (err < 0) {
+ og_dbi_close(dbi);
+ return -1;
+ }
+ og_schedule_create(schedule_id, atoi(params->task_id), &params->time);
+ og_schedule_refresh(og_loop);
+ og_dbi_close(dbi);
+
+ return 0;
+}
+
+static int og_cmd_schedule_create(json_t *element, struct og_msg_params *params)
+{
const char *key;
json_t *value;
int err;
@@ -3971,8 +3994,12 @@ static int og_cmd_schedule_create(json_t *element, struct og_msg_params *params)
} else if (!strcmp(key, "name")) {
err = og_json_parse_string(value, &params->name);
params->flags |= OG_REST_PARAM_NAME;
- } else if (!strcmp(key, "when"))
+ } else if (!strcmp(key, "when")) {
err = og_json_parse_time_params(value, params);
+ } else if (!strcmp(key, "type")) {
+ err = og_json_parse_string(value, &params->type);
+ params->flags |= OG_REST_PARAM_TYPE;
+ }
if (err < 0)
break;
@@ -3990,23 +4017,7 @@ static int og_cmd_schedule_create(json_t *element, struct og_msg_params *params)
OG_REST_PARAM_TIME_AM_PM))
return -1;
- dbi = og_dbi_open(&dbi_config);
- if (!dbi) {
- syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
- __func__, __LINE__);
- return -1;
- }
-
- err = og_dbi_schedule_create(dbi, params, &schedule_id);
- og_dbi_close(dbi);
-
- if (err < 0)
- return -1;
-
- og_schedule_create(schedule_id, atoi(params->task_id), &params->time);
- og_schedule_refresh(og_loop);
-
- return err;
+ return og_task_schedule_create(params);
}
static int og_cmd_schedule_update(json_t *element, struct og_msg_params *params)