Skip to content

Commit

Permalink
feat: add field rank_change_since_30_days in UserStatistics (#30)
Browse files Browse the repository at this point in the history
* feat: add field rank_change_since_30_days in UserStatistics

* fix: update serde serializer with new field
  • Loading branch information
damaredayo authored Jul 18, 2024
1 parent 9e76879 commit c17576c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/model/ranking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl<'de> Visitor<'de> for UserStatsVisitor {
let mut playtime = None;
let mut pp = None;
let mut ranked_score = None;
let mut rank_change_since_30_days = None;
let mut replays_watched = None;
let mut total_hits = None;
let mut total_score = None;
Expand All @@ -178,6 +179,7 @@ impl<'de> Visitor<'de> for UserStatsVisitor {
}
"pp" => pp = Some(map.next_value::<Option<f32>>()?.unwrap_or_default()),
"ranked_score" => ranked_score = Some(map.next_value()?),
"rank_change_since_30_days" => rank_change_since_30_days = Some(map.next_value()?),
"replays_watched_by_others" => replays_watched = Some(map.next_value()?),
"total_hits" => total_hits = Some(map.next_value()?),
"total_score" => total_score = Some(map.next_value()?),
Expand All @@ -201,6 +203,8 @@ impl<'de> Visitor<'de> for UserStatsVisitor {
let playtime = playtime.ok_or_else(|| Error::missing_field("play_time"))?;
let pp = pp.ok_or_else(|| Error::missing_field("pp"))?;
let ranked_score = ranked_score.ok_or_else(|| Error::missing_field("ranked_score"))?;
let rank_change_since_30_days = rank_change_since_30_days
.ok_or_else(|| Error::missing_field("rank_change_since_30_days"))?;
let replays_watched =
replays_watched.ok_or_else(|| Error::missing_field("replays_watched_by_others"))?;
let total_hits = total_hits.ok_or_else(|| Error::missing_field("total_hits"))?;
Expand All @@ -223,6 +227,7 @@ impl<'de> Visitor<'de> for UserStatsVisitor {
playtime,
pp,
ranked_score,
rank_change_since_30_days,
replays_watched,
total_hits,
total_score,
Expand Down Expand Up @@ -267,6 +272,7 @@ impl<'u> serde::Serialize for UserCompactBorrowed<'u> {
playtime,
pp,
ranked_score,
rank_change_since_30_days,
replays_watched,
total_hits,
total_score,
Expand All @@ -293,6 +299,7 @@ impl<'u> serde::Serialize for UserCompactBorrowed<'u> {
s.serialize_field("play_time", playtime)?;
s.serialize_field("pp", pp)?;
s.serialize_field("ranked_score", ranked_score)?;
s.serialize_field("rank_change_since_30_days", rank_change_since_30_days)?;
s.serialize_field("replays_watched_by_others", replays_watched)?;
s.serialize_field("total_hits", total_hits)?;
s.serialize_field("total_score", total_score)?;
Expand Down
3 changes: 3 additions & 0 deletions src/model/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ pub struct UserStatistics {
pub pp: f32,
/// Current ranked score
pub ranked_score: u64,
/// Rank change in the last 30 days
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rank_change_since_30_days: Option<i32>,
/// Number of replays watched by other users
#[serde(rename = "replays_watched_by_others")]
pub replays_watched: u32,
Expand Down
1 change: 1 addition & 0 deletions tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ mod types {
playtime: 10_000_000,
pp: 9876.54,
ranked_score: 111_222_333_444,
rank_change_since_30_days: Some(42),
replays_watched: 123,
total_hits: 123_456_789,
total_score: 111_222_333_444_555,
Expand Down

0 comments on commit c17576c

Please sign in to comment.