Skip to content

Commit

Permalink
Merge pull request #48 from TuTarea/develop
Browse files Browse the repository at this point in the history
Ft/In the memory of strip option (#47)
  • Loading branch information
pxp9 authored Jul 27, 2023
2 parents fb9ed36 + 0b1d03c commit 14d46d6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.4.0 (2023-07-27) [#47](https://github.com/TuTarea/vinted-rs/pull/47/)

## Improved
- Remove `strip_option` in `Filter` struct for compatilbility.

## 0.3.3 (2023-07-26) [#45](https://github.com/TuTarea/vinted-rs/pull/45/)

## Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vinted-rs"
version = "0.3.3"
version = "0.4.0"
edition = "2021"
repository = "https://github.com/TuTarea/vinted-rs"
authors = ["Pepe Márquez <[email protected]>" , "Álvaro Cabo <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Via `cargo` you can add the library to your project's `Cargo.toml`

```toml
[dependencies]
vinted-rs = "0.3.3"
vinted-rs = "0.4.0"
```

## DB setup
Expand Down
8 changes: 3 additions & 5 deletions examples/filter_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use bb8_postgres::tokio_postgres::NoTls;
use std::env;
use vinted_rs::{db::DbController, queries::Host, Filter, VintedWrapper};


#[tokio::main]
async fn main() {
let args: Vec<String> = env::args().collect();
Expand All @@ -26,9 +25,9 @@ async fn main() {
let brands = format!("{},{}", adidas.id, nike.id);

let filter = Filter::builder()
.brand_ids(brands)
.price_from(15)
.price_to(20)
.brand_ids(Some(brands))
.price_from(Some(15))
.price_to(Some(20))
.build();

let vinted = VintedWrapper::new_with_host(host);
Expand All @@ -38,7 +37,6 @@ async fn main() {
let items = vinted.get_items(&filter, 10).await.unwrap();

if items.items.is_empty() {

println!("No items found");
}
println!("{}", items);
Expand Down
51 changes: 26 additions & 25 deletions src/model/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pub mod size;
/// use vinted_rs::Filter;
///
/// let filter: Filter = Filter::builder()
/// .catalog_ids(String::from("4,16"))
/// .brand_ids(String::from("14,53"))
/// .build();
/// .catalog_ids(Some(String::from("4,16"))
/// .brand_ids(Some(String::from("14,53"))
/// ).build();
///
/// // Women shoes and Women clothes that are only from brands Adidas and Nike.
///
Expand All @@ -51,11 +51,11 @@ pub struct Filter {
///```rust
/// use vinted_rs::Filter;
///
///let filter: Filter = Filter::builder().search_text(String::from("shoes")).build();
///let filter: Filter = Filter::builder().search_text(Some(String::from("shoes"))).build();
///```
///
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub search_text: Option<String>,
///
///
Expand All @@ -74,14 +74,13 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().catalog_ids(String::from("4,16")).build();
/// let filter: Filter = Filter::builder().catalog_ids(Some(String::from("4,16"))).build();
/// // Where 4 and 16 are catalog_ids from Vinted
/// // 4 is catalog_id for Women clothes
/// // 16 is catalog_id for Women Shoes
///```
#[builder(default, setter(strip_option))]
#[builder(default)]
pub catalog_ids: Option<String>,
#[builder(default, setter(strip_option))]
///The color IDs to filter items by. Must be formatted as `^[\d+,]*\d+$` regex.
///
///If not formated with the specified regex, undefined behaviour. (Input will not be checked).
Expand All @@ -96,12 +95,13 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().color_ids(String::from("1,5")).build();
/// let filter: Filter = Filter::builder().color_ids(Some(String::from("1,5"))).build();
/// // Where 1 and 5 are color_ids from Vinted
/// // 1 is color_id for Black
/// // 5 is color_id for Pink
///```
///
#[builder(default)]
pub color_ids: Option<String>,
/// The brand IDs to filter items by. Must be formatted as `^[\d+,]*\d+$` regex.
///
Expand All @@ -115,13 +115,13 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().brand_ids(String::from("14,53")).build();
/// let filter: Filter = Filter::builder().brand_ids(Some(String::from("14,53"))).build();
/// // Where 14 and 53 are brand_ids from Vinted
/// // 14 is brand_id for Adidas
/// // 53 is brand_id for Nike
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub brand_ids: Option<String>,
/// The country IDs to filter items by. Must be formatted as `^[\d+,]*\d+$` regex.
///
Expand All @@ -135,13 +135,13 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().countries_ids(String::from("7,16")).build();
/// let filter: Filter = Filter::builder().countries_ids(Some(String::from("7,16"))).build();
/// // Where 7 and 16 are country_ids from Vinted
/// // 7 is country_id for Spain
/// // 16 is country_id for France
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub countries_ids: Option<String>,
/// The size IDs to filter items by. Must be formatted as `^[\d+,]*\d+$` regex.
///
Expand All @@ -155,13 +155,13 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().size_ids(String::from("1226,102")).build();
/// let filter: Filter = Filter::builder().size_ids(Some(String::from("1226,102"))).build();
/// // Where 7 and 16 are country_ids from Vinted
/// // 1226 is size_id for XXXS / 30 / 2
/// // 102 is size_id for XXS / 32 / 4
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub material_ids: Option<String>,
/// The material IDs to filter items by. Must be formatted as `^[\d+,]*\d+$` regex.
///
Expand All @@ -175,15 +175,15 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().material_ids(String::from("44,102")).build();
/// let filter: Filter = Filter::builder().material_ids(Some(String::from("44,102"))).build();
/// // Where 7 and 16 are country_ids from Vinted
/// // 44 is material_id for coton
/// // 49 is material_id for silk
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub size_ids: Option<String>,
#[builder(default, setter(strip_option))]

/// The article statuses to filter items by.
///
///### Example
Expand All @@ -192,9 +192,10 @@ pub struct Filter {
/// use vinted_rs::model::filter::ArticleStatus;
///
/// let filter: Filter = Filter::builder().article_status(vec![ArticleStatus::NewTags ,
/// ArticleStatus::NewNoTags]).build();
/// ArticleStatus::NewNoTags])).build();
///```
///
#[builder(default)]
pub article_status: Option<Vec<ArticleStatus>>,
/// The sort order for the retrieved items.
Expand All @@ -204,10 +205,10 @@ pub struct Filter {
/// use vinted_rs::model::filter::SortBy;
///
/// let filter: Filter = Filter::builder().sort_by(SortBy::PriceAscendant).build();
/// let filter: Filter = Filter::builder().sort_by(SortBy::PriceAscendant)).build();
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub sort_by: Option<SortBy>,
/// The minimum price of the article
///
Expand All @@ -216,10 +217,10 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().price_from(10u32).build();
/// let filter: Filter = Filter::builder().price_from(10u32)).build();
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub price_from: Option<u32>,
/// The max price of the article
///
Expand All @@ -228,10 +229,10 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().price_from(20u32).build();
/// let filter: Filter = Filter::builder().price_from(20u32)).build();
///```
///
#[builder(default, setter(strip_option))]
#[builder(default)]
pub price_to: Option<u32>,
}
/**
Expand Down
29 changes: 20 additions & 9 deletions src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ fn _hex_to_rgb(hex_color: &str) -> (u8, u8, u8) {
async fn test_get_item_query_text() {
let vinted = VintedWrapper::new();

let filter: Filter = Filter::builder().search_text(String::from("shoes")).build();
let filter: Filter = Filter::builder()
.search_text(Some(String::from("shoes")))
.build();

match vinted.get_items(&filter, 1).await {
// Limitado el numero de elementos a 1
Expand All @@ -51,7 +53,9 @@ async fn test_get_item_brands() {
let db: DbController<NoTls> = DbController::new(DB_URL, POOL_SIZE, NoTls).await.unwrap();
let brand = db.get_brand_by_name(&String::from("Adidas")).await.unwrap();

let filter: Filter = Filter::builder().brand_ids(brand.id.to_string()).build();
let filter: Filter = Filter::builder()
.brand_ids(Some(brand.id.to_string()))
.build();

match vinted.get_items(&filter, 1).await {
// Limitado el numero de elementos a 1
Expand All @@ -71,7 +75,9 @@ async fn test_get_items_brands() {
let db: DbController<NoTls> = DbController::new(DB_URL, POOL_SIZE, NoTls).await.unwrap();
let brand = db.get_brand_by_name(&String::from("Adidas")).await.unwrap();

let filter: Filter = Filter::builder().brand_ids(brand.id.to_string()).build();
let filter: Filter = Filter::builder()
.brand_ids(Some(brand.id.to_string()))
.build();

match vinted.get_items(&filter, 10).await {
Ok(items) => {
Expand All @@ -91,15 +97,17 @@ async fn test_get_items_brands() {
async fn test_get_items_catalogs_no_db() {
let vinted = VintedWrapper::new();
//Woman elements
let filter: Filter = Filter::builder().catalog_ids(String::from("1904")).build();
let filter: Filter = Filter::builder()
.catalog_ids(Some(String::from("1904")))
.build();
let substrings = vec![
"women", "mujer", "femme", "kobiety", "donna", "moterims", "noi", "dames", "zeny", "damen",
"femei", "mulher", "beauty", "femmes", "dam",
];

match vinted.get_items(&filter, 10).await {
Ok(items) => {
assert!(items.items.len() < 10);
assert!(items.items.len() <= 10);
items.items.iter().for_each(|item| {
let url_item: &str = &item.url;
let category = url_item.split('/').nth(3).unwrap();
Expand All @@ -124,7 +132,10 @@ async fn test_get_items_by_price() {
let min = 50;
let max = 100;

let filter: Filter = Filter::builder().price_from(min).price_to(max).build();
let filter: Filter = Filter::builder()
.price_from(Some(min))
.price_to(Some(max))
.build();

match vinted.get_items(&filter, 10).await {
Ok(items) => {
Expand All @@ -149,7 +160,7 @@ async fn test_get_items_by_size() {
let size_id = String::from("1568");
let size_title = String::from("XS");

let filter: Filter = Filter::builder().size_ids(size_id).build();
let filter: Filter = Filter::builder().size_ids(Some(size_id)).build();

match vinted.get_items(&filter, 20).await {
Ok(items) => {
Expand All @@ -170,7 +181,7 @@ async fn test_get_items_by_material() {
let vinted = VintedWrapper::new();
let id = 49; // Silk

let filter: Filter = Filter::builder().material_ids(id.to_string()).build();
let filter: Filter = Filter::builder().material_ids(Some(id.to_string())).build();
let num: usize = 15;

match vinted.get_items(&filter, num as u32).await {
Expand All @@ -192,7 +203,7 @@ async fn test_get_items_by_color() {

//let props = calculate_color_props(hex);

let filter: Filter = Filter::builder().color_ids(id.to_string()).build();
let filter: Filter = Filter::builder().color_ids(Some(id.to_string())).build();

let num: usize = 20;

Expand Down

0 comments on commit 14d46d6

Please sign in to comment.