From a234a79828e2a1f995f8b33c6aa562581f450b03 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 28 Apr 2020 21:51:47 +0200 Subject: [PATCH] fix: add tags array to json even when empty --- models/relay_dbo.cc | 4 ++-- models/schedule_dbo.cc | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/models/relay_dbo.cc b/models/relay_dbo.cc index eabbc09..363a72c 100644 --- a/models/relay_dbo.cc +++ b/models/relay_dbo.cc @@ -173,10 +173,10 @@ relay_dbo::to_json() relay_json["active_schedule"] = this->active_schedule->to_json(); relay_json["schedules"] = schedules_json; + Json::Value tags_json(Json::arrayValue); int *tags_ids = junction_tag_dbo::get_tags_for_relay_id(this->id); if(tags_ids != nullptr) { - Json::Value tags_json(Json::arrayValue); int tags_count; for(tags_count = 0; tags_ids[tags_count] != 0; ++tags_count); @@ -188,8 +188,8 @@ relay_dbo::to_json() tags[i] = tag_dbo::get_tag(tags_ids[i]); tags_json[i] = tags[i]; } - relay_json["tags"] = tags_json; } + relay_json["tags"] = tags_json; return relay_json; } diff --git a/models/schedule_dbo.cc b/models/schedule_dbo.cc index eb4254c..b3e7ca9 100644 --- a/models/schedule_dbo.cc +++ b/models/schedule_dbo.cc @@ -153,11 +153,10 @@ schedule_dbo::to_json() schedule_json["id"] = id_str; schedule_json["periods"] = this->periods->to_json(); + Json::Value tags_json(Json::arrayValue); int *tags_ids = junction_tag_dbo::get_tags_for_schedule_id(this->id); if(tags_ids != nullptr) { - Json::Value tags_json(Json::arrayValue); - int tags_count; for(tags_count = 0; tags_ids[tags_count] != 0; ++tags_count); @@ -168,8 +167,8 @@ schedule_dbo::to_json() tags[i] = tag_dbo::get_tag(tags_ids[i]); tags_json[i] = tags[i]; } - schedule_json["tags"] = tags_json; } + schedule_json["tags"] = tags_json; return schedule_json; }