feat(travel): Refactor route handling to use direction instead of destination
This commit is contained in:
@@ -28,7 +28,8 @@ void SettingHandler::load_settings() {
|
||||
}
|
||||
}
|
||||
|
||||
// Load routes
|
||||
// Load routes - clear existing settings as per new format
|
||||
routes_.clear();
|
||||
std::string routes_json = storage_->get(NVS_KEY_ROUTES);
|
||||
if (!routes_json.empty()) {
|
||||
routes_from_json(routes_json);
|
||||
@@ -65,7 +66,7 @@ void SettingHandler::add_route(const RoutePair& route) {
|
||||
}
|
||||
|
||||
routes_.push_back(route);
|
||||
ESP_LOGI(TAG, "Added route: %s -> %s", route.station_name.c_str(), route.dest_name.c_str());
|
||||
ESP_LOGI(TAG, "Added route: %s -> %s", route.station_name.c_str(), route.direction_name.c_str());
|
||||
}
|
||||
|
||||
void SettingHandler::remove_route(size_t index) {
|
||||
@@ -100,8 +101,8 @@ std::string SettingHandler::routes_to_json() const {
|
||||
cJSON_AddStringToObject(route_obj, "line_color", route.line_color.c_str());
|
||||
cJSON_AddStringToObject(route_obj, "station_code", route.station_code.c_str());
|
||||
cJSON_AddStringToObject(route_obj, "station_name", route.station_name.c_str());
|
||||
cJSON_AddStringToObject(route_obj, "dest_code", route.dest_code.c_str());
|
||||
cJSON_AddStringToObject(route_obj, "dest_name", route.dest_name.c_str());
|
||||
cJSON_AddStringToObject(route_obj, "direction", route.direction.c_str());
|
||||
cJSON_AddStringToObject(route_obj, "direction_name", route.direction_name.c_str());
|
||||
cJSON_AddItemToArray(root, route_obj);
|
||||
}
|
||||
|
||||
@@ -152,13 +153,13 @@ void SettingHandler::routes_from_json(const std::string& json) {
|
||||
item = cJSON_GetObjectItem(route_obj, "station_name");
|
||||
if (item && cJSON_IsString(item)) route.station_name = item->valuestring;
|
||||
|
||||
item = cJSON_GetObjectItem(route_obj, "dest_code");
|
||||
if (item && cJSON_IsString(item)) route.dest_code = item->valuestring;
|
||||
item = cJSON_GetObjectItem(route_obj, "direction");
|
||||
if (item && cJSON_IsString(item)) route.direction = item->valuestring;
|
||||
|
||||
item = cJSON_GetObjectItem(route_obj, "dest_name");
|
||||
if (item && cJSON_IsString(item)) route.dest_name = item->valuestring;
|
||||
item = cJSON_GetObjectItem(route_obj, "direction_name");
|
||||
if (item && cJSON_IsString(item)) route.direction_name = item->valuestring;
|
||||
|
||||
if (!route.line_code.empty() && !route.station_code.empty() && !route.dest_code.empty()) {
|
||||
if (!route.line_code.empty() && !route.station_code.empty() && !route.direction.empty()) {
|
||||
routes_.push_back(route);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user