mirror of
https://github.com/pcvolkmer/arsnova-client.git
synced 2025-04-19 19:16:51 +00:00
refactor: return default (zero) values if no statistics given
This commit is contained in:
parent
9b50fed24b
commit
96c90e7f0e
@ -187,6 +187,18 @@ pub struct SummaryResponse {
|
|||||||
pub stats: RoomStats,
|
pub stats: RoomStats,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for SummaryResponse {
|
||||||
|
fn default() -> Self {
|
||||||
|
SummaryResponse {
|
||||||
|
stats: RoomStats {
|
||||||
|
ack_comment_count: 0,
|
||||||
|
content_count: 0,
|
||||||
|
room_user_count: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
pub struct RoomStats {
|
pub struct RoomStats {
|
||||||
#[serde(rename = "contentCount")]
|
#[serde(rename = "contentCount")]
|
||||||
@ -464,7 +476,13 @@ impl Client<LoggedIn> {
|
|||||||
.json::<Vec<SummaryResponse>>()
|
.json::<Vec<SummaryResponse>>()
|
||||||
.await
|
.await
|
||||||
.map_err(|err| ParserError(err.to_string()))
|
.map_err(|err| ParserError(err.to_string()))
|
||||||
.map(|summary_response| summary_response.first().unwrap().stats.clone()))?,
|
.map(|summary_response| {
|
||||||
|
summary_response
|
||||||
|
.first()
|
||||||
|
.unwrap_or(&SummaryResponse::default())
|
||||||
|
.stats
|
||||||
|
.clone()
|
||||||
|
}))?,
|
||||||
StatusCode::NOT_FOUND => Err(RoomNotFoundError(short_id.into())),
|
StatusCode::NOT_FOUND => Err(RoomNotFoundError(short_id.into())),
|
||||||
_ => Err(ConnectionError),
|
_ => Err(ConnectionError),
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user