From 40b8084ab1e56bfbd8e80fe8195fec6a51102dbf Mon Sep 17 00:00:00 2001 From: Alvaro Cabo Date: Tue, 2 Apr 2024 20:58:08 +0200 Subject: [PATCH] Ft/Made model's field public (#81) * Made public all model's fields * Fixed clippy * Added docs * Small changes in docs for queries.rs --- src/model/filter.rs | 2 +- src/model/item.rs | 21 +++++++++++-- src/model/payment_method.rs | 21 +++++++------ src/model/user.rs | 59 +++++++++++++++++++++---------------- src/queries.rs | 6 ++-- src/tests/queries.rs | 2 +- 6 files changed, 68 insertions(+), 43 deletions(-) diff --git a/src/model/filter.rs b/src/model/filter.rs index 3f9fee0..f77685a 100644 --- a/src/model/filter.rs +++ b/src/model/filter.rs @@ -36,7 +36,7 @@ pub mod size; /// let filter: Filter = Filter::builder() /// .catalog_ids(Some(String::from("4,16"))) /// .brand_ids(Some(String::from("14,53"))) -/// .build(); +/// .build(); /// /// // Women shoes and Women clothes that are only from brands Adidas and Nike. /// diff --git a/src/model/item.rs b/src/model/item.rs index a710151..a9ff4e2 100644 --- a/src/model/item.rs +++ b/src/model/item.rs @@ -44,24 +44,31 @@ impl fmt::Display for Item { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Hash, Eq)] #[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs,))] pub struct AdvancedItem { - // Products filter info + /// Vinted item ID pub id: i64, + /// Item title pub title: String, + /// Item description pub description: String, + /// See [`Size`](crate::model::filter::size::Size) #[serde(rename = "size")] pub size_title: String, + /// See [`Brand`](crate::model::filter::brand::Brand) #[serde(rename = "brand")] pub brand_title: String, #[serde(skip_serializing_if = "Option::is_none")] pub composition: Option, #[serde(skip_serializing_if = "Option::is_none")] pub extra_conditions: Option, + /// See [`Brand`](crate::model::filter::brand::Brand) #[serde(skip_serializing_if = "Option::is_none")] pub brand_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub size_id: Option, + /// See [`ArticleStatus`](crate::model::filter::ArticleStatus) #[serde(skip_serializing_if = "Option::is_none")] pub status_id: Option, + /// Status of the item in French 🇫🇷 #[serde(rename = "status")] #[serde(skip_serializing_if = "Option::is_none")] pub status_fr: Option, @@ -78,7 +85,7 @@ pub struct AdvancedItem { #[serde(skip_serializing_if = "Option::is_none")] pub color2: Option, pub package_size_id: i32, - //Location + /// See [`Country`](crate::model::filter::country::Country) pub country_id: i32, #[serde(skip_serializing_if = "Option::is_none")] pub city_id: Option, @@ -86,17 +93,25 @@ pub struct AdvancedItem { pub city: Option, //Stats + /// Number of bids on the item pub active_bid_count: i32, + /// Number of times the item was added to favourites pub favourite_count: i32, + /// Number of times the item was viewed pub view_count: i32, + /// Moderation status of the item (Vinted internal use only) pub moderation_status: i32, #[serde(skip_serializing_if = "Option::is_none")] pub last_push_up_at: Option, + /// Related ['Brand'](crate::model::filter::brand::Brand) IDs pub related_catalog_ids: Vec, // Pricing + /// Original price of the item pub original_price_numeric: String, + /// Currency the item was posted with. See [`Currency`](crate::model::filter::Currency) for valid currencies on Vinted pub currency: String, + /// Current valid price of the item pub price_numeric: String, // Order by stats @@ -106,7 +121,7 @@ pub struct AdvancedItem { #[serde(skip_serializing_if = "Option::is_none")] pub user_updated_at_ts: Option, - // Asets + // Assets pub photos: Vec, pub url: String, pub user: AdvancedUser, diff --git a/src/model/payment_method.rs b/src/model/payment_method.rs index 828c3ee..058fd92 100644 --- a/src/model/payment_method.rs +++ b/src/model/payment_method.rs @@ -8,19 +8,22 @@ use redis_macros::{FromRedisValue, ToRedisArgs}; #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Hash, Eq)] #[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs,))] pub struct PayInMethod { - id: i32, - code: String, - requires_credit_card: bool, + pub id: i32, + /// Code of the payment method given by Vinted + pub code: String, + /// If the payment method requires a credit card + pub requires_credit_card: bool, #[serde(skip_serializing_if = "Option::is_none")] - event_tracking_code: Option, + pub event_tracking_code: Option, + /// Icon of the payment method #[serde(skip_serializing_if = "Option::is_none")] - icon: Option, - enabled: bool, + pub icon: Option, + pub enabled: bool, #[serde(skip_serializing_if = "Option::is_none")] - translated_name: Option, + pub translated_name: Option, #[serde(skip_serializing_if = "Option::is_none")] - note: Option, - method_change_possible: bool, + pub note: Option, + pub method_change_possible: bool, } impl fmt::Display for PayInMethod { diff --git a/src/model/user.rs b/src/model/user.rs index ead468b..5d80f3b 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -1,51 +1,60 @@ -use std::fmt; - use crate::model::{Deserialize, Serialize}; #[cfg(feature = "redis")] use crate::model::{FromRedisValue, ToRedisArgs}; +use std::fmt; use super::{payment_method::PayInMethod, photo::Photo}; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)] #[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs,))] pub struct User { - id: i64, - login: String, //usernameredis_macros - photo: Photo, + /// Vinted user ID + pub id: i64, + // Username + pub login: String, + /// User's profile picture URL + pub photo: Photo, } - +/// All avalible fields for a user #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Hash, Eq)] #[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs,))] pub struct AdvancedUser { - id: i64, - login: String, //username + /// Vinted user ID + pub id: i64, + /// Username + pub login: String, + /// User's profile picture URL #[serde(skip_serializing_if = "Option::is_none")] - photo: Option, - + pub photo: Option, + /// User's real name #[serde(skip_serializing_if = "Option::is_none")] - real_name: Option, + pub real_name: Option, + /// User's email #[serde(skip_serializing_if = "Option::is_none")] - email: Option, + pub email: Option, + /// User's birthday #[serde(skip_serializing_if = "Option::is_none")] - birthday: Option, + pub birthday: Option, #[serde(skip_serializing_if = "Option::is_none")] - gender: Option, - + pub gender: Option, + /// Last time the user logged in #[serde(skip_serializing_if = "Option::is_none")] - last_loged_on_ts: Option, - expose_location: bool, - country_id: i32, + pub last_loged_on_ts: Option, + /// If the user wants to expose his location + pub expose_location: bool, + /// See [`Country`](crate::model::filter::country::Country) + pub country_id: i32, #[serde(skip_serializing_if = "Option::is_none")] - city_id: Option, + pub city_id: Option, + /// City name #[serde(skip_serializing_if = "Option::is_none")] - city: Option, - + pub city: Option, #[serde(skip_serializing_if = "Option::is_none")] - path: Option, + pub path: Option, #[serde(skip_serializing_if = "Option::is_none")] - about: Option, - - accepted_pay_in_methods: Vec, + pub about: Option, + /// Payment methods accepted by the user + pub accepted_pay_in_methods: Vec, } impl fmt::Display for AdvancedUser { diff --git a/src/queries.rs b/src/queries.rs index 7476183..c7051ed 100644 --- a/src/queries.rs +++ b/src/queries.rs @@ -425,14 +425,12 @@ impl<'a> VintedWrapper<'a> { pub fn get_id(&self) -> &usize { &self.id } - /** - - After changing host is always necessary to refresh cookies - */ + /// After changing host is always necessary to refresh cookies pub fn set_new_random_host(&mut self) { self.host = random_host(); } + /// After changing host is always necessary to refresh cookies pub fn set_new_host(&mut self, host: Host) { self.host = host.into(); } diff --git a/src/tests/queries.rs b/src/tests/queries.rs index f2fdd31..b806efa 100644 --- a/src/tests/queries.rs +++ b/src/tests/queries.rs @@ -61,7 +61,7 @@ async fn test_get_item_brands() { match vinted.get_items(&filter, 1, None, None, None).await { // Limitado el numero de elementos a 1 Ok(items) => { - assert_eq!(items.items.get(0).unwrap().brand_title, brand.title); + assert_eq!(items.items.first().unwrap().brand_title, brand.title); } Err(err) => match err { VintedWrapperError::ItemNumberError => unreachable!(),