-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…data #104 add pricing data from pokedata
- Loading branch information
Showing
42 changed files
with
377 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use serde::{Serialize, Deserialize}; | ||
use actix_web::{get, web, Responder, Result}; | ||
use urlencoding; | ||
use crate::utils::prices_data::get_prices; | ||
|
||
#[allow(non_snake_case)] | ||
#[derive(Serialize)] | ||
#[derive(Deserialize)] | ||
pub struct Price { | ||
pub date: String, | ||
pub cardId: String, | ||
pub variant: String, | ||
pub rawPrice: f64, | ||
pub gradedPriceTen: f64, | ||
pub gradedPriceNine: f64, | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[derive(Deserialize)] | ||
pub struct PriceSearch { | ||
pub start: String | ||
} | ||
|
||
#[get("/pokemon/card/price/ebay/{id}")] | ||
pub async fn card_prices_ebay( | ||
id: web::Path<String>, | ||
search_params: web::Query<PriceSearch>, | ||
) -> Result<impl Responder> { | ||
let _id = urlencoding::decode(&id).unwrap(); | ||
let start = urlencoding::decode(&search_params.start).unwrap(); | ||
let prices = get_prices(&_id, &start)?; | ||
Ok(web::Json(prices)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,60 @@ | ||
use crate::routes::prices::Price; | ||
use crate::utils::shared::get_data_dir; | ||
use lazy_static::lazy_static; | ||
use crate::utils::shared::{get_data_dir}; | ||
use rusqlite::{named_params, Connection, Result}; | ||
|
||
lazy_static! { | ||
pub static ref PRICES_DB_PATH: String = format!("{}{}", get_data_dir(), "/prices.sql"); | ||
} | ||
/// # Get Prices | ||
/// * Get prices for a card given a start date. will pull prices from start to now. | ||
/// # Arguments | ||
/// * card_id - id of the card you want prices from. | ||
/// * start - inclusive start data filter. | ||
pub fn get_prices(card_id: &str, start: &str) -> Result<Vec<Price>, Box<dyn std::error::Error>> { | ||
let connection = Connection::open(PRICES_DB_PATH.as_str())?; | ||
let mut statement = connection.prepare( | ||
"SELECT date, cardId, variant, rawPrice, gradedPriceTen, gradedPriceNine | ||
FROM prices | ||
WHERE cardId = :card_id | ||
AND date(date) >= date(:date) | ||
ORDER BY date(date) DESC", | ||
)?; | ||
let mut prices: Vec<Price> = Vec::new(); | ||
let _prices = statement.query_map( | ||
named_params! {":card_id": &card_id, ":date": &start}, | ||
|row| { | ||
let price = Price { | ||
date: row.get(0).unwrap(), | ||
cardId: row.get(1).unwrap(), | ||
variant: row.get(2).unwrap_or_default(), | ||
rawPrice: row.get(3).unwrap(), | ||
gradedPriceTen: row.get(4).unwrap(), | ||
gradedPriceNine: row.get(5).unwrap(), | ||
}; | ||
Ok(price) | ||
}, | ||
)?; | ||
for price in _prices { | ||
prices.push(price?) | ||
} | ||
Ok(prices) | ||
} | ||
#[cfg(test)] | ||
mod price_tests { | ||
use super::{*, get_prices}; | ||
use serde_json::to_string_pretty; | ||
#[test] | ||
fn get_prices_test() { | ||
let result = get_prices("SWSH03-Darkness-Ablaze-Swanna-149", "2020-01-01"); | ||
match result { | ||
Ok(val) => { | ||
println!("prices {}", to_string_pretty(&val[0]).unwrap()); | ||
assert!(val.len() > 0) | ||
} | ||
Err(_) => { | ||
assert!(false) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.