add faction id to rackets and fix territory wars

This commit is contained in:
TotallyNot 2023-11-22 00:01:25 +01:00
parent 9025f6a15e
commit f594a6b241
2 changed files with 18 additions and 2 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "torn-api"
version = "0.6.1"
version = "0.6.2"
edition = "2021"
authors = ["Pyrit [2111649]"]
license = "MIT"

View file

@ -21,7 +21,11 @@ pub enum TornSelection {
)]
Competition,
#[api(type = "HashMap<String, TerritoryWar>", field = "territorywars")]
#[api(
type = "HashMap<String, TerritoryWar>",
with = "decode_territory_wars",
field = "territorywars"
)]
TerritoryWars,
#[api(type = "HashMap<String, Racket>", field = "rackets")]
@ -57,6 +61,15 @@ pub enum Competition {
Unkown(String),
}
fn decode_territory_wars<'de, D>(deserializer: D) -> Result<HashMap<String, TerritoryWar>, 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<Option<Competition>, D::Error>
where
D: serde::Deserializer<'de>,
@ -140,6 +153,9 @@ pub struct Racket {
pub created: DateTime<Utc>,
#[serde(with = "chrono::serde::ts_seconds")]
pub changed: DateTime<Utc>,
#[serde(rename = "faction")]
pub faction_id: Option<i32>,
}
#[derive(Debug, Clone, Deserialize)]