Skip to content

Commit

Permalink
Develop (#26)
Browse files Browse the repository at this point in the history
* Pxp9/ft filters url (#14)

* tenemos las tallas gracias a la cortesía de ChatGPT beautiful soup y una buena feature del navegador xd, subimos el JSON donde están todas las categorías (falta parsear) y empezamos con las marcas

* script de python que te saca todos los nombres de marcas de la pagina brands/byLetter/Letra

* nombres de marcas y tallas extraidas

* script que hace requests a la api y obtiene el ID de la marca

* Got brands_ids :D

* formatting catalogs ids

* organizando los recursos de los filtros

* materiales

* arreglillos de ultima hora

* arreglillos de ultima hora

* Added scrappers as submodule

* Refactor completed

* Fmt formatted

* actualizando el submodulo del scrapper

* primera migration sizes complete

* get_catalogs , alvaro y README

* Finished catalogs

* Fix README

* Fix both Readme

* Fix dependency for Diesel

* Created more migrations

* Brands needs a fix

* fix migrations and brands

* migracion de countries y query de la BBDD de una marca

* fix clippy

* arreglando un bug con las cookies, haciendo un test y limitando get_item a 1 elemento

* fix fmt

* mejorando la API del wrapper , implementando FROM de Brand

* fix fmt

* fix clippy on test

* review API and model types

* fix fmt

* Db tests

* fix workflow

* empezando a procesar los filtros en la URI

* Finished db-feeder

* Added some tests

* Added query

* Added optional num field in get_items

* Added Get_category_by_name tested

* Converted vec<i32> to String

Co-authored-by: Pmarquez <pxp9@users.noreply.github.com>

* Finished filters

* Fix doctest

* Added get-host

* Cargo clippy fix

* Small changes big steps

* Fix languages

* fuck cargo fmt

---------

Co-authored-by: alvarocabo <alvarocaboac2@gmail.com>
Co-authored-by: Pmarquez <pxp9@users.noreply.github.com>

* Fix cargo lock

* countries , price from and price to filter done (#25)

* countries , price from and price to filter done

* fix typo docs

* Improved README

* Fixing doc tests

* Small fix

* Added search by country

* Como no el fmt

* Added material and size filters

* Removed debug element

* Attemp of testing item by color

* Ignoring the test for now

* Fix clippy

* Ignore test for now

* Removed main.rs

* Updated .gitignore

* tests de filtros

* fix clippy and fmt

---------

Co-authored-by: alvarocabo <alvarocaboac2@gmail.com>

---------

Co-authored-by: alvarocabo <alvarocaboac2@gmail.com>
Co-authored-by: Pmarquez <pxp9@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 9, 2023
1 parent 82289e2 commit c932042
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --all-features -- --ignored
args: --verbose --all-features -- --ignored --nocapture

release:
name: Release x86_64-unknown-linux-gnu
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
**/main.rs
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.1.0"
version = "0.2.0"
edition = "2021"
repository = "https://github.com/TuTarea/vinted-rs"
authors = ["Pepe Márquez <pepe.marquezromero@gmail.com>" , "Álvaro Cabo <alvarocaboac2@gmail.com>"]
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@
[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs

A complete Vinted API-Wrapper in Rust
## Table of Contents

- [Vinted-rs: A Vinted API wrapper](#vinted-rs-a-vinted-api-wrapper)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [DB setup](#db-setup)
- [Create a migration](#create-a-migration)
- [Run a Docker container with PostgreSQL](#run-a-docker-container-with-postgresql)
- [Run migrations](#run-migrations)
- [Stop DB](#stop-db)
- [Running Tests](#running-tests)

## Installation

Via `cargo` you can add the library to your project's `Cargo.toml`

```toml
[dependencies]
vinted-rs = "0.0.1"
vinted-rs = "0.2"
```

## Authors

[Álvaro Cabo](https://github.com/alvarocabo)

[Pepe Márquez](https://github.com/pxp9)

## DB setup

Advanced filtering features must require this setup before running.

- First start installing diesel-cli (in order to run the migrations in PostgreSQL database)

### VERY IMPORTANT

diesel-cli installation may fail if you do not have `libpq` library installed.
⚠️**Very important:** diesel-cli installation may fail if you do not have `libpq` library installed.

To install `libpq`, just install PostgreSQL package on your machine.

Expand Down Expand Up @@ -85,9 +87,7 @@ make stop

## Running Tests

### Very important

Before running tests is important to do the DB setup
⚠️**Very important:** Before running tests is important to do the [DB setup](#db-setup)

Then run the tests

Expand Down
17 changes: 16 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ use bb8_postgres::{
use postgres_types::ToSql;
use thiserror::Error;

use crate::model::filter::{brand::Brand, category::Category};
use crate::model::filter::{brand::Brand, category::Category, country::Country};

const GET_BRAND_BY_NAME: &str = include_str!("sql_queries/GET_BRAND_BY_NAME.sql");
const GET_BRANDS_BY_NAME: &str = include_str!("sql_queries/GET_BRANDS_BY_NAME.sql");
const GET_CATEGORY_BY_NAME: &str = include_str!("sql_queries/GET_CATEGORY_BY_NAME.sql");
const GET_COUNTRY_BY_ISO_CODE: &str = include_str!("sql_queries/GET_COUNTRY_BY_ISO_CODE.sql");

/**
Represents an error that can occur during database operations.
Expand Down Expand Up @@ -122,4 +123,18 @@ where

Ok(cat)
}

/// Retrieves a category by its title from the database
pub async fn get_country_by_iso<S: AsRef<str> + Sync + ToSql + Display>(
&self,
code: &S,
) -> Result<Country, DbError> {
let conn = self.pool.get().await?;
let row: Row = conn.query_one(GET_COUNTRY_BY_ISO_CODE, &[&code]).await?;

// Works because From<Row> for Category is implemented
let country: Country = row.into();

Ok(country)
}
}
34 changes: 0 additions & 34 deletions src/main.rs

This file was deleted.

61 changes: 57 additions & 4 deletions src/model/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod material;
pub mod size;

/// Represents a filter for querying items.

///
/// Trait Implementations:
/// - `TypedBuilder`: Implements the builder pattern for constructing a `Filter` instance.
///
Expand All @@ -19,6 +19,7 @@ pub mod size;
///### Example
///
///```rust
/// use vinted_rs::Filter;
///
/// let filter: Filter = Filter::builder()
/// .catalog_ids(String::from("4,16"))
Expand All @@ -30,11 +31,16 @@ pub mod size;
///
///```
///
///
/// `price_from` filter should be always <= `price_to` , otherwise Vinted will not find anything
///
#[derive(TypedBuilder, Debug, Clone)]
pub struct Filter {
///The search text to filter items by.
///### Example
///```rust
/// use vinted_rs::Filter;
///
///let filter: Filter = Filter::builder().search_text(String::from("shoes")).build();
///```
///
Expand Down Expand Up @@ -73,6 +79,8 @@ pub struct Filter {
///
///Try it in [Regex 101](https://regex101.com/r/u8ZEpv/1)
///
///
/// **Note:** Color names are only avalible in French in our database at the moment
///### Example
///```rust
/// use vinted_rs::Filter;
Expand Down Expand Up @@ -117,7 +125,7 @@ pub struct Filter {
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().country_ids(String::from("7,16")).build();
/// let filter: Filter = Filter::builder().countries_ids(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
Expand All @@ -144,14 +152,34 @@ pub struct Filter {
///```
///
#[builder(default, setter(strip_option))]
pub material_ids: Option<String>,
/// The material 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).
///
///
///Try it in [Regex 101](https://regex101.com/r/u8ZEpv/1)
///
///### Example
///```rust
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().material_ids(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))]
pub size_ids: Option<String>,
#[builder(default, setter(strip_option))]
/// The article statuses to filter items by.
///
///### Example
///```rust
/// use vinted_rs::Filter;
///
/// use vinted_rs::model::filter::ArticleStatus;
///
/// let filter: Filter = Filter::builder().article_status(vec![ArticleStatus::NewTags ,
/// ArticleStatus::NewNoTags]).build();
Expand All @@ -163,13 +191,38 @@ pub struct Filter {
///### Example
///```rust
/// use vinted_rs::Filter;
///
/// use vinted_rs::model::filter::SortBy;

///
/// let filter: Filter = Filter::builder().sort_by(SortBy::PriceAscendant).build();
///```
///
#[builder(default, setter(strip_option))]
pub sort_by: Option<SortBy>,
/// The minimum price of the article
///
///### Example
///```rust
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().price_from(10u32).build();
///```
///
#[builder(default, setter(strip_option))]
pub price_from: Option<u32>,
/// The max price of the article
///
///### Example
///```rust
/// use vinted_rs::Filter;
///
///
/// let filter: Filter = Filter::builder().price_from(20u32).build();
///```
///
#[builder(default, setter(strip_option))]
pub price_to: Option<u32>,
}

/*
Expand Down
12 changes: 6 additions & 6 deletions src/model/filter/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
pub struct Category {
id: i32,
pub id: i32,
// TODO creo que estos titulos solo estan en ingles
title: String,
code: String,
parent_id: i32,
url: String,
url_en: String,
pub title: String,
pub code: String,
pub parent_id: i32,
pub url: String,
pub url_en: String,
}

#[cfg(feature = "advanced_filters")]
Expand Down
6 changes: 3 additions & 3 deletions src/model/filter/category_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
pub struct CategoryTree {
id: i32,
parent_id: i32,
child_id: i32,
pub id: i32,
pub parent_id: i32,
pub child_id: i32,
}

#[cfg(feature = "advanced_filters")]
Expand Down
7 changes: 3 additions & 4 deletions src/model/filter/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
pub struct Color {
id: i32,
// TODO el titulo solo está en francés valorar que podemos hacer
title: String,
hex: String,
pub id: i32,
pub title: String,
pub hex: String,
}

#[cfg(feature = "advanced_filters")]
Expand Down
12 changes: 7 additions & 5 deletions src/model/filter/country.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ use bb8_postgres::tokio_postgres::Row;
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
struct Country {
id: i32,
local_name: String,
iso_code: String,
flag: String,
pub struct Country {
pub id: i32,
pub name: String,
pub local_name: String,
pub iso_code: String,
pub flag: String,
}

#[cfg(feature = "advanced_filters")]
impl From<Row> for Country {
fn from(row: Row) -> Self {
Country::builder()
.id(row.get("id"))
.name(row.get("name"))
.local_name(row.get("local_name"))
.iso_code(row.get("iso_code"))
.flag(row.get("flag"))
Expand Down
8 changes: 4 additions & 4 deletions src/model/filter/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
pub struct Material {
id: i32,
material_es: String,
material_fr: String,
material_en: String,
pub id: i32,
pub material_es: String,
pub material_fr: String,
pub material_en: String,
}

#[cfg(feature = "advanced_filters")]
Expand Down
8 changes: 4 additions & 4 deletions src/model/photo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::model::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct Photo {
id: i64,
url: String,
dominant_color: String,
dominant_color_opaque: String,
pub id: i64,
pub url: String,
pub dominant_color: String,
pub dominant_color_opaque: String,
}
Loading

0 comments on commit c932042

Please sign in to comment.