added user->attacks
This commit is contained in:
parent
fe5d34968d
commit
3e3909bb6c
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "torn-api"
|
name = "torn-api"
|
||||||
version = "0.5.17"
|
version = "0.5.18"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Pyrit [2111649]"]
|
authors = ["Pyrit [2111649]"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -56,3 +56,108 @@ pub struct Territory {
|
||||||
#[serde(deserialize_with = "de_util::string_or_decimal")]
|
#[serde(deserialize_with = "de_util::string_or_decimal")]
|
||||||
pub coordinate_y: rust_decimal::Decimal,
|
pub coordinate_y: rust_decimal::Decimal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
||||||
|
pub enum AttackResult {
|
||||||
|
Attacked,
|
||||||
|
Mugged,
|
||||||
|
Hospitalized,
|
||||||
|
Lost,
|
||||||
|
Arrested,
|
||||||
|
Escape,
|
||||||
|
Interrupted,
|
||||||
|
Assist,
|
||||||
|
Timeout,
|
||||||
|
Stalemate,
|
||||||
|
Special,
|
||||||
|
Looted,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct Attack<'a> {
|
||||||
|
pub code: &'a str,
|
||||||
|
#[serde(with = "ts_seconds")]
|
||||||
|
pub timestamp_started: DateTime<Utc>,
|
||||||
|
#[serde(with = "ts_seconds")]
|
||||||
|
pub timestamp_ended: DateTime<Utc>,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
||||||
|
pub attacker_id: Option<i32>,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
||||||
|
pub attacker_faction: Option<i32>,
|
||||||
|
pub defender_id: i32,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
||||||
|
pub defender_faction: Option<i32>,
|
||||||
|
pub result: AttackResult,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "de_util::int_is_bool")]
|
||||||
|
pub stealthed: bool,
|
||||||
|
|
||||||
|
#[cfg(feature = "decimal")]
|
||||||
|
pub respect: rust_decimal::Decimal,
|
||||||
|
|
||||||
|
#[cfg(not(feature = "decimal"))]
|
||||||
|
pub respect: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct RespectModifiers {
|
||||||
|
pub fair_fight: f32,
|
||||||
|
pub war: f32,
|
||||||
|
pub retaliation: f32,
|
||||||
|
pub group_attack: f32,
|
||||||
|
pub overseas: f32,
|
||||||
|
pub chain_bonus: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct AttackFull<'a> {
|
||||||
|
pub code: &'a str,
|
||||||
|
#[serde(with = "ts_seconds")]
|
||||||
|
pub timestamp_started: DateTime<Utc>,
|
||||||
|
#[serde(with = "ts_seconds")]
|
||||||
|
pub timestamp_ended: DateTime<Utc>,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
||||||
|
pub attacker_id: Option<i32>,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_is_none")]
|
||||||
|
pub attacker_name: Option<&'a str>,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
||||||
|
pub attacker_faction: Option<i32>,
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "de_util::empty_string_is_none",
|
||||||
|
rename = "attacker_factionname"
|
||||||
|
)]
|
||||||
|
pub attacker_faction_name: Option<&'a str>,
|
||||||
|
|
||||||
|
pub defender_id: i32,
|
||||||
|
pub defender_name: &'a str,
|
||||||
|
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
||||||
|
pub defender_faction: Option<i32>,
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "de_util::empty_string_is_none",
|
||||||
|
rename = "defender_factionname"
|
||||||
|
)]
|
||||||
|
pub defender_faction_name: Option<&'a str>,
|
||||||
|
|
||||||
|
pub result: AttackResult,
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "de_util::int_is_bool")]
|
||||||
|
pub stealthed: bool,
|
||||||
|
#[serde(deserialize_with = "de_util::int_is_bool")]
|
||||||
|
pub raid: bool,
|
||||||
|
#[serde(deserialize_with = "de_util::int_is_bool")]
|
||||||
|
pub ranked_war: bool,
|
||||||
|
|
||||||
|
#[cfg(feature = "decimal")]
|
||||||
|
pub respect: rust_decimal::Decimal,
|
||||||
|
#[cfg(feature = "decimal")]
|
||||||
|
pub respect_loss: rust_decimal::Decimal,
|
||||||
|
|
||||||
|
#[cfg(not(feature = "decimal"))]
|
||||||
|
pub respect: f32,
|
||||||
|
#[cfg(not(feature = "decimal"))]
|
||||||
|
pub respect_loss: f32,
|
||||||
|
|
||||||
|
pub modifiers: RespectModifiers,
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
|
||||||
use chrono::{serde::ts_seconds, DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use torn_api_macros::ApiCategory;
|
use torn_api_macros::ApiCategory;
|
||||||
|
|
||||||
use crate::de_util::{self, null_is_empty_dict};
|
use crate::de_util::{self, null_is_empty_dict};
|
||||||
|
|
||||||
pub use crate::common::{LastAction, Status, Territory};
|
pub use crate::common::{Attack, AttackFull, LastAction, Status, Territory};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||||
#[api(category = "faction")]
|
#[api(category = "faction")]
|
||||||
|
@ -76,111 +76,6 @@ pub struct Basic<'a> {
|
||||||
pub territory_wars: Vec<FactionTerritoryWar<'a>>,
|
pub territory_wars: Vec<FactionTerritoryWar<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
||||||
pub enum AttackResult {
|
|
||||||
Attacked,
|
|
||||||
Mugged,
|
|
||||||
Hospitalized,
|
|
||||||
Lost,
|
|
||||||
Arrested,
|
|
||||||
Escape,
|
|
||||||
Interrupted,
|
|
||||||
Assist,
|
|
||||||
Timeout,
|
|
||||||
Stalemate,
|
|
||||||
Special,
|
|
||||||
Looted,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub struct Attack<'a> {
|
|
||||||
pub code: &'a str,
|
|
||||||
#[serde(with = "ts_seconds")]
|
|
||||||
pub timestamp_started: DateTime<Utc>,
|
|
||||||
#[serde(with = "ts_seconds")]
|
|
||||||
pub timestamp_ended: DateTime<Utc>,
|
|
||||||
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
|
||||||
pub attacker_id: Option<i32>,
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
|
||||||
pub attacker_faction: Option<i32>,
|
|
||||||
pub defender_id: i32,
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
|
||||||
pub defender_faction: Option<i32>,
|
|
||||||
pub result: AttackResult,
|
|
||||||
|
|
||||||
#[serde(deserialize_with = "de_util::int_is_bool")]
|
|
||||||
pub stealthed: bool,
|
|
||||||
|
|
||||||
#[cfg(feature = "decimal")]
|
|
||||||
pub respect: rust_decimal::Decimal,
|
|
||||||
|
|
||||||
#[cfg(not(feature = "decimal"))]
|
|
||||||
pub respect: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub struct RespectModifiers {
|
|
||||||
pub fair_fight: f32,
|
|
||||||
pub war: f32,
|
|
||||||
pub retaliation: f32,
|
|
||||||
pub group_attack: f32,
|
|
||||||
pub overseas: f32,
|
|
||||||
pub chain_bonus: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub struct AttackFull<'a> {
|
|
||||||
pub code: &'a str,
|
|
||||||
#[serde(with = "ts_seconds")]
|
|
||||||
pub timestamp_started: DateTime<Utc>,
|
|
||||||
#[serde(with = "ts_seconds")]
|
|
||||||
pub timestamp_ended: DateTime<Utc>,
|
|
||||||
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
|
||||||
pub attacker_id: Option<i32>,
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_is_none")]
|
|
||||||
pub attacker_name: Option<&'a str>,
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
|
||||||
pub attacker_faction: Option<i32>,
|
|
||||||
#[serde(
|
|
||||||
deserialize_with = "de_util::empty_string_is_none",
|
|
||||||
rename = "attacker_factionname"
|
|
||||||
)]
|
|
||||||
pub attacker_faction_name: Option<&'a str>,
|
|
||||||
|
|
||||||
pub defender_id: i32,
|
|
||||||
pub defender_name: &'a str,
|
|
||||||
#[serde(deserialize_with = "de_util::empty_string_int_option")]
|
|
||||||
pub defender_faction: Option<i32>,
|
|
||||||
#[serde(
|
|
||||||
deserialize_with = "de_util::empty_string_is_none",
|
|
||||||
rename = "defender_factionname"
|
|
||||||
)]
|
|
||||||
pub defender_faction_name: Option<&'a str>,
|
|
||||||
|
|
||||||
pub result: AttackResult,
|
|
||||||
|
|
||||||
#[serde(deserialize_with = "de_util::int_is_bool")]
|
|
||||||
pub stealthed: bool,
|
|
||||||
#[serde(deserialize_with = "de_util::int_is_bool")]
|
|
||||||
pub raid: bool,
|
|
||||||
#[serde(deserialize_with = "de_util::int_is_bool")]
|
|
||||||
pub ranked_war: bool,
|
|
||||||
|
|
||||||
#[cfg(feature = "decimal")]
|
|
||||||
pub respect: rust_decimal::Decimal,
|
|
||||||
#[cfg(feature = "decimal")]
|
|
||||||
pub respect_loss: rust_decimal::Decimal,
|
|
||||||
|
|
||||||
#[cfg(not(feature = "decimal"))]
|
|
||||||
pub respect: f32,
|
|
||||||
#[cfg(not(feature = "decimal"))]
|
|
||||||
pub respect_loss: f32,
|
|
||||||
|
|
||||||
pub modifiers: RespectModifiers,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -2,12 +2,13 @@ use serde::{
|
||||||
de::{self, MapAccess, Visitor},
|
de::{self, MapAccess, Visitor},
|
||||||
Deserialize, Deserializer,
|
Deserialize, Deserializer,
|
||||||
};
|
};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use torn_api_macros::ApiCategory;
|
use torn_api_macros::ApiCategory;
|
||||||
|
|
||||||
use crate::de_util;
|
use crate::de_util;
|
||||||
|
|
||||||
pub use crate::common::{LastAction, Status};
|
pub use crate::common::{Attack, AttackFull, LastAction, Status};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, ApiCategory)]
|
#[derive(Debug, Clone, Copy, ApiCategory)]
|
||||||
#[api(category = "user")]
|
#[api(category = "user")]
|
||||||
|
@ -22,6 +23,10 @@ pub enum Selection {
|
||||||
PersonalStats,
|
PersonalStats,
|
||||||
#[api(type = "CriminalRecord", field = "criminalrecord")]
|
#[api(type = "CriminalRecord", field = "criminalrecord")]
|
||||||
Crimes,
|
Crimes,
|
||||||
|
#[api(type = "BTreeMap<i32, Attack>", field = "attacks")]
|
||||||
|
AttacksFull,
|
||||||
|
#[api(type = "BTreeMap<i32, AttackFull>", field = "attacks")]
|
||||||
|
Attacks,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
||||||
|
@ -404,6 +409,7 @@ mod tests {
|
||||||
Selection::Profile,
|
Selection::Profile,
|
||||||
Selection::PersonalStats,
|
Selection::PersonalStats,
|
||||||
Selection::Crimes,
|
Selection::Crimes,
|
||||||
|
Selection::Attacks,
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
@ -414,6 +420,8 @@ mod tests {
|
||||||
response.profile().unwrap();
|
response.profile().unwrap();
|
||||||
response.personal_stats().unwrap();
|
response.personal_stats().unwrap();
|
||||||
response.crimes().unwrap();
|
response.crimes().unwrap();
|
||||||
|
response.attacks().unwrap();
|
||||||
|
response.attacks_full().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_test]
|
#[async_test]
|
||||||
|
|
Loading…
Reference in a new issue