From f594a6b2418c8aa5c20b7a437f2b56754d064747 Mon Sep 17 00:00:00 2001 From: TotallyNot <44345987+TotallyNot@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:01:25 +0100 Subject: [PATCH] add faction id to rackets and fix territory wars --- torn-api/Cargo.toml | 2 +- torn-api/src/torn.rs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/torn-api/Cargo.toml b/torn-api/Cargo.toml index 881dc5e..5ed2222 100644 --- a/torn-api/Cargo.toml +++ b/torn-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "torn-api" -version = "0.6.1" +version = "0.6.2" edition = "2021" authors = ["Pyrit [2111649]"] license = "MIT" diff --git a/torn-api/src/torn.rs b/torn-api/src/torn.rs index 952d825..aa9137a 100644 --- a/torn-api/src/torn.rs +++ b/torn-api/src/torn.rs @@ -21,7 +21,11 @@ pub enum TornSelection { )] Competition, - #[api(type = "HashMap", field = "territorywars")] + #[api( + type = "HashMap", + with = "decode_territory_wars", + field = "territorywars" + )] TerritoryWars, #[api(type = "HashMap", field = "rackets")] @@ -57,6 +61,15 @@ pub enum Competition { Unkown(String), } +fn decode_territory_wars<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + let map: Option<_> = serde::Deserialize::deserialize(deserializer)?; + + Ok(map.unwrap_or_default()) +} + fn decode_competition<'de, D>(deserializer: D) -> Result, D::Error> where D: serde::Deserializer<'de>, @@ -140,6 +153,9 @@ pub struct Racket { pub created: DateTime, #[serde(with = "chrono::serde::ts_seconds")] pub changed: DateTime, + + #[serde(rename = "faction")] + pub faction_id: Option, } #[derive(Debug, Clone, Deserialize)]