mirror of
https://github.com/pcvolkmer/arsnova-client.git
synced 2025-04-19 19:16:51 +00:00
refactor: expect exactly four counter values for feedback
This commit is contained in:
parent
2796a6a608
commit
5d7a4ebfa0
@ -110,7 +110,7 @@ struct WsFeedbackBody {
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct WsFeedbackPayload {
|
struct WsFeedbackPayload {
|
||||||
values: Vec<u16>,
|
values: [u16; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WsFeedbackPayload {
|
impl WsFeedbackPayload {
|
||||||
@ -146,28 +146,13 @@ pub struct Feedback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Feedback {
|
impl Feedback {
|
||||||
pub fn from_values(values: Vec<u16>) -> Feedback {
|
pub fn from_values(values: [u16; 4]) -> Feedback {
|
||||||
let mut result = Feedback {
|
Feedback {
|
||||||
very_good: 0,
|
very_good: values[0],
|
||||||
good: 0,
|
good: values[1],
|
||||||
bad: 0,
|
bad: values[2],
|
||||||
very_bad: 0,
|
very_bad: values[3],
|
||||||
};
|
|
||||||
|
|
||||||
if !values.is_empty() {
|
|
||||||
result.very_good = values[0]
|
|
||||||
}
|
}
|
||||||
if values.len() >= 2 {
|
|
||||||
result.good = values[1]
|
|
||||||
}
|
|
||||||
if values.len() >= 3 {
|
|
||||||
result.bad = values[2]
|
|
||||||
}
|
|
||||||
if values.len() >= 4 {
|
|
||||||
result.very_bad = values[3]
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn count_votes(&self) -> u16 {
|
pub fn count_votes(&self) -> u16 {
|
||||||
@ -336,7 +321,7 @@ impl Client<LoggedIn> {
|
|||||||
{
|
{
|
||||||
Ok(res) => match res.status() {
|
Ok(res) => match res.status() {
|
||||||
StatusCode::OK => Ok(Feedback::from_values(
|
StatusCode::OK => Ok(Feedback::from_values(
|
||||||
res.json::<Vec<u16>>()
|
res.json::<[u16; 4]>()
|
||||||
.await
|
.await
|
||||||
.map_err(|err| ParserError(err.to_string()))?,
|
.map_err(|err| ParserError(err.to_string()))?,
|
||||||
)),
|
)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user