From c17576c5942847a6c76d12da32c2d7cc1329c56a Mon Sep 17 00:00:00 2001 From: Tyler Thompson Date: Thu, 18 Jul 2024 02:52:38 +0100 Subject: [PATCH] feat: add field rank_change_since_30_days in UserStatistics (#30) * feat: add field rank_change_since_30_days in UserStatistics * fix: update serde serializer with new field --- src/model/ranking.rs | 7 +++++++ src/model/user.rs | 3 +++ tests/serde.rs | 1 + 3 files changed, 11 insertions(+) diff --git a/src/model/ranking.rs b/src/model/ranking.rs index a48a022..82ca7e9 100644 --- a/src/model/ranking.rs +++ b/src/model/ranking.rs @@ -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; @@ -178,6 +179,7 @@ impl<'de> Visitor<'de> for UserStatsVisitor { } "pp" => pp = Some(map.next_value::>()?.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()?), @@ -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"))?; @@ -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, @@ -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, @@ -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)?; diff --git a/src/model/user.rs b/src/model/user.rs index 5d6b8d5..d30da2e 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -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, /// Number of replays watched by other users #[serde(rename = "replays_watched_by_others")] pub replays_watched: u32, diff --git a/tests/serde.rs b/tests/serde.rs index d49c72f..cac2548 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -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,