refactor: add deserialisation to all models
This commit is contained in:
parent
7132eb9f68
commit
695ea83969
|
@ -6,6 +6,7 @@ use crate::{
|
||||||
use scraper::Html;
|
use scraper::Html;
|
||||||
|
|
||||||
pub mod character;
|
pub mod character;
|
||||||
|
pub mod free_company;
|
||||||
|
|
||||||
selectors!(
|
selectors!(
|
||||||
PAGINATION_TOTAL => ".parts__total";
|
PAGINATION_TOTAL => ".parts__total";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
macro_rules! ffxiv_enum {
|
macro_rules! ffxiv_enum {
|
||||||
($(#[$meta:meta])* $name:ident { $($variant:ident => $str_repr:expr),+$(,)? }) => {
|
($(#[$meta:meta])* $name:ident { $($variant:ident => $str_repr:expr),+$(,)? }) => {
|
||||||
$(#[$meta])*
|
$(#[$meta])*
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum $name {
|
pub enum $name {
|
||||||
$($variant,)+
|
$($variant,)+
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use super::GrandCompany;
|
||||||
|
|
||||||
use ffxiv_types::{World, Race, Clan, Guardian};
|
use ffxiv_types::{World, Race, Clan, Guardian};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Character {
|
pub struct Character {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ pub struct Character {
|
||||||
pub profile_text: String,
|
pub profile_text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct GrandCompanyInfo {
|
pub struct GrandCompanyInfo {
|
||||||
pub grand_company: GrandCompany,
|
pub grand_company: GrandCompany,
|
||||||
pub rank: String,
|
pub rank: String,
|
||||||
|
|
|
@ -8,13 +8,13 @@ use url::Url;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct FreeCompany {
|
pub struct FreeCompany {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub world: World,
|
pub world: World,
|
||||||
pub slogan: String,
|
pub slogan: String,
|
||||||
#[serde(serialize_with = "multi_url")]
|
#[serde(with = "multi_url")]
|
||||||
pub crest: Vec<Url>,
|
pub crest: Vec<Url>,
|
||||||
pub grand_company: GrandCompany,
|
pub grand_company: GrandCompany,
|
||||||
pub active_members: u16,
|
pub active_members: u16,
|
||||||
|
@ -25,27 +25,42 @@ pub struct FreeCompany {
|
||||||
pub reputation: BTreeMap<GrandCompany, u8>,
|
pub reputation: BTreeMap<GrandCompany, u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct PvpRankings {
|
pub struct PvpRankings {
|
||||||
pub weekly: Option<u64>,
|
pub weekly: Option<u64>,
|
||||||
pub monthly: Option<u64>,
|
pub monthly: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Estate {
|
pub struct Estate {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub address: String,
|
pub address: String,
|
||||||
pub greeting: String,
|
pub greeting: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn multi_url<S>(urls: &Vec<Url>, serializer: S) -> Result<S::Ok, S::Error>
|
mod multi_url {
|
||||||
where S: serde::Serializer,
|
use serde::{Deserializer, Deserialize, Serializer, ser::SerializeSeq};
|
||||||
{
|
|
||||||
use serde::ser::SerializeSeq;
|
|
||||||
|
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
crate fn serialize<S>(urls: &Vec<Url>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where S: Serializer,
|
||||||
|
{
|
||||||
let mut seq = serializer.serialize_seq(Some(urls.len()))?;
|
let mut seq = serializer.serialize_seq(Some(urls.len()))?;
|
||||||
for url in urls {
|
for url in urls {
|
||||||
seq.serialize_element(&url_serde::Ser::new(url))?;
|
seq.serialize_element(&url_serde::Ser::new(url))?;
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
crate fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Url>, D::Error>
|
||||||
|
where D: Deserializer<'de>
|
||||||
|
{
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Wrapper(#[serde(with = "url_serde")] Url);
|
||||||
|
|
||||||
|
let urls = Vec::deserialize(deserializer)?;
|
||||||
|
Ok(urls.into_iter().map(|Wrapper(u)| u).collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
pub mod character;
|
pub mod character;
|
||||||
|
pub mod free_company;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Pagination {
|
pub struct Pagination {
|
||||||
pub current_page: u64,
|
pub current_page: u64,
|
||||||
pub total_pages: u64,
|
pub total_pages: u64,
|
||||||
pub total_results: u64,
|
pub total_results: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Paginated<T> {
|
pub struct Paginated<T> {
|
||||||
pub pagination: Pagination,
|
pub pagination: Pagination,
|
||||||
pub results: Vec<T>,
|
pub results: Vec<T>,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ffxiv_types::World;
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct CharacterSearchItem {
|
pub struct CharacterSearchItem {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user