add prices to detail view

This commit is contained in:
kageru 2024-03-06 17:39:51 +01:00
parent 5853c9619f
commit 40deda425d
3 changed files with 320 additions and 312 deletions

607
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,10 +7,10 @@ edition = "2021"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
nom = "7.1"
actix-web = { version = "4.3", default_features = false, features = ["macros"] }
itertools = "0.11"
actix-web = { version = "4.5", default_features = false, features = ["macros"] }
itertools = "0.12"
time = { version = "0.3", features = ["serde", "serde-human-readable"] }
regex = { version = "1.7", default_features = false, features = ["std"] }
regex = { version = "1.10", default_features = false, features = ["std"] }
[dev-dependencies]
test-case = "3.1"
test-case = "3.3"

View File

@ -32,6 +32,8 @@ pub struct Card {
#[serde(default)]
pub card_sets: Vec<CardSet>,
pub banlist_info: Option<BanlistInfo>,
#[serde(default)]
pub card_prices: Vec<CardPrice>,
}
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy, Default)]
@ -63,10 +65,18 @@ pub struct Set {
pub tcg_date: Option<Date>,
}
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Default)]
pub struct CardPrice {
cardmarket_price: String,
tcgplayer_price: String,
}
impl Card {
pub fn extended_info(&self) -> Result<String, fmt::Error> {
let mut s = String::with_capacity(1000);
write!(s, "<p><a href=\"https://db.ygorganization.com/search#card:{}\">Rulings</a> – <a href=\"https://yugipedia.com/wiki/{:08}\">Yugipedia</a></p>", &self.name, &self.id)?;
// the ygorg search breaks for I:P and similar criminals.
let url_name = self.name.replace(':', " ");
write!(s, "<p><a href=\"https://db.ygorganization.com/search#card:{url_name}\">Rulings</a> – <a href=\"https://yugipedia.com/wiki/{:08}\">Yugipedia</a></p>", &self.id)?;
s.push_str("<h3>Printings:</h3>");
for printing in &self.card_sets {
write!(s, "{}: {} ({})", printing.set_name, printing.set_code, printing.set_rarity)?;
@ -75,6 +85,11 @@ impl Card {
}
s.push_str("<br/>");
}
if let Some(CardPrice { cardmarket_price, tcgplayer_price }) = self.card_prices.first() {
s.push_str("<h3>Prices:</h3>");
write!(s, "Cardmarket: <a href=\"https://www.cardmarket.com/en/YuGiOh/Products/Search?searchString={url_name}\">{cardmarket_price}&ThinSpace;€</a><br/>")?;
write!(s, "TCGplayer: <a href=\"https://www.tcgplayer.com/search/yugioh/product?productLineName=yugioh&q={url_name}\">$&ThinSpace;{tcgplayer_price}</a><br/>")?;
}
Ok(s)
}