item.rs
1 use crate::unit::Currency; 2 use candid::CandidType; 3 use serde::{Deserialize, Serialize}; 4 5 pub mod attr; 6 use crate::unit::Price; 7 use attr::{AttrKeys, Stock}; 8 9 pub mod spec; 10 use spec::SpecResult; 11 12 pub type ItemId = u128; 13 14 #[derive(CandidType, Clone, Serialize, Deserialize, Debug, Hash, Eq, PartialEq)] 15 pub struct ItemPageArgs { 16 pub item_id: u128, 17 pub market_id: Option<u128>, 18 pub currency: Currency, 19 pub attr_keys: AttrKeys, 20 } 21 22 #[derive(CandidType, Clone, Debug, Serialize, Deserialize)] 23 pub struct ItemPageResult { 24 pub name: String, 25 pub price: Price, 26 pub descriptions: Vec<String>, 27 pub tags: Vec<Tag>, 28 pub image_vec: Vec<ImageData>, 29 pub stock: Stock, 30 pub store_id: u128, 31 pub store_name: String, 32 pub market_name: Option<String>, 33 pub specs: Option<SpecResult>, 34 } 35 36 #[derive(CandidType, Clone, Debug, Serialize, Deserialize)] 37 pub struct ImageData { 38 pub url: String, 39 pub description: String, 40 } 41 42 impl ImageData { 43 pub fn new_str(url: &str, description: &str) -> Self { 44 Self { 45 url: url.to_string(), 46 description: description.to_string(), 47 } 48 } 49 } 50 51 #[derive(CandidType, Clone, Debug, Serialize, Deserialize)] 52 pub struct Tag { 53 pub id: u128, 54 pub name: String, 55 } 56 57 #[derive(CandidType, Clone, Serialize, Deserialize, Debug, Hash, Eq, PartialEq, Copy)] 58 pub struct ItemCoreKeys { 59 pub item_id: ItemId, 60 pub attr_keys: AttrKeys, 61 } 62 63 #[derive(CandidType, Clone, Serialize, Deserialize, Debug, Hash, Eq, PartialEq)] 64 pub struct ItemCoreDataArgs { 65 pub item: ItemCoreKeys, 66 pub currency: Currency, 67 } 68 69 #[derive(CandidType, Clone, Debug, Serialize, Deserialize)] 70 pub struct ItemCoreDataResult { 71 pub id: ItemId, 72 pub name: String, 73 pub price: Price, 74 pub tags: Vec<Tag>, 75 pub image: ImageData, 76 pub stock: Stock, 77 pub store_id: u128, 78 pub store_name: String, 79 }