fixed bug with indiware one-line ZusatzInfo

bumped version to 0.8.0-dev
This commit is contained in:
Denys Konovalov 2021-12-14 16:04:07 +01:00
parent 9a31bf8221
commit 5114be327a
2 changed files with 19 additions and 15 deletions

@ -1,6 +1,6 @@
[package] [package]
name = "api" name = "api"
version = "0.7.6" version = "0.8.0-dev"
edition = "2018" edition = "2018"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
authors = ["Denys Konovalov <denys.konovalov@protonmail.com>"] authors = ["Denys Konovalov <denys.konovalov@protonmail.com>"]

@ -91,7 +91,7 @@ pub async fn get_timetable(_conn: DbConn, url: String) -> Vec<Timetable> {
let empty_list = serde_json::Value::Array(vec![]); let empty_list = serde_json::Value::Array(vec![]);
let empty_obj = serde_json::Value::Object(Map::new()); let empty_obj = serde_json::Value::Object(Map::new());
let empty_vec = Vec::new(); let empty_vec = Vec::new();
let info_list = xml let info_value = xml
.as_object() .as_object()
.unwrap() .unwrap()
.get("VpMobil") .get("VpMobil")
@ -99,13 +99,15 @@ pub async fn get_timetable(_conn: DbConn, url: String) -> Vec<Timetable> {
.get("ZusatzInfo") .get("ZusatzInfo")
.unwrap_or(&empty_obj) .unwrap_or(&empty_obj)
.get("ZiZeile") .get("ZiZeile")
.unwrap_or(&empty_list) .unwrap_or(&empty_list);
.as_array()
.unwrap_or(&empty_vec);
let mut info = String::new(); let mut info = String::new();
for item in info_list { if info_value.is_array() {
info.push_str(item.as_str().unwrap_or("\r\n")); for item in info_value.as_array().unwrap_or(&empty_vec) {
info.push_str("\r\n"); info.push_str(item.as_str().unwrap_or("\r\n"));
info.push_str("\r\n");
}
} else if info_value.is_string() {
info.push_str(info_value.as_str().unwrap_or(""));
} }
let response = TimetableData { let response = TimetableData {
count: plan.len(), count: plan.len(),
@ -159,7 +161,7 @@ pub async fn get_class_timetable(_conn: DbConn, class: String, url: String) -> T
let empty_list = serde_json::Value::Array(vec![]); let empty_list = serde_json::Value::Array(vec![]);
let empty_obj = serde_json::Value::Object(Map::new()); let empty_obj = serde_json::Value::Object(Map::new());
let empty_vec = Vec::new(); let empty_vec = Vec::new();
let info_list = xml let info_value = xml
.as_object() .as_object()
.unwrap() .unwrap()
.get("VpMobil") .get("VpMobil")
@ -167,13 +169,15 @@ pub async fn get_class_timetable(_conn: DbConn, class: String, url: String) -> T
.get("ZusatzInfo") .get("ZusatzInfo")
.unwrap_or(&empty_obj) .unwrap_or(&empty_obj)
.get("ZiZeile") .get("ZiZeile")
.unwrap_or(&empty_list) .unwrap_or(&empty_list);
.as_array()
.unwrap_or(&empty_vec);
let mut info = String::new(); let mut info = String::new();
for item in info_list { if info_value.is_array() {
info.push_str(item.as_str().unwrap_or("\r\n")); for item in info_value.as_array().unwrap_or(&empty_vec) {
info.push_str("\r\n"); info.push_str(item.as_str().unwrap_or("\r\n"));
info.push_str("\r\n");
}
} else if info_value.is_string() {
info.push_str(info_value.as_str().unwrap_or(""));
} }
let mut response = TimetableData { let mut response = TimetableData {
count: 0, count: 0,