Replace web product store with detailed product

This commit is contained in:
eraden 2022-11-28 08:26:47 +01:00
parent ee5bc43962
commit 2316426a13
2 changed files with 28 additions and 35 deletions

View File

@ -290,30 +290,11 @@ pub struct Product {
pub photos: Vec<Photo>, pub photos: Vec<Photo>,
} }
pub mod v2 {
use crate::api::{Category, Photo};
#[derive(Debug, Hash, serde::Serialize, serde::Deserialize)]
pub struct ProductVariant {
pub id: crate::ProductVariantId,
pub product_id: crate::ProductId,
pub name: crate::ProductName,
pub short_description: crate::ProductShortDesc,
pub long_description: crate::ProductLongDesc,
pub category: Option<Category>,
pub price: crate::Price,
pub available: bool,
pub quantity_unit: crate::QuantityUnit,
pub deliver_days_flag: crate::Days,
pub photos: Vec<Photo>,
}
}
impl<'path> impl<'path>
From<( From<(
crate::Product, crate::Product,
&mut Vec<ProductLinkedPhoto>, &mut Vec<ProductLinkedPhoto>,
&mut Vec<crate::Stock>, &mut Vec<Stock>,
&'path str, &'path str,
)> for Product )> for Product
{ {
@ -392,7 +373,7 @@ impl
From<( From<(
Vec<crate::Product>, Vec<crate::Product>,
Vec<ProductLinkedPhoto>, Vec<ProductLinkedPhoto>,
Vec<crate::Stock>, Vec<Stock>,
String, String,
)> for Products )> for Products
{ {
@ -566,3 +547,22 @@ pub mod admin {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct LogoutResponse {} pub struct LogoutResponse {}
} }
pub mod v2 {
use crate::api::{Category, Photo};
#[derive(Debug, Hash, serde::Serialize, serde::Deserialize)]
pub struct ProductVariant {
pub id: crate::ProductVariantId,
pub product_id: crate::ProductId,
pub name: crate::ProductName,
pub short_description: crate::ProductShortDesc,
pub long_description: crate::ProductLongDesc,
pub category: Option<Category>,
pub price: crate::Price,
pub available: bool,
pub quantity_unit: crate::QuantityUnit,
pub deliver_days_flag: crate::Days,
pub photos: Vec<Photo>,
}
}

View File

@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use model::v2::ProductVariantId; use model::v2::{DetailedProduct, ProductVariantId};
use model::ProductId; use model::ProductId;
use seed::Url; use seed::Url;
@ -75,13 +75,11 @@ impl From<::model::api::Config> for Config {
pub struct Products { pub struct Products {
pub categories: Vec<model::api::Category>, pub categories: Vec<model::api::Category>,
pub product_ids: Vec<ProductId>, pub product_ids: Vec<ProductId>,
pub products: HashMap<ProductId, model::api::Product>, pub products: HashMap<ProductId, DetailedProduct>,
pub product_variant_ids: Vec<ProductVariantId>,
pub product_variants: HashMap<ProductVariantId, model::api::v2::ProductVariant>,
} }
impl Products { impl Products {
pub fn update(&mut self, products: Vec<model::api::Product>) { pub fn update(&mut self, products: Vec<DetailedProduct>) {
let len = products.len(); let len = products.len();
self.categories = products self.categories = products
.iter() .iter()
@ -106,18 +104,13 @@ impl Products {
}; };
} }
pub fn filter_product_variant_ids<F>(&self, filter: F) -> Vec<ProductVariantId> pub fn filter_product_ids<F>(&self, filter: F) -> Vec<DetailedProduct>
where where
F: Fn(&model::api::v2::ProductVariant) -> bool, F: Fn(&DetailedProduct) -> bool,
{ {
self.product_variant_ids self.product_ids
.iter() .iter()
.filter_map(|id| { .filter_map(|id| self.products.get(id).filter(|&p| filter(p)).map(|p| p.id))
self.product_variants
.get(id)
.filter(|&p| filter(p))
.map(|p| p.id)
})
.collect() .collect()
} }
} }