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]
name = "api"
version = "0.7.6"
version = "0.8.0-dev"
edition = "2018"
license = "AGPL-3.0-or-later"
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_obj = serde_json::Value::Object(Map::new());
let empty_vec = Vec::new();
let info_list = xml
let info_value = xml
.as_object()
.unwrap()
.get("VpMobil")
@ -99,14 +99,16 @@ pub async fn get_timetable(_conn: DbConn, url: String) -> Vec<Timetable> {
.get("ZusatzInfo")
.unwrap_or(&empty_obj)
.get("ZiZeile")
.unwrap_or(&empty_list)
.as_array()
.unwrap_or(&empty_vec);
.unwrap_or(&empty_list);
let mut info = String::new();
for item in info_list {
if info_value.is_array() {
for item in info_value.as_array().unwrap_or(&empty_vec) {
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 {
count: plan.len(),
courses,
@ -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_obj = serde_json::Value::Object(Map::new());
let empty_vec = Vec::new();
let info_list = xml
let info_value = xml
.as_object()
.unwrap()
.get("VpMobil")
@ -167,14 +169,16 @@ pub async fn get_class_timetable(_conn: DbConn, class: String, url: String) -> T
.get("ZusatzInfo")
.unwrap_or(&empty_obj)
.get("ZiZeile")
.unwrap_or(&empty_list)
.as_array()
.unwrap_or(&empty_vec);
.unwrap_or(&empty_list);
let mut info = String::new();
for item in info_list {
if info_value.is_array() {
for item in info_value.as_array().unwrap_or(&empty_vec) {
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 {
count: 0,
courses,