add: tests

add: schedule endpoints
This commit is contained in:
Tobias Reisinger 2020-05-05 22:29:04 +02:00
parent 6d828fcffc
commit b5a8523ae0
14 changed files with 468 additions and 42 deletions

View file

@ -96,7 +96,7 @@ schedule_db_select(sqlite3_stmt *stmt)
}
else
{
LOG_ERROR("srror selecting schedules from database: %s\n", sqlite3_errstr(s));
LOG_ERROR("error selecting schedules from database: %s\n", sqlite3_errstr(s));
break;
}
}
@ -139,6 +139,47 @@ schedule_save(schedule_t *schedule)
return result;
}
int
schedule_remove(schedule_t *schedule)
{
sqlite3_stmt *stmt;
if(!schedule->id)
{
return 0;
}
sqlite3_prepare_v2(global_database, "DELETE FROM schedules WHERE id=?1;", -1, &stmt, NULL);
sqlite3_bind_int(stmt, 1, schedule->id);
int rc = sqlite3_step(stmt);
sqlite3_finalize(stmt);
return rc != SQLITE_DONE;
}
int
schedule_is_protected(schedule_t *schedule)
{
uuid_t tmp_uuid;
memset(tmp_uuid, 0, sizeof(uuid_t));
memcpy(tmp_uuid, "off", 3);
if(uuid_compare(schedule->uid, tmp_uuid) == 0)
{
return 1;
}
memset(tmp_uuid, 0, sizeof(uuid_t));
memcpy(tmp_uuid, "on", 2);
if(uuid_compare(schedule->uid, tmp_uuid) == 0)
{
return 1;
}
return 0;
}
void
schedule_free(schedule_t *schedule)
{
@ -262,10 +303,41 @@ schedule_to_json(schedule_t *schedule)
}
cJSON_AddItemToObject(json, "tags", json_tags);
return json;
}
schedule_t*
schedule_get_by_id(int id)
{
sqlite3_stmt *stmt;
sqlite3_prepare_v2(global_database, "SELECT * FROM schedules WHERE id = ?1;", -1, &stmt, NULL);
sqlite3_bind_int(stmt, 1, id);
schedule_t **sql_result = schedule_db_select(stmt);
schedule_t *result = sql_result[0];
free(sql_result);
return result;
}
schedule_t*
schedule_get_by_uid(uuid_t uid)
{
sqlite3_stmt *stmt;
sqlite3_prepare_v2(global_database, "SELECT * FROM schedules WHERE uid = ?1;", -1, &stmt, NULL);
sqlite3_bind_blob(stmt, 1, uid, sizeof(uuid_t), SQLITE_STATIC);
schedule_t **sql_result = schedule_db_select(stmt);
schedule_t *result = sql_result[0];
free(sql_result);
return result;
}
schedule_t**
schedule_get_all()
{