Skip to content

Commit 81439d0

Browse files
committed
simple search example
1 parent 1615a38 commit 81439d0

File tree

7 files changed

+1331
-16
lines changed

7 files changed

+1331
-16
lines changed

rust/price-rs/mercado-rs/Cargo.lock

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/price-rs/mercado-rs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
serde_json = { version = "1" }
10+
serde = { version = "1", features = ["derive"]}

rust/price-rs/mercado-rs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod types;
1+
pub mod types;
22

33
#[cfg(test)]
44
mod tests {

rust/price-rs/mercado-rs/src/types.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
1-
struct Paging {
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Deserialize, Serialize, Debug)]
4+
pub struct Paging {
25
total: u64,
36
primary_results: u32,
47
offset: u32,
58
limit: u32,
69
}
710

8-
struct Seller {
9-
id: String,
11+
#[derive(Deserialize, Serialize, Debug)]
12+
pub struct Seller {
13+
id: u64,
1014
permalink: String,
1115
registration_date: String,
1216
}
1317

14-
struct Installments {
18+
#[derive(Deserialize, Serialize, Debug)]
19+
pub struct Installments {
1520
quantity: u8,
16-
amount: u32,
21+
amount: f32,
1722
rate: f32,
1823
currency_id: String,
1924
}
2025

21-
struct Address {
26+
#[derive(Deserialize, Serialize, Debug)]
27+
pub struct Address {
2228
state_id: String,
2329
state_name: String,
2430
city_id: String,
2531
city_name: String,
2632
}
2733

28-
struct Shipping {
34+
#[derive(Deserialize, Serialize, Debug)]
35+
pub struct Shipping {
2936
free_shipping: bool,
3037
mode: String,
3138
tags: Vec<String>,
3239
logistic_type: String,
3340
store_pick_up: bool
3441
}
3542

36-
struct Attribute {
43+
#[derive(Deserialize, Serialize, Debug)]
44+
pub struct Attribute {
3745
id: String,
3846
attribute_group_id: String,
3947
name: String,
40-
value_name: String,
48+
value_name: Option<String>,
4149
attribute_group_name: String,
4250
}
4351

44-
struct SearchResult {
52+
#[derive(Deserialize, Serialize, Debug)]
53+
pub struct SearchResult {
4554
id: String,
4655
title: String,
4756
seller: Seller,
48-
price: u64,
57+
price: f32,
4958
available_quantity: u32,
5059
sold_quantity: u32,
5160
condition: String, // should be enum
@@ -61,12 +70,14 @@ struct SearchResult {
6170
attributes: Vec<Attribute>
6271
}
6372

64-
struct Sort {
73+
#[derive(Deserialize, Serialize, Debug)]
74+
pub struct Sort {
6575
id: String,
6676
name: String
6777
}
6878

69-
struct SearchResults {
79+
#[derive(Deserialize, Serialize, Debug)]
80+
pub struct SearchResults {
7081
query: String,
7182
paging: Paging,
7283
results: Vec<SearchResult>,

0 commit comments

Comments
 (0)